Raindrop game
in
Programming Questions
•
2 years ago
Hello,
I am relatively new to processing, and I have to do some small exercises.
I have created most of a raindrop game but I am stuck when it comes to implementing a score feature.
In the main sketch I have an if-function that register when raindrops intersects with the catcher. In this if-loop I have tried to implement the score, so that every time a drop hits the catcher, the score counts one up.
When I write the "score++" in the if-loop, i get an error with a missing right curly bracket at the else part of the loop.
I have three classes named "Catcher", "FancyRaindrop" and "Timer". If you need any of these classes to solve the problem, I can of course show them too.
Here is the main sketch:
I am relatively new to processing, and I have to do some small exercises.
I have created most of a raindrop game but I am stuck when it comes to implementing a score feature.
In the main sketch I have an if-function that register when raindrops intersects with the catcher. In this if-loop I have tried to implement the score, so that every time a drop hits the catcher, the score counts one up.
When I write the "score++" in the if-loop, i get an error with a missing right curly bracket at the else part of the loop.
I have three classes named "Catcher", "FancyRaindrop" and "Timer". If you need any of these classes to solve the problem, I can of course show them too.
Here is the main sketch:
Catcher catcher;
FancyRaindrop[] raindrops;
int score = 0;
void setup() {
size(200,200);
smooth();
catcher = new Catcher(20);
raindrops = new FancyRaindrop[100];
}
void draw() {
background(255);
for(int i = 0; i < raindrops.length; i++)
if (raindrops[i] == null || raindrops[i].reachedBottom()) {
raindrops[i] = new FancyRaindrop(random(width),random(5,10),random(.5,3),color(0,0,255));
break;
}
for(int i = 0; i < raindrops.length; i++)
if (raindrops[i] != null && !raindrops[i].reachedBottom())
raindrops[i].move();
catcher.setLocation(mouseX,mouseY);
for(int i = 0; i < raindrops.length; i++) {
if (raindrops[i] != null && !raindrops[i].reachedBottom()) {
if (catcher.intersects(raindrops[i]))
score++;
raindrops[i] = null;
else
raindrops[i].display();
}
}
catcher.display();
}
1