Moving along the path
Now that you’ve created a custom path using the
ArrayList structure, how are we going to get our balloons to move along it smoothly?
- Coordinate based representation
- Distance based representation
- Converting between the two (Challenge)
Coordinate representations for positions
Normally when we have an object in a game that moves around, we will store two numbers - the x-coordinate and the y-coordinate.
Drawing an object using coordinates is extremely simple - all we need to do is create a shape using one of our graphics functions (
rect(), etc.) and it will draw a shape right there. Nothing new.
Moving an object along our path with this representation, however, is difficult - because our path can contain lots of twists and turns, it is very hard to figure out the next location a balloon should travel to at any given time.
Is there a way we can simplify movement?
Distance representations for positions
What if instead of storing two co-ordinates, we decided to store a single number, representing the distance travelled along our path?
Moving an object with this representation is now very simple - all we need to do is increase this number by the speed of the balloon every frame.
Drawing this object now becomes an issue - how are we supposed to figure out where the balloon is on the screen, just from a single number?
In our game, we will make use of the benefits of both representations in order to move our balloons along the path.
Code-wise, we will store the distance travelled for each balloon and use the custom method
PVector getLocation(float travelDistance) to convert from distance representation to the coordinate representation.
When we are displaying balloons, we will call this method and use the converted values in order to display our balloon.
While this method is already implemented in the templates, we encourage you to try and come up with a solution yourself!
Create an written explanation on how such a method would work in theory, earning up to 100 extra points for the Game Jam, on top of the 200 participation points.
Submissions for this challenge are now closed.