(c):#include <PA9.h> #include "gfx/all_gfx.c"#include "gfx/all_gfx.h"#include "function.h" //Debut de la fonctionvoid ingame(){ //On init tout ce qu'il faut PA_InitText(1,0); PA_LoadSpritePal(0, 0, (void*)decors_Pal); PA_LoadSpritePal(0, 1, (void*)objet_Pal); PA_LoadSpritePal(0, 2, (void*)personnage_Pal); //Map Test (pour les tests s16 map[9][9] = { {1,1,1,1,1,1,1,1,1}, {1,0,1,0,0,0,1,2,1}, {1,0,1,2,0,0,0,0,1}, {1,0,1,2,1,0,0,0,1}, {1,0,1,1,1,0,0,0,1}, {1,0,1,2,1,0,0,0,1}, {1,0,0,0,0,0,0,0,1}, {1,2,1,0,0,0,0,0,1}, {1,1,1,1,1,1,1,1,1}}; //Idem s16 objet[9][9] = { {0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0}, {0,3,0,0,0,3,0,0,0}, {0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,3,0}, {0,0,0,0,0,0,0,0,0}, {0,0,0,0,3,0,3,0,0}, {0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0}}; //Les variables (Note : j'ai du me trompé avec le s8) s8 x, y, hx, hy, im, retour; hx = 1, hy = 1, im = 0, retour = 0; //Le hero x) PA_CreateSprite(0, im, (void*)personnage_Sprite, OBJ_SIZE_16X16, 1, 2, hx, hy); im ++; for(x = 0; x < 9; x ++){ for(y = 0; y < 9; y ++){ switch(objet[y][x]){ case 3: PA_CreateSprite(0, im, (void*)caisse_no_Sprite, OBJ_SIZE_16X16, 1, 1, x << 4, y << 4); im ++; break; } } y = 0; } for(x = 0; x < 9; x ++){ for(y = 0; y < 9; y ++){ switch(map[y][x]){ case 1: PA_CreateSprite(0, im, (void*)murs_Sprite, OBJ_SIZE_16X16, 1, 0, x << 4, y << 4); break; case 0: PA_CreateSprite(0, im, (void*)sols_Sprite, OBJ_SIZE_16X16, 1, 0, x << 4, y << 4); break; case 2: PA_CreateSprite(0, im, (void*)emplacement_Sprite, OBJ_SIZE_16X16, 1, 1, x << 4, y << 4); break; } im ++; } y = 0; } while (1) { //Deplacement x) if(Pad.Newpress.Up){ verification(map, objet, &hx, &hy, 1, 0, -1, 0, -2, 0);} else if(Pad.Newpress.Down){ verification(map, objet, &hx, &hy, 1, 1, +1, 0, +2, 0);} else if(Pad.Newpress.Right){ verification(map, objet, &hx, &hy, 2, 1, 0, +1, 0, +2);} else if(Pad.Newpress.Left){ verification(map, objet, &hx, &hy, 2, 0, 0, -1, 0, -2);} PA_OutputText(1,10,10,"%d",retour); PA_SetSpriteXY(0, 0, hx<<4, hy<<4); //Affichage des objets sur l'écran du haut pour les tests. (très utile ses lignes) im = 1; for(x = 0; x < 9; x ++){ for(y = 0; y < 9; y ++){ if(objet[y][x] == 3 || objet[y][x] == 4){ PA_SetSpriteXY(0, im, x << 4, y << 4); im ++; } PA_OutputText(1,x,y,"%d",objet[y][x]); } y = 0; } PA_OutputText(1,x,y,"x %d y %d",hx, hy); PA_WaitForVBL(); } } //Fonction de deplacement des objets/herosvoid verification(s16 map[9][9], s16 objet[9][9], s8 *hx, s8 *hy, s8 direct, s8 ajout, s8 iy, s8 ix, s8 ey, s8 ex){s8 hhx, hhy, deplac; deplac = 0; hhx = *hx; hhy = *hy; //On verifie les objets et map pour savoir si certain deplacement sont autorisés >__< if(map[hhy + ey][hhx + ex] == 2 && (objet[hhy + iy][hhx + ix] == 3 || objet[hhy + iy][hhx + ix] == 4)){objet[hhy + ey][hhx + ex] = 4; objet[hhy + iy][hhx + ix] = 0; deplac = 1;} else if(map[hhy + ey][hhx + ex] != 1 && (objet[hhy + iy][hhx + ix] == 3 || objet[hhy + iy][hhx + ix] == 4)){objet[hhy + ey][hhx + ex] = 3; objet[hhy + iy][hhx + ix] = 0; deplac = 1;} else if(map[hhy + iy][hhx + ix] != 1){deplac = 1;} //appelle de la fonction qui deplace le hero if(deplac == 1){deplacement_hero(map, objet, &hhx, &hhy, direct, ajout);}*hx = hhx;*hy = hhy; } //Fonction de deplacement du hero simple (si, je n'ai pas cette fonction, je devrait copié, collé a chaque fois ce code >__<)void deplacement_hero(s16 map[9][9], s16 objet[9][9], s8 *hx, s8 *hy, s8 direct, s8 ajout){s8 hhx, hhy;hhx = *hx;hhy = *hy; if(ajout == 1){ if(direct == 1){hhy ++;} else if(direct == 2){hhx ++;} } else{ if(direct == 1){hhy --;} else if(direct == 2){hhx --;} } *hx = hhx;*hy = hhy;}
(c):void deplacement_hero(/*u8 map[9][9], u8 objet[9][9],*/ u8 *hx, u8 *hy, u8 direct, u8 ajout){ if(ajout==1) { if(direct==1) (*hy)++; else if(direct==2) (*hx)++; } else { if(direct==1) (*hy)--; else if(direct==2) (*hx)--; }}
(c):void verification(u8 map[9][9], u8 objet[9][9], u8 *hx, u8 *hy, u8 direct, u8 ajout, u8 iy, u8 ix, u8 ey, u8 ex){ u8 deplac=0; if(map[(*hy) + ey][(*hx) + ex]==2 && (objet[(*hy) + iy][(*hx) + ix]==3 || objet[(*hy) + iy][(*hx) + ix]==4)) { objet[(*hy) + ey][(*hx) + ex]=4; objet[(*hy) + iy][(*hx) + ix]=0; deplac=1; } else if(map[(*hy) + ey][(*hx) + ex]!=1 && (objet[(*hy) + iy][(*hx) + ix]==3 || objet[(*hy) + iy][(*hx) + ix]==4)) { objet[(*hy) + ey][(*hx) + ex]=3; objet[(*hy) + iy][(*hx) + ix]=0; deplac=1; } else if(map[(*hy) + iy][(*hx) + ix] != 1) deplac=1; if(deplac==1) deplacement_hero(map, objet, hx, hy, direct, ajout);}
(c):(Tu fesais bien ce code ?, exactement ? (les parenthèses sont importantes))
(c): if(Pad.Newpress.Up){ verification(map, objet, &hx, &hy, 1, 0, -1, 0, -2, 0);} else if(Pad.Newpress.Down){ verification(map, objet, &hx, &hy, 1, 1, +1, 0, +2, 0);} else if(Pad.Newpress.Right){ verification(map, objet, &hx, &hy, 2, 1, 0, +1, 0, +2);} else if(Pad.Newpress.Left){ verification(map, objet, &hx, &hy, 2, 0, 0, -1, 0, -2);}