» codelab : http://codelab.fr/accueil » Forum : Processing : http://codelab.fr/processing » PacMan : http://codelab.fr/5509 Ceci est la version imprimable d'un sujet du forum, pour retourner à la version complète : PacMan |
ClaireT — 2015-01-13 11:24:39 |
Bonjour à tous ! |
Mushussu — 2015-01-13 13:28:53 |
Bonjour, La méthode setup() sert à initialiser les valeurs. for (int i = 0; i< nbFant; i++) { Ghost[i].Fantom(); Ghost[i].bouger(); if (dist(Ghost[i].x, Ghost[i].y, PacMan.x, PacMan.y) < 15) { println("Fin de la partie"); noLoop(); } } Ton code est difficile à lire, tu jongles entre des variables en tançais en anglais, il faut faire un choix. Je te recommande le français. |
ClaireT — 2015-01-15 11:43:35 |
Merci !!! Oui oui j'suis un peu dans la mouise avec ce projet ! ^^ Les méthodes positions, c'était pour enregistrer les position de chaque objet et les comparer par la suite ( c'est là que je me suis carrément noyée ;-)), du coup ce que tu as marqué me parait presque évident ! ^^ Merci encore ! |
Mushussu — 2015-01-15 20:55:43 |
Bonsoir, tu peux utiliser les PVector pour faciliter l'organisation de ton programme. Voilà ce que j'ai fait à partir de timon idée : int nbFant = int(random(10)+1); Creature pacMan; Fantome [] ghost = new Fantome [nbFant]; int nbcheck = 10;//Entry.getInt("nombre de checkpoint ?"); Checkpoint[] cp = new Checkpoint [nbcheck]; int grille [][] = new int [width][height]; void setup () { size (500, 500); pacMan = new Creature (int(random(width)), int(random(height)), color(255, 200, 0)); for (int i = 0; i<nbFant; i++) { ghost [i]= new Fantome (int (random(width)), int (random (height)), int (1), int (1), color(int (random(255)), int (random(255)), int (random(255)))); } for (int i=0; i<nbcheck; i++) { cp[i] = new Checkpoint(); } rectMode(CENTER); } void draw() { background(0); if (keyPressed) { if (keyCode == RIGHT ) { pacMan.modifierX(2); } if (keyCode == LEFT ) { pacMan.modifierX(-2); } if (keyCode == UP) { pacMan.modifierY(-2); } if (keyCode == DOWN) { pacMan.modifierY(2); } } pacMan.Dessiner(); for (int i = 0; i< nbFant; i++) { ghost[i].dessiner(); ghost[i].bouger(); if (PVector.dist(ghost[i].position, pacMan.position) < 15) { println("Fin de la partie"); noLoop(); } } for (int i=0; i<nbcheck; i++) { cp[i].check(); } } class Creature { //ma class creature color couleur; PVector position; Creature (int x, int y, color c) { //Mon constructeur position = new PVector(x, y); couleur = c; } void Dessiner () { //Dessine pacMan fill (couleur); ellipse(position.x, position.y, 30, 30); fill (0); ellipse (position.x + 5, position.y - 10, 5, 5); } PVector position() { //Prend les positions du pacMan return position; } void modifierX(int x) { position.x += x; } void modifierY(int y) { position.y += y; } } class Checkpoint { PVector position; Checkpoint() { position = new PVector(int(random(300)), int(random(300))); } //void Atout () { // } En fonction de la couleur; 5 neutral= ; 80% -> rien; 15% -> vitt PacM augmente pdt 100 pas; 5% -> bouclier pdt 50 pas; void check() { fill(255); ellipse(position.x, position.y, 5, 5); } } class Fantome { PVector position, vitesse; color couleur; int a = int (random (2)); Fantome (int x, int y, int vx, int vy, color c) { position = new PVector(x, y); vitesse = new PVector(vx, vy); couleur = c; } void dessiner () { fill(couleur); rect(position.x, position.y, 20, 20); } PVector position() { return position; } void bouger () { position.add(vitesse); if ((position. x > width) || (position.x < 0)) { vitesse.x *= -1; } if ((position. y > height) || (position.y < 0)) { vitesse.y *= -1; } } } |