État du code
Sur cette page sera présenté l'état du code au fil des séances et l'évolution du départ à la finition.

int espace;
PImage ennemi;
PImage vaisseau;
PImage laser;
int nmbt;
​
void setup(){
size(600,600);
ennemi=loadImage("vaisseau 2.png");
vaisseau=loadImage("vaisseau 1.png");
laser=loadImage("laser 1.png");
for(int i=0; i<TirJ_Valide.length; i++){
TirJ_Valide[i]=false;
}
​
void draw(){
background(0,0,0);
noCursor();
for(int L=0; L<TirJ.length; L++){
if(TirJ_Valide[L]==true){
TirJ[L].deplacement();
}
}
pushMatrix();
image(vaisseau,mouseX,500,100,100);
image(ennemi,300,300,100,100);
popMatrix();
if(mousePressed==true){
TirJ[nmbT]= new laser(mouseX+25,500);
mousePressed=false;
TirJ_Valide[nmbT]=true;
nmbT++;
if(nmbT>=150){
nmbT=0;
}
}
}
​


laser[] TirJ= new laser[150];
boolean[] TirJ_Valide= new boolean[150];
class laser {
int positionx;
int positiony;
int vitessey=5;
int taillex=50;
int tailley=150;
laser(int Npositionx,int Npositiony){
positionx=Npositionx;
positiony=Npositiony;
}
void deplacement(){
image(laser,positionx,positiony,taillex,tailley);
positiony-=vitessey;
}
}

class Ennemi {
float x;
float y;
float vitesseX;
float vitesseY;
Ennemi(float mouvX, float mouvY,color mouvCouleur) {
x = mouvX;
y = mouvY;
vitesseX=2;
vitesseY=2;
}
void display(){
pushMatrix();
image(ennemi,600,700,50,50);
popMatrix();
}
void bouge() {
x=x+vitesseX;
y=y+vitesseY;
}
}

PImage espace;
PImage clickJouer;
PImage jouer;
PImage clickOption;
PImage option;
void setup(){
espace= loadImage("Fond.png");
clickJouer= loadImage("bouton jouer souris.png");
jouer= loadImage("bouton -jouer-.png");
clickOption= loadImage("Option souris.png");
option= loadImage("Option.png");
size(850,850);
textSize(50);
}
void draw(){
image(espace,0,0,850,850);
image(jouer,270,300,300,250);
image(option,280,500,300,250);
PFont police;
police = loadFont("Castellar-80.vlw");
textFont(police,80);
text("SPACE PROTECTOR",10,200);
noStroke();
noFill();
rect(280,370,300,100);
rect(280,570,300,100);
if(mouseX>280 && mouseX<580 && mouseY>370 && mouseY<470){
image(clickJouer,270,300,300,250);
}
if(mouseX>280 && mouseX<580 && mouseY>570 && mouseY<670){
image(clickOption,280,500,300,250);
}
}

Nouvelle version du code

Star[] stars = new Star[300];
import ddf.minim.*;
Minim minim;
AudioPlayer musicM;
AudioPlayer musicJ ;
AudioPlayer musicOp ;
int fenetre;
int x = 850;
int y = 850;
int taille = 50;
PImage titre;
PImage clickJouer;
PImage jouer;
PImage clickOption;
PImage option;
PImage souris;
PImage retour;
PImage retourClick;
Enemi d;
void setup(){
minim = new Minim(this);
musicM = minim.loadFile("star-wars-the-mandalorian-theme-epic-version.mp3");
musicM.play();
musicJ =minim.loadFile("timecop1983-on-the-run.mp3");
musicOp =minim.loadFile("music-options.mp3");
size(750,650);
titre = loadImage("TITRE 5.png");
clickJouer = loadImage("Jouer_souris.png");
jouer = loadImage("Jouer.png");
clickOption = loadImage("Option_Click.png");
option = loadImage("Option.png");
for(int i = 0;i < stars.length;i++){
stars[i] = new Star();
}
d = new Enemi();
}
void draw(){
background(255);
d.deplacement();
d.affichage_enemi();
if(fenetre==0){
Menu();
translate(width/2,height/2);
for(int i = 0;i < stars.length;i++){
stars[i].update();
stars[i].show();
}
}
if(fenetre==1){
FenetreOP();
musicM.pause();
musicOp.play();
}
if(fenetre==2){
Jeux();
musicM.pause();
musicJ.play();
}
}
void Menu(){
background(0);
image(titre,110,70,500,300);
image(jouer,200,250,300,250);
image(clickOption,200,450,300,500);
noStroke();
noFill();
rect(280,370,300,100);
rect(280,570,300,100);
if(mouseX>280 && mouseX<580 && mouseY>370 && mouseY<470){
image(clickJouer,200,250,300,500);
if(mousePressed== true){
fenetre = 2;
}
}
if(mouseX>280 && mouseX<580 && mouseY>570 && mouseY<670){
image(option,200,450,300,500);
if(mousePressed== true){
fenetre = 1;
}
}
}
void FenetreOP(){
Option();
affichage_option();
}
void Jeux(){
jeu1();
jeu2();
}
class Enemi {
float x = width/2;
float y = 0;
float yvitesse = 1;
void deplacement(){
y= y + yvitesse;
}
void affichage_enemi(){
image(ennemi,300,300,100,100);
}
}
PImage fondj;
int nb_ennemi=5;
int espace;
PImage ennemi;
PImage vaisseau;
PImage laser;
int nmbT;
void jeu1(){
size(750,650);
fondj = loadImage("starfiled.jpg");
ennemi=loadImage("vaisseau 2.png");
vaisseau=loadImage("vaisseau 1.png");
laser=loadImage("Laser 1.png");
for(int i=0; i<TirJ_Valide.length; i++){
TirJ_Valide[i]=false;
}
}
void jeu2(){
background(0,0,0);
image(fondj,0,0,750,650);
noCursor();
for(int L=0; L<TirJ.length; L++){
if(TirJ_Valide[L]==true){
TirJ[L].deplacement();
}
}
pushMatrix();
image(vaisseau,mouseX,550,100,100);
//image(ennemi,300,300,100,100);
popMatrix();
if(mousePressed==true){
TirJ[nmbT]= new laser(mouseX+25,300);
mousePressed=false;
TirJ_Valide[nmbT]=true;
nmbT++;
if(nmbT>=150){
nmbT=0;
}
}
}
​
void Option(){
souris = loadImage("Souris Option.png");
retour = loadImage("retour.png");
retourClick = loadImage("retourclick.png");
}
void affichage_option(){
image(souris,30,60,850,850);
image(retour,10,700,300,250);
if(mouseX>10 && mouseX<310 && mouseY>700 && mouseY<950){
image(retourClick,10,700,300,250);
if(mousePressed== true){
fenetre = 0;
}
}
if(fenetre==0){
musicOp.pause();
}
}
​
​
​
laser[] TirJ= new laser[150];
boolean[] TirJ_Valide= new boolean[150];
class laser {
int positionx;
int positiony;
int vitessey=5;
int taillex=50;
int tailley=150;
laser(int Npositionx,int Npositiony){
positionx=Npositionx;
positiony=Npositiony;
}
void deplacement(){
image(laser,positionx,positiony,taillex,tailley);
positiony-=vitessey;
}
}
​
class Star{
float x;
float y;
float z;
float pz;
Star(){
x = random(-width,width);
y = random(-height,height);
z = random(width);
pz = z;
}
void update(){
z = z-20;
if(z < 1){
z=width;
x = random(-width,width);
y = random(-height,height);
pz = z;
}
}
void show(){
fill(255);
noStroke();
float sx = map(x / z,0,1,0,width);
float sy = map(y/ z,0,1,0,height);
float r = map(z,0,width,16,0);
ellipse(sx,sy,r,r);
float px = map(x / pz,0,1,0,width);
float py = map(y/ pz,0,1,0,height);
stroke(255);
line(px,py,sx,sy);
}
}
​
​
​
​







Code Final

Star[] stars = new Star[300];
import ddf.minim.*;
Minim minim;
AudioPlayer musicM;
AudioPlayer musicJ ;
AudioPlayer musicOp ;
AudioPlayer musicLaser;
AudioPlayer musicGameover;
AudioPlayer musicVictoire;
int fenetre;
int x = 850;
int y = 850;
int taille = 50;
PImage titre;
PImage clickJouer;
PImage jouer;
PImage clickOption;
PImage option;
PImage souris;
PImage retour;
PImage retourClick;
void setup(){
minim = new Minim(this);
musicM = minim.loadFile("star-wars-the-mandalorian-theme-epic-version.mp3");
musicM.play();
musicJ = minim.loadFile("timecop1983-on-the-run.mp3");
musicOp = minim.loadFile("music-options.mp3");
musicLaser = minim.loadFile("laser-gun-sound.mp3");
musicGameover = minim.loadFile("super-mario-dies-sound-effect.mp3");
musicVictoire = minim.loadFile("marios-victory-theme.mp3");
size(750,650,P3D);
titre = loadImage("TITRE 5.png");
clickJouer = loadImage("Jouer_souris.png");
jouer = loadImage("Jouer.png");
clickOption = loadImage("Option_Click.png");
option = loadImage("Option.png");
ennemi = loadImage("vaiseauE.png");
for(int i = 0;i < stars.length;i++){
stars[i] = new Star();
}
}
void draw(){
background(255);
if(fenetre==0){
Menu();
translate(width/2,height/2);
for(int i = 0;i < stars.length;i++){
stars[i].update();
stars[i].show();
}
}
if(fenetre==1){
FenetreOP();
musicM.pause();
musicOp.play();
}
if(fenetre==2){
Jeux();
musicM.pause();
musicJ.play();
}
if(fenetre==3){
score();
}
if(fenetre ==4){
}
}
void Menu(){
background(0);
image(titre,110,70,500,300);
image(jouer,225,200,300,250);
image(clickOption,225,390,300,500);
noStroke();
noFill();
rect(280,370,300,100);
rect(280,570,300,100);
if(mouseX>242 && mouseX<506 && mouseY>267 && mouseY<373){
image(clickJouer,225,200,300,500);
if(mousePressed== true){
fenetre = 2;
}
}
if(mouseX>223 && mouseX<526 && mouseY>457 && mouseY<563){
image(option,225,390,300,500);
if(mousePressed== true){
fenetre = 1;
}
}
}
void FenetreOP(){
Option();
affichage_option();
}
void Jeux(){
jeu1();
jeu2();
deplacement();
score();
scorelose ();
}

PImage fondj;
PImage ennemi;
PImage vaisseau;
PImage asteroide;
PImage laser;
float laserY = 200;
float laserX = 50;
float EnnemiX = 350;
float EnnemiY = 0;
float asteroideX = 350;
float asteroideY = 0;
boolean moveDown = true;
boolean moveUp =false;
boolean Laser = true;
int scoreE = 0;
int scoreP = 0;
void jeu1(){
fondj = loadImage("starfiled.jpg");
ennemi = loadImage("vaisseauE.png");
vaisseau = loadImage("vaisseau 1.png");
laser = loadImage("Laser 1.png");
asteroide = loadImage("asteroide 1.png");
}
void jeu2(){
background(0,0,0);
image(fondj,0,0,750,650);
noCursor();
image(ennemi,EnnemiX,EnnemiY,100,100);
image(asteroide,asteroideX,asteroideY,80,80);
fill(255,0,0);
text("Ennemi",50,50);
text(scoreE,200,50);
fill(0,0,255);
textSize(20);
text("Protector",450,50);
text(scoreP,550,50);
image(laser,mouseX,laserY,100,200);
if(moveDown == true){
EnnemiY = EnnemiY + 6;
asteroideY = asteroideY + 6;
}
if(EnnemiY <= 650){
moveDown = true;
}
if(asteroideY <= 620){
moveDown = true;
}
if(EnnemiY > 650){
EnnemiY = 0;
EnnemiX = random(90,670);
moveDown = true;
scoreE++;
}
if(asteroideY > 620){
asteroideY = 0;
asteroideX = random(155,500);
moveDown = true;
scoreE++;
}
if(mousePressed){
moveUp = true;
musicLaser.play();
}
if(moveUp == true){
laserY = laserY - 20;
}
if(laserY < 10){
laserY = 520;
moveUp = false;
}
if(laserY < EnnemiY + 20 && laserY > EnnemiY - 90 && mouseX < EnnemiX + 20 && mouseX > EnnemiX - 20){
EnnemiY =0;
EnnemiX = random(100,670);
moveDown = true;
scoreP++;
}
if(laserY < asteroideY + 20 && asteroideY > asteroideY - 90 && mouseX < asteroideX + 20 && mouseX > asteroideX - 20){
asteroideY =0;
asteroideX = random(155,600);
moveDown = true;
scoreP++;
}
}
void deplacement (){
image(vaisseau,mouseX,550,100,100);
}
void score (){
if(scoreP >= 20){
background(0);
fill(0,0,255);
textSize(64);
text("VICTOIRE", 250, 300);
musicVictoire.play();
}
}
void scorelose (){
if(scoreE >= 5){
background(0);
fill(255,0,0);
textSize(64);
text("GAME OVER", 180, 300);
musicGameover.play();
}
}

void Option(){
souris = loadImage("souris gestuelle.png");
retour = loadImage("retour.png");
retourClick = loadImage("retourclick.png");
}
void affichage_option(){
image(souris,0,0,750,650);
image(retour,7,500,200,250);
if(mouseX>7 && mouseX<300 && mouseY>500 && mouseY<950){
image(retourClick,7,500,200,250);
if(mousePressed== true){
fenetre = 0;
}
}
if(fenetre==0){
musicOp.pause();
}
}

class Star{
float x;
float y;
float z;
float pz;
Star(){
x = random(-width,width);
y = random(-height,height);
z = random(width);
pz = z;
}
void update(){
z = z-20;
if(z < 1){
z=width;
x = random(-width,width);
y = random(-height,height);
pz = z;
}
}
void show(){
fill(255);
noStroke();
float sx = map(x / z,0,1,0,width);
float sy = map(y/ z,0,1,0,height);
float r = map(z,0,width,16,0);
ellipse(sx,sy,r,r);
float px = map(x / pz,0,1,0,width);
float py = map(y/ pz,0,1,0,height);
stroke(255);
line(px,py,sx,sy);
}
}
