I am a new programmer so the solution to this might be simple. Its just that I don't know how to do this. Okay, well I am trying to make this game that has falling Blue and Red dots. The goal is to remove the balls with the Right and Left arrows keys. My problem is that when I press Right/Left it removes all of the balls of the corresponding color. I would like it to remove just the lowest ball on the screen (The ball with the biggest Y) here is my code for removing the balls:
(This is the code for the Blue Dot)
I have a similar code for the Red Dot which has the same problem.
boolean alive = true; //300 is a Line on the screen. The balls must have passed this line so that it can be removed. if (getY() >= 300) { //If you press RIGHT ARROW remove the BLUE DOT if(Greenfoot.isKeyDown("right") == true) { //This is the code that removes the balls (I would like it to remove just 1, the lowest ball on the screen) getWorld().removeObjects(getWorld().getObjects(BlueDot.class)); alive = false; } } if( alive == true ) { //If the Dot reaches the end of the screen then GAME OVER if (getY() > 600){ Greenfoot.stop(); System.out.println("GAME OVER!"); } }