Hello guys,
I need help please, The thing would be, when I press a key an image appears and when I press it again it disappears.
i’ve made it into my code and the image doesn’t shows up
I put my code here and if someone sees something wrong about it tell me pls ^^
PImage chaines;
PImage dvd;
float b;
float d = 1;
int speedX = 3;
int speedY = 3;
float x = random(width);
float y = random(height);
bug[] bugs = new bug[3000];
boolean freeze = false;
boolean slow = false;
boolean showImage = false;
color white = (255);
void setup (){
fullScreen();
chaines = loadImage ("chaine2.png");
dvd = loadImage ("dvd.png");
for (int i = 0; i < bugs.length; i++) {
bugs[i] = new bug();
}
}
void draw () {
background (white);
if (showImage) {
image (chaines,width/2,height/2); }
if (freeze) {
for (int i = 0; i < bugs.length; i++) {
bugs[i].fall();
bugs[i].show();
}
if (slow) {
frameRate(30); }
}
bouger();
couleurs();
}
void couleurs() {
b = b + d;
tint (b, 255-b, b);
if (b > 255 || b < 0) { d = d * -1;}
}
void bouger() {
x = x + speedX;
y = y + speedY;
if (x < 0 || x > width - 339) { speedX = speedX * -1;}
if (y < 0 || y > height - 149) { speedY = speedY * -1;}
image (dvd,x,y);
}
void keyPressed() {
if (key == 'b' || key == 'B') {
if (freeze) {
freeze = false;}
else { freeze = true;}
if (slow) {
slow = !slow; }
}
if (key == 'v') {
if (showImage) {
showImage = !showImage; }
}
}
And on another outlet
class bug {
float x = random(width);
float y = random (-100,100);
float speedY = random(5,10);
float taille = random (50, 70);
void fall() {
y = y+speedY;
if (y > height) {
y = random (-100,-100);
}
}
void show() {
fill(0);
line(x,y,x,y+taille);
}
}