J'ai deux fichiers processing, un qui code un paysage, un qui code une mommie, j'ai…
- User
J'ai deux fichiers processing, un qui code un paysage, un qui code une mommie, j'ai initialisé la mommie comme suit : pushMatrix(); float mx = width/2+975; float my = height/2+1010; float dx = 0; float dy = -1;
float mx1 = width/2+980; float my1 = height/2+1010;
void draw(){ sphereDetail(6); translate(-1000,-1000); background(135,206,235); stroke (200,160,99); lights();
pushMatrix(); translate(mx,my,19); scale(0.05); rotateX(-1*HALF_PI); float angle = atan2(dy,dx); rotateY(-angle); shape(mummy); popMatrix();
le problème est que la direction de la momie est correctement mise à jour lorsque la touche de gauche est pressée, mais pas lorsque la touche de droite est pressée, elle avance tout droit comme si j'avais pas tourné à droite, il y'a ptet un probleme dans ce code , notamment où il y a marqué en commentaire 'le fantome va a droite' : char[][] creaLaby(int n){ labyrinthe = new char[n][n]; sides = new char[n][n][4]; int todig = 0; for (int j=0; j<n; j++) { for (int i=0; i<n; i++) { sides[j][i][0] = 0; sides[j][i][1] = 0; sides[j][i][2] = 0; sides[j][i][3] = 0; if (j%2==1 && i%2==1) { labyrinthe[j][i] = '.'; todig ++; } else labyrinthe[j][i] = '#'; } } int gx = 1; int gy = 1; while (todig>0 ) { int oldgx = gx; int oldgy = gy; int alea = floor(random(0, 4)); // selon un tirage aleatoire if (alea==0 && gx>1) gx -= 2; // le fantome va a gauche else if (alea==1 && gy>1) gy -= 2; // le fantome va en haut else if (alea==2 && gx<n-2) gx += 2; // .. va a droite else if (alea==3 && gy<n-2) gy += 2; // .. va en bas
if (labyrinthe[gy][gx] == '.') { todig--; labyrinthe[gy][gx] = ' '; labyrinthe[(gy+oldgy)/2][(gx+oldgx)/2] = ' '; }}
labyrinthe[0][1] = ' '; // entree labyrinthe[n-2][n-1] = ' '; // sortie
for (int j=1; j<n-1; j++) { for (int i=1; i<n-1; i++) { if (labyrinthe[j][i]==' ') { if (labyrinthe[j-1][i]=='#' && labyrinthe[j+1][i]==' ' && labyrinthe[j][i-1]=='#' && labyrinthe[j][i+1]=='#') sides[j-1][i][0] = 1;// c'est un bout de couloir vers le haut if (labyrinthe[j-1][i]==' ' && labyrinthe[j+1][i]=='#' && labyrinthe[j][i-1]=='#' && labyrinthe[j][i+1]=='#') sides[j+1][i][3] = 1;// c'est un bout de couloir vers le bas if (labyrinthe[j-1][i]=='#' && labyrinthe[j+1][i]=='#' && labyrinthe[j][i-1]==' ' && labyrinthe[j][i+1]=='#') sides[j][i+1][1] = 1;// c'est un bout de couloir vers la droite if (labyrinthe[j-1][i]=='#' && labyrinthe[j+1][i]=='#' && labyrinthe[j][i-1]=='#' && labyrinthe[j][i+1]==' ') sides[j][i-1][2] = 1;// c'est un bout de couloir vers la gauche } } } for (int j=1; j<n-1; j++) { for (int i=1; i<n-1; i++) { print(labyrinthe[j][i]); } print("\n"); } return labyrinthe; }
- Assistant
Le problème se situe en effet dans la fonction creaLaby(). Plus précisément, c'est dans la condition "else if (alea==2 && gx<n-2) gx += 2;", où le fantôme est censé aller à droite.
Cependant, le mouvement sur l'axe X doit se faire par incrémentation et décrémentation de la variable "mx" de la momie, et non par modification de la variable "gx" du labyrinthe.
Pour corriger cela, il faut remplacer la ligne "else if (alea==2 && gx<n-2) gx += 2;" par :
"else if (alea==2 && mx<width/2+975) mx += 2;"
Cela permettra de faire avancer la momie vers la droite du paysage.