Bonjour/Bonsoir les gens!!! je sais qu'en ce moment vous bouffez du Pacman mais j'ai besoin d'une dernière aide et après je vous laisse tranquille avec mon Pacman c'est promis;)
il me reste une dernière étape à faire. C'est tout con mais il faut que je fasse un système de vie. Et pour cela, je pensais comparer la case sur laquelle se trouve mon Pacman avec celle des fantômes. Mais c'est là que je n'y arrive pas. Je ne sais pas comment comparer parce que je ne sais pas comment trouver la position des fantômes.
Donc si quelqu'un aurait la gentillesse de m'aider ça serait super. Et j'aurai une dernière chose à vous demander les gars, si vous pouvez me donner la solution ce soir ça serait TOP!!!
Pacman p; Fantome[] f; float nombreDeCase2 =180; int caseX; int caseY; int tailleCase; int[][] terrainInitial = { {0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0}, {0, 2, 2, 2, 0, 1, 0, 2, 0, 1, 0, 2, 2, 2, 0}, {0, 2, 0, 2, 0, 0, 0, 2, 0, 0, 0, 2, 0, 2, 0}, {0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0}, {0, 2, 0, 2, 0, 2, 0, 0, 0, 2, 0, 2, 0, 2, 0}, {0, 2, 0, 2, 0, 2, 0, 0, 0, 2, 0, 2, 0, 2, 0}, {0, 2, 0, 2, 2, 2, 2, 0, 2, 2, 2, 2, 0, 2, 0}, {0, 2, 2, 2, 0, 0, 2, 2, 2, 0, 0, 2, 2, 2, 0}, {0, 0, 0, 2, 0, 0, 2, 0, 2, 0, 0, 2, 0, 0, 0}, {1, 1, 0, 2, 0, 0, 2, 0, 2, 0, 0, 2, 0, 1, 1}, {0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0}, {0, 2, 2, 2, 0, 2, 0, 0, 0, 2, 0, 2, 2, 2, 0}, {0, 2, 0, 2, 0, 2, 0, 1, 0, 2, 0, 2, 0, 2, 0}, {0, 2, 0, 2, 0, 2, 3, 1, 0, 2, 0, 2, 0, 2, 0}, {0, 2, 0, 2, 0, 2, 0, 1, 0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 0, 0, 2, 0, 1, 1}, {0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0}, {0, 2, 2, 2, 0, 2, 0, 0, 0, 2, 0, 2, 2, 2, 0}, {0, 2, 0, 2, 0, 2, 0, 1, 0, 2, 0, 2, 0, 2, 0}, {0, 2, 0, 2, 0, 2, 3, 1, 0, 2, 0, 2, 0, 2, 0}, {0, 2, 0, 2, 0, 2, 0, 1, 0, 2, 0, 2, 0, 2, 0}, {0, 2, 2, 2, 0, 2, 0, 0, 0, 2, 0, 2, 2, 2, 0}, {0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0}, {1, 1, 0, 2, 0, 0, 2, 0, 2, 0, 0, 2, 0, 1, 1}, {0, 0, 0, 2, 0, 0, 2, 0, 2, 0, 0, 2, 0, 0, 0}, {0, 2, 2, 2, 0, 0, 2, 2, 2, 0, 0, 2, 2, 2, 0}, {0, 2, 0, 2, 2, 2, 2, 0, 2, 2, 2, 2, 0, 2, 0}, {0, 2, 0, 2, 0, 2, 0, 0, 0, 2, 0, 2, 0, 2, 0}, {0, 2, 0, 2, 0, 2, 0, 0, 0, 2, 0, 2, 0, 2, 0}, {0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0}, {0, 2, 0, 2, 0, 0, 0, 2, 0, 0, 0, 2, 0, 2, 0}, {0, 2, 2, 2, 0, 1, 0, 2, 0, 1, 0, 2, 2, 2, 0}, {0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0}, }; void setup() { fullScreen(); tailleCase = 50; p = new Pacman(1, 1, tailleCase); f = new Fantome[3]; f[0] = new Fantome(12, 7, tailleCase, color(255, 0, 0)); f[1] = new Fantome(13, 7, tailleCase, color(0, 255, 0)); f[2] = new Fantome(14, 7, tailleCase, color(0, 0, 255)); } void draw() { if(nombreDeCase2==0) { fill(0); rect(0,0,width,height); fill(250); textSize(300); text("YOU WIN", 50,height/6*4-50); textSize(100); text("restart", width/4*3,height/4*3+50); if(mousePressed == true) { if((width/4*3<=mouseX)&&(mouseX<=width/4*3+320)&&(height/4*3-50<=mouseY)&&(mouseY<=height/4*3+100)) { arrayCopy(terrainInitial,terrain); nombreDeCase2 = 180; int caseX = 75; int caseY = 75; p.position.x=caseX; p.position.y=caseY; p.direction.set(0, 0); } } }else { background(0); for (int i = 0; i < terrain.length; i++) { for (int j = 0; j < terrain[i].length; j++) { pushMatrix(); translate(i * tailleCase, j * tailleCase); switch (terrain[i][j]) { case 0: fill(#1811F7); stroke(#000000); strokeWeight(2.5); rect(0, 0, tailleCase, tailleCase); strokeWeight(1); break; case 2: fill(#FCD5A1); noStroke(); ellipse(tailleCase / 2, tailleCase / 2, 8, 8); break; case 3: fill(255, 0, 0); stroke(#000000); strokeWeight(2.5); rect(0, 0, tailleCase, tailleCase); strokeWeight(1); break; } popMatrix(); } } p.deplacement(terrain); p.affichage(); for (int i = 0; i < f.length; i++) { f[i].deplacement(terrain); f[i].affichage(); } } } void keyPressed() { int caseX = tailleCase * (p.getX() / tailleCase) + tailleCase / 2; int caseY = tailleCase * (p.getY() / tailleCase) + tailleCase / 2; int intervalle = 10; if (keyCode == DOWN) { if ((p.getX() > caseX - intervalle) && (p.getX() < caseX + intervalle) && (terrain[p.getX() / tailleCase][p.getY() / tailleCase + 1] != 0) && (terrain[p.getX() / tailleCase][p.getY() / tailleCase + 1] != 3)) { p.position.x = caseX; p.direction.set(0, 1); if(terrain[caseX/tailleCase][caseY/tailleCase]==2) { nombreDeCase2= nombreDeCase2-1; } terrain[caseX/tailleCase][caseY/tailleCase]=1; } } if (keyCode == UP) { if ((p.getX() > caseX - intervalle) && (p.getX() < caseX + intervalle) && (terrain[p.getX() / tailleCase][p.getY() / tailleCase - 1] != 0) && (terrain[p.getX() / tailleCase][p.getY() / tailleCase - 1] != 3)) { p.position.x = caseX; p.direction.set(0, -1); if(terrain[caseX/tailleCase][caseY/tailleCase]==2) { nombreDeCase2= nombreDeCase2-1; } terrain[caseX/tailleCase][caseY/tailleCase]=1; } } if (keyCode == RIGHT) { if ((p.getY() > caseY - intervalle) && (p.getY() < caseY + intervalle) && (terrain[p.getX() / tailleCase + 1][p.getY() / tailleCase] != 0) && (terrain[p.getX() / tailleCase + 1][p.getY() / tailleCase] != 3)) { p.position.y = caseY; p.direction.set(1, 0); if(terrain[caseX/tailleCase][caseY/tailleCase]==2) { nombreDeCase2= nombreDeCase2-1; } terrain[caseX/tailleCase][caseY/tailleCase]=1; } } if (keyCode == LEFT) { if ((p.getY() > caseY - intervalle) && (p.getY() < caseY + intervalle) && (terrain[p.getX() / tailleCase - 1][p.getY() / tailleCase] != 0) && (terrain[p.getX() / tailleCase - 1][p.getY() / tailleCase] != 3)) { p.position.y = caseY; p.direction.set(-1, 0); if(terrain[caseX/tailleCase][caseY/tailleCase]==2) { nombreDeCase2= nombreDeCase2-1; } terrain[caseX/tailleCase][caseY/tailleCase]=1; } } } class Pacman { int taille; int vitesse; PVector position, direction; Pacman(int x, int y, int t) { position = new PVector(x * t + t / 2, y * t + t / 2); direction = new PVector(0, 0); taille = t; vitesse = 2; } void deplacement(int[][] t) { int caseX = taille * ((int)position.x / taille) + taille / 2; int caseY = taille * ((int)position.y / taille) + taille / 2; if ((direction.x == 1) && (position.x == caseX)) { if (t[(int)position.x / taille + 1][(int)position.y / taille] == 0) { direction.set(0, 0); } } if ((direction.x == -1) && (position.x == caseX)) { if (t[(int)position.x / taille - 1][(int)position.y / taille] == 0) { direction.set(0, 0); } } if ((direction.y == 1) && (position.y == caseY)) { if (t[(int)position.x / taille][(int)position.y / taille + 1] == 0) { direction.set(0, 0); } } if ((direction.y == -1) && (position.y == caseY)) { if (t[(int)position.x / taille][(int)position.y / taille - 1] == 0) { direction.set(0, 0); } } position.add(PVector.mult(direction, vitesse)); } void affichage() { float r = 0; float o = 0; if (frameCount % 40 >= 30) { r = QUARTER_PI; o = 0.3; } stroke(1); fill(255, 255, 0); pushMatrix(); translate(position.x, position.y); rotate(direction.y * PI / 2); if (direction.x == -1) { arc(0, 0, 45, 45, PI + o, TWO_PI + PI - r, PIE); fill(0); ellipse(-3, -10, 5, 5); } else { arc(0, 0, 45, 45, r, TWO_PI - o, PIE); fill(0); ellipse(3, -10, 5, 5); } popMatrix(); noStroke(); } int getX() { return (int)position.x; } int getY() { return (int)position.y; } } class Fantome { color couleur; PVector position, direction; int etat, taille, vitesse; Fantome(int x, int y, int t, color c) { position = new PVector(x * t + t / 2, y * t + t / 2); direction = new PVector(2 * int(random(2)) - 1, 0); couleur = c; etat = 0; taille = t; vitesse = 2; } PVector croisement(int[][] t, int x, int y) { byte dir = 0; byte n = 0; if (t[x][y - 1] != 0) { dir |= (1 << 0); n++; } if (t[x + 1][y] != 0) { dir |= (1 << 1); n++; } if (t[x][y + 1] != 0) { dir |= (1 << 2); n++; } if (t[x - 1][y] != 0) { dir |= (1 << 3); n++; } if (n == 1) { return PVector.mult(direction, -1); } else { int choix = 0; PVector res = new PVector(0, 0); while (choix == 0) { choix = dir & (1 << int(random(4))); switch (choix) { case 1 : res.set(0, -1); break; case 2 : res.set(1, 0); break; case 4 : res.set(0, 1); break; case 8 : res.set(-1, 0); break; } if (res.dist(direction) == 2) { choix = 0; } } return res; } } void deplacement(int[][] t) { int caseX = taille * ((int)position.x / taille) + taille / 2; int caseY = taille * ((int)position.y / taille) + taille / 2; if ((position.x == caseX) && (position.y == caseY)) { direction.set(croisement(t, (int)position.x / taille, (int)position.y / taille)); } position.add(PVector.mult(direction, vitesse)); } void affichage() { pushMatrix(); translate(position.x, position.y); switch (etat) { case 0: fill(couleur); arc(taille / 2-25, taille / 2-32, 30, 30, -PI, 0); rect(taille / 2- 40, taille / 2 - 32, 30, 15); triangle(taille/2 - 40,taille/2-17 , taille/2 -30, taille/2-17, taille/2 -40, taille/2-10); triangle(taille/2 - 33,taille/2-17 , taille/2 -18, taille/2-17, taille/2 -25, taille/2-10); triangle(taille/2 - 20,taille/2-17 , taille/2 -10, taille/2-17, taille/2 -10, taille/2-10); fill(0); ellipse(taille/2-30, taille/2-33, 8,8); ellipse(taille/2-20, taille/2-33, 8,8); fill(#2B45EA); ellipse(taille/2-31, taille/2-32, 3,4); ellipse(taille/2-21, taille/2-32, 3,4); } popMatrix(); }; }
Dernière modification par lenzone (2016-05-20 19:38:49)
Hors ligne
Pages: 1