1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
| //partie 50 rebonds
boolean isKey;
boolean vaisseauKill;
int vaisseauX;
int vaisseauY;
int vitesseX;
int vitesseY;
int vitesseC;
int canonX;
int canonY1;
int canonY2;
int canonYH;
int cpt;
int cptDestroy;
int cptFrame;
color rouge = color(255, 0, 0);
color vert = color(0, 255, 0);
color blanc = color(255, 255, 255);
color bleu = color(0, 0, 255);
color valeur;
void setup() {
vaisseauKill=false;
isKey=false;
background(0);
frameRate(60);
size(600, 600);
vitesseC=5;
cptDestroy=0;
cptFrame = 0;
vitesseX = 2;
vitesseY = 2;
canonX = width/2;
canonY1 = height-10;
canonY2 = height-25;
canonYH = height-35;
vaisseauX = 130;
vaisseauY = 100;
}
void isKeyPressed() {
if (key == CODED) {
if (keyCode==RIGHT) {
canonX+=vitesseC;
} else if (keyCode==LEFT) {
canonX -= vitesseC;
} else if (keyCode==UP) {
if (cptFrame>0) {
if (canonX>vaisseauX-25 && canonX<vaisseauX+25) {
line(canonX, canonY2, canonX, vaisseauY+10);
if (cptFrame==3) {
cptDestroy++;
}
} else {
strokeWeight(4);
stroke(0, 255, 115);
line(canonX, canonY2, canonX, 0);
}
cptFrame--;
}
}
}
}
void createCanon() {
strokeWeight(25);
stroke(255, 255, 255);
line(canonX, height, canonX, height);
strokeWeight(4);
stroke(255, 255, 255);
line(canonX, canonY1, canonX, canonY2);
}
void createVaisseau() {
vaisseauX += vitesseX;
vaisseauY += vitesseY;
noStroke();
if (cptDestroy>=0 && cptDestroy<3 ) {
ellipse(vaisseauX, vaisseauY, 50, 20);
fill(bleu);
} else if (cptDestroy>=3 && cptDestroy<6) {
ellipse(vaisseauX, vaisseauY, 50, 20);
fill(rouge);
} else if (cptDestroy>=6 && cptDestroy<10) {
ellipse(vaisseauX, vaisseauY, 50, 20);
fill(vert);
} else if (cptDestroy==10) {
ellipse(vaisseauX, vaisseauY, 50, 20);
fill(blanc);
vaisseauKill=true;
vitesseY = 10;
vitesseX = 0;
}
}
void draw() {
background(0);
if (vaisseauX-25<0) {
vitesseX =-vitesseX;
cpt++;
}
if (vaisseauX+25>width ) {
vitesseX = -vitesseX;
cpt++;
}
if (vaisseauY-10<0 ) {
vitesseY = -vitesseY;
cpt++;
}
if (vaisseauY+10>height-100 && vaisseauKill==false) {
vitesseY = -vitesseY;
cpt++;
}
text(cpt, width -50, height -20);
text(cptDestroy, width -150, height -20);
if (cptDestroy>=10) {
text("YOU WIN", width/2, height/2);
textSize(25);
}
createVaisseau();
createCanon();
if (isKey==true)
isKeyPressed();
}
void mousePressed() {
vitesseX=-vitesseX;
vitesseY=-vitesseY;
}
void mouseDragged() {
vaisseauX = mouseX;
vaisseauY = mouseY;
}
void keyReleased() {
isKey=false;
}
void keyPressed() {
isKey=true;
cptFrame=3;
} |
Partager