I've been learning Java by experimenting with a little "game" that started with just trying to make a ball jump. I've got 3 classes (JumpingBall3, BallSprite3, & Floor) and have achieved a gravity of some sorts, a jump that works consistently, and hit detection against floors to stop the ball falling infinitely. With this last point I've spotted a potential issue with future development. Right now I have two floors created by JumpingBall3 ("floor1" & "platform") and I detect collision within the BallSpite3 using the following code:
public boolean collision()
{
if (game.floor1.getBounds().intersects(getBounds()) || game.platform.getBounds().intersects(getBounds())) {
onFloor = true;
}
else
{
onFloor = false;
}
return onFloor;
}
If I were to keep adding more floors or platforms that "if" condition is quickly going to spiral out of control in terms of length. Is there a way to create a method that cycles through all visible Floor objects created in my JumpingBall3 class?
I've posted the full code online here, it seemed a bit lengthy to include within this post.