Game Development Reference
In-Depth Information
When you test your collision code, you will find that you cannot get to some of
these tiles! Let's fix this next.
Go into the Bagel.java class and modify the screen boundary constants at the top of
the class so that the left and the top boundaries use the 0,0 origin values, since the
Group class uses the upper-left corner of your screen as its point of reference, rather
than the center of the screen, as the StackPane does. To calculate the rightBoundary
value, you would take the WIDTH of the screen and subtract the width of the sprite us-
ing the SPRITE_PIXELS_X constant. A similar approach would be used for the bot-
tomBoundary value, which will take the HEIGHT of the screen and subtract the height
of the sprite using the SPRITE_PIXELS_Y constant. As you can see in Figure 16-45 ,
we don't have to change the .setBoundaries() method at all, thanks to the modular, lo-
gical and organized way that we have set up our code.
Figure 16-45 . Update the Bagel.java class with new Boundary values for the right, left, bottom and top Boundary
value
Before we finish up with the chapter, let's add a scoring engine framework to our
game, so that this collision detection routine calls a scoringEngine method, in addition
to playing a sound and removing the Actor from the game.
 
 
Search WWH ::




Custom Search