» codelab : http://codelab.fr/accueil » Forum : Processing : http://codelab.fr/processing » Un programme processing dans un autre programme !! : http://codelab.fr/4936 Ceci est la version imprimable d'un sujet du forum, pour retourner à la version complète : Un programme processing dans un autre programme !! |
Lilith — 2014-04-10 22:01:33 |
Bonjours tout le monde, ;) Clo monClo = new Clo(250, -175, color(255)); float b=40 ; float sens=1; PImage ovni; PImage clo; int initial = 1; void setup() { smooth(); //Lissage des dessins size(500, 750); //Taille de la fenêtre ovni = loadImage("OVNI.gif"); clo = loadImage("clo.gif"); } void draw() { background(0, 0, 70); fill(0, 0, 0 , 100); rect(0, 0, 500, 750); fill(250,250,200); ellipse(random(500), random(750) , random(7), random(7)); noStroke(); fill(0); //tant que intial =1 // si y <200 descendre le bonhomme // sinon initial = 0 // si initial =0 monClo.bouge(); monClo.testCollision(); monClo.display(); if ((b>100)||(b<40)) { sens= 0; } imageMode(CENTER); image(ovni,250, 45, b*2, b); b = b + sens; } class Clo { float x; float y; float vitesseX; float vitesseY; color couleur; Clo (float nouvX, float nouvY, color nouvCouleur) { x = nouvX; y = nouvY; couleur = nouvCouleur; vitesseX = 2; vitesseY = 2; } void display() { fill(0); image(clo,x,y,125,200); } void bouge() { y = y + vitesseY; } void testCollision() { //Si la balle touche une mur, elle rebondit if (y > 350 ) { vitesseY = 0; } } } - float x = 250; float y = 350; float vitesseX; float vitesseY; PImage clo; Meteroite maMeteroite = new Meteroite(200, 750); PImage ile; void setup() { smooth(); size(500,750); clo = loadImage("clo.gif"); } void draw() { background(0); fill(0, 0, 0 , 100); rect(0, 0, 500, 750); fill(250,250,200); ellipse(random(500), random(750) , random(7), random(7)); fill(0); if (x > 530) { x=x-555;} if (x < -30) { x=x +555;} if (y > 780) { y=y-785;} if (y < -30) { y=y +785;} keyPressed (); imageMode(CENTER); image(clo,x,y,125,200); ile = loadImage("meteorite.gif"); maMeteroite.bouge(); maMeteroite.testCollision(); maMeteroite.display(); } void keyPressed() { if (key == CODED){ if (keyCode == LEFT) x = x - vitesseX; if (keyCode == RIGHT) x = x + vitesseX; if (keyCode == UP) y = y - vitesseY; if (keyCode == DOWN) y = y + vitesseY; vitesseX = 3; vitesseY = 3; } } class Meteroite { float w; float z; float vitesseW; //AJOUT float vitesseZ; //AJOUT Meteroite (float nouvW, float nouvZ) { w = nouvW; z = nouvZ; vitesseW = -3/2; vitesseZ = -3/2; } } void display() { image(ile,w,z,40,40); } void bouge() { w = w + vitesseW; z = z + vitesseZ; } void testCollision() { if (W > width-40 || w < 0) { vitesseW = vitesseW * -1; } } |
Mushussu — 2014-04-10 23:53:46 |
Bonsoir, Clo monClo; Meteroite maMeteroite; float x = 250; float y = 350; float vitesseX; float vitesseY; PImage clo, ovni, ile; boolean intro; float b=40 ; float sens=1; int initial = 1; void setup() { smooth(); size(500, 750); clo = loadImage("clo.gif"); ovni = loadImage("OVNI.gif"); monClo = new Clo(250, -175, color(255)); maMeteroite = new Meteroite(200, 750); intro = true; } void draw() { if (intro) { // Intro background(0, 0, 70); fill(0, 0, 0, 100); rect(0, 0, 500, 750); fill(250, 250, 200); ellipse(random(500), random(750), random(7), random(7)); noStroke(); fill(0); //tant que intial =1 // si y <200 descendre le bonhomme // sinon initial = 0 // si initial =0 monClo.bouge(); monClo.testCollision(); monClo.display(); if ((b>100)||(b<40)) { sens= 0; } imageMode(CENTER); image(ovni, 250, 45, b*2, b); b = b + sens; // intro = flase; // Quand l'intro se termine } else { // Jeu background(0); fill(0, 0, 0, 100); rect(0, 0, 500, 750); fill(250, 250, 200); ellipse(random(500), random(750), random(7), random(7)); fill(0); if (x > 530) { x=x-555; } if (x < -30) { x=x +555; } if (y > 780) { y=y-785; } if (y < -30) { y=y +785; } imageMode(CENTER); image(clo, x, y, 125, 200); ile = loadImage("meteorite.gif"); maMeteroite.bouge(); maMeteroite.testCollision(); maMeteroite.display(); } } void keyPressed() { if (key == CODED) { if (keyCode == LEFT) x = x - vitesseX; if (keyCode == RIGHT) x = x + vitesseX; if (keyCode == UP) y = y - vitesseY; if (keyCode == DOWN) y = y + vitesseY; vitesseX = 3; vitesseY = 3; } } class Meteroite { float w; float z; float vitesseW; //AJOUT float vitesseZ; //AJOUT Meteroite (float nouvW, float nouvZ) { w = nouvW; z = nouvZ; vitesseW = -3/2; vitesseZ = -3/2; } void display() { image(ile, w, z, 40, 40); } void bouge() { w = w + vitesseW; z = z + vitesseZ; } void testCollision() { if (w > width-40 || w < 0) { vitesseW = vitesseW * -1; } } } class Clo { float x; float y; float vitesseX; float vitesseY; color couleur; Clo (float nouvX, float nouvY, color nouvCouleur) { x = nouvX; y = nouvY; couleur = nouvCouleur; vitesseX = 2; vitesseY = 2; } void display() { fill(0); image(clo, x, y, 125, 200); } void bouge() { y = y + vitesseY; } void testCollision() { //Si la balle touche une mur, elle rebondit if (y > 350 ) { vitesseY = 0; } } } Cependant, deux remarques sur ton code. |
Lilith — 2014-04-11 00:10:50 |
Merci beaucoup ! |
Mushussu — 2014-04-11 07:49:07 |
Tu n'as pas indiqué quand l'intro doit s'arrêter, et je ne peux le tester car il n'y a pas les fichiers images joints. intro = false; C'est à toi de le faire. |
Lilith — 2014-04-11 09:31:52 |
J'avais essayer de le mettre, l'intro marche mais le jeu non. je vais essayer de le déplacer dans le else. |
Mushussu — 2014-04-11 13:39:44 |
Clo monClo; Meteroite maMeteroite; float x = 250; float y = 350; float vitesseX; float vitesseY; PImage clo, ovni, ile; boolean intro; float b=40 ; float sens=1; int initial = 1; void setup() { smooth(); size(500, 750); clo = loadImage("clo.gif"); ovni = loadImage("OVNI.gif"); monClo = new Clo(250, -175, color(255)); maMeteroite = new Meteroite(200, 750); intro = true; } void draw() { if (intro) { // Intro background(0, 0, 70); fill(0, 0, 0, 100); rect(0, 0, 500, 750); fill(250, 250, 200); ellipse(random(500), random(750), random(7), random(7)); noStroke(); fill(0); //tant que intial =1 // si y <200 descendre le bonhomme // sinon initial = 0 // si initial =0 monClo.bouge(); intro = monClo.testCollision(); monClo.display(); if ((b>100)||(b<40)) { sens= 0; } imageMode(CENTER); image(ovni, 250, 45, b*2, b); b = b + sens; // intro = flase; // Quand l'intro se termine } else { // Jeu background(0); fill(0, 0, 0, 100); rect(0, 0, 500, 750); fill(250, 250, 200); ellipse(random(500), random(750), random(7), random(7)); fill(0); if (x > 530) { x=x-555; } if (x < -30) { x=x +555; } if (y > 780) { y=y-785; } if (y < -30) { y=y +785; } imageMode(CENTER); image(clo, x, y, 125, 200); ile = loadImage("meteorite.gif"); maMeteroite.bouge(); maMeteroite.testCollision(); maMeteroite.display(); } } void keyPressed() { if (key == CODED) { if (keyCode == LEFT) x = x - vitesseX; if (keyCode == RIGHT) x = x + vitesseX; if (keyCode == UP) y = y - vitesseY; if (keyCode == DOWN) y = y + vitesseY; vitesseX = 3; vitesseY = 3; } } class Meteroite { float w; float z; float vitesseW; //AJOUT float vitesseZ; //AJOUT Meteroite (float nouvW, float nouvZ) { w = nouvW; z = nouvZ; vitesseW = -3/2; vitesseZ = -3/2; } void display() { image(ile, w, z, 40, 40); } void bouge() { w = w + vitesseW; z = z + vitesseZ; } void testCollision() { if (w > width-40 || w < 0) { vitesseW = vitesseW * -1; } } } class Clo { float x; float y; float vitesseX; float vitesseY; color couleur; Clo (float nouvX, float nouvY, color nouvCouleur) { x = nouvX; y = nouvY; couleur = nouvCouleur; vitesseX = 2; vitesseY = 2; } void display() { fill(0); image(clo, x, y, 125, 200); } void bouge() { y = y + vitesseY; } boolean testCollision() { //Si la balle touche une mur, elle rebondit if (y > 350 ) { vitesseY = 0; return false; } else { return true; } } } |