Preparing the Game Environment
Before you can work on the game loop for, you must initiate all of these new sprites—paddle, ball, and blocks—each of which has different attributes and properties. You also have to prepare the environment—the game surface—in which the sprites are used. Let’s start by changing the source files you opened in the previous section to prepare the way for your new game.
Modifying SpriteObject.java
SpriteObject.java
needs an extra function to return the MoveX
and MoveY
values, which are the variables that store the horizontal and vertical velocity of the sprites. In this way, you can easily reverse them to cause the ball to switch directions. In other game types, you may want to check the speed of a sprite to make sure ...
Get Beginning Android Tablet Games Programming now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.