Game Development Reference
In-Depth Information
of the screen the character is in. The way we would thus calculate the boundaries is to
take half of the screen width and subtract half of the sprite width to find the right (pos-
itive) boundary value and simply take the negative of this for the value for the left
boundary limit. A similar calculation applies to the top and bottom boundary value lim-
it, for which we will take half of the screen height and subtract half of the sprite height
to find the bottom (positive) boundary value and simply take the negative of this for the
value for the top boundary limit value. The Java code for these calculations should look
like the following:
protected static final double rightBoundary =
WIDTH/
2 - SPRITE_PIXELS_X/2;
protected static final double leftBoundary
= -(WIDTH/
2 - SPRITE_PIXELS_X/2);
protected static final double bottomBoundary =
HEIGHT/2
- SPRITE_PIXELS_Y/2;
protected static final double topBoundary
= -(HEIGHT/2
- SPRITE_PIXELS_Y/2);
As you can see in Figure 12-16 , NetBeans is having trouble seeing the constants in-
side the InvinciBagel class.
Figure 12-16 . Hold a left arrow (or A) and up arrow (or W) key down at the same time, and move the Actor diagon-
ally
Mouse-over the wavy red error highlighting in NetBeans that is underneath the
WIDTH constant, and select the import static invinciba-
gel.InvinciBagel.WIDTH; option so that NetBeans will write this import state-
 
 
Search WWH ::




Custom Search