The terrain object
This object contains the individual Block
objects that form the landscape. It contains just enough Block
objects to fill the screen, and as the _terrain
object scrolls to the left, the Block
objects that leave the screen are moved to the far right side of the _terrain
and reused as new blocks, ensuring continuous scrolling.
The _terrain
object is also responsible for collision checks with the _player
object, since it has quick access to all information we'll need for collision detection; namely the list of blocks currently on the screen, their size, type, and position. Our main loop then will call on the Terrain
object to test for collision with the player
object.
Let's work on these main objects, starting with the Player
object.