I'm new to game development. I do have basic knowledge in Java and also have moderately good experience in OOP from other languages.
I started developing this simple 2D game as my first project.
The game is simple, I have a character, I can move only right and left with constant speed.
I want to add obstacle objects that fall from the sky (top) that I have to dodge. I created the main class (StartingClass) that contains the game loop. receives input from the user's keyboard and moves the character accordingly.
I created a Character class which describes the character position, and reflect its position with painting its image.
Everything is well. However, I'm now trying to add the falling objects. My delima is how to implement them.
I started by creating a new class (FallingObject). In the instructor I create its width, height, falling speed.. etc (randomly). The issue I'm having is to determine how to update this object's position. I would have created an update method for the object and call it every time in the game loop to update its position. But my problem is I will have multiple objects falling simultaneously, each with different speed. So these are the solutions that came to my mind:
- Visible/Active falling objects will be stored in an array list *
1) on every game loop, iterate over the falling objects and update them individually, which doesn't sound that friendly to me.
2) In the falling object instructor, when finished assigning the random values, call a synchronized "startFalling" method on the object, so it keeps falling until it hits the ground.
3) My FallingObject class would implement the runnable interface, and run the function described above through thread. But still... thread for each falling object? I'm not liking that idea.
So I would like to know if I'm somewhat in the right direction in my way of thinking to solve this issue, and which of the above suggestions you think is best, or if there's way better solutions (which I believe is true) that I'm unable to see due to my limited experience in game development design / java.
Thank you very much for your help and support! Cheers Shady