Help needed for game code
The following code makes a rectangle move across the screen from left to right similar to the class example.
float x = 0;
//...some code not shown
rect(x,50,50,50);
x = x + 1;
//...some code not shown
Add code so that your program does the following:
1. When the rectangle is clicked, it jumps back to the left hand side of the screen and 1 point is added to a score. When the rectangle reaches the right hand side of the screen, it jumps back but not points are added.
2. Keep the score stored in a variable and display it using the text() function. You can look this up in the reference to see how it works.
3. The rectangle should shrink in size as it moves across the screen and then restore itself to original size when it jumps back.
In addition to the requirements above, choose one of the following extensions to add to your game:
Make the rectangle change color as it moves across the screen.
Make the rectangle move more quickly as the score gets higher.
Have the player lose points each time the rectangle reaches the right side without being clicked.
So far, this is what I have:
float rectX = 0;
float rectY = 100;
int score = 0;
void setup() {
size(300,250);
}
void draw() {
background(0);
//draws rectangle
stroke(255);
fill(rectX,rectY,rectX);
rect(rectX, rectY, 50,50);
rectX = rectX + 1;
}
I'm a bit stuck on how to proceed from here on. Any help would be highly appreciated!