Adding boundaries
As we are quite familiar with the process of creating a new class, we will simply create our two new classes for our upper and lower boundary and call them UpperBoundary.java
and LowerBoundary.java
, respectively. We have the following objectives for our boundaries:
- Make them appear at the top and bottom of our game screen
- If a player collides with them, then reset the game
With these objectives in mind, we will move ahead to create boundaries for our game.
Creating the classes for our boundaries
Before actually creating our boundaries, we will need an image sprite in order to make them visible on the screen. For this purpose, we will take a simple sprite with a plain color. Here's the sprite that we will be using for our game:
Our ground.png file
Also, we will place this file in our res/drawable
folder as we did for our previous image files. Once you are done with this, move on to the next part.
So now, let's create our UpperBoundary.java
class. Go ahead, create a new class and...