How do I add score to my game?

I’m new to processing and have been trying to make a game in which the character moves to the coordinates of mouse click and then stays there until it is called again. I have a “food” which moves to a random location whenever the character and the food overlap. I want to add a score function for this game but the problem I’m getting is that it keeps adding the score infinitely and not once. I want the score to increase if it consumes the food from right and decrease if it consumes it from the left, but it just keeps increasing until its infinity or decreasing till its 0. How do I solve this?

1 Like


It seems that your conditions are too general and that there is always a condition that is fulfilled so your score is changing at every frame.

But to be sure, we would need to see the full code.

And please format your code when you copy some here =)

This seems to happen only once and works correctly. Maybe change the score in the code there?



1 Like

Reddit bad, processing community good.


I do have a food that moves to a random location every time the character overlaps it. I actually just uploaded my full code, so it is more clear now.


Thank you for replying, I just uploaded my full code. I just realized that I need the preformat option to format the text.


First problem, you are iterating the score in the draw loop as jb4x said. Remove score(); from the draw.

Now you want the score to increase when the face eats the food? Simplest solution is to call your score(); method when you move the face to a new position.
Where do you move the food?

Hopefully this is clear.