Game Development Reference
In-Depth Information
The third if statement needs to look at the bottomBoundary value and compare the
current iY location to that value. If the iY value is greater than or equal to the bot-
tomBoundary value limit, then you will want to set the iY value to the bottomBoundary
value. This will keep your InvinciBagel locked into position at the bottom of the screen
boundary. The reverse of this logic will also work for the top of the screen; if the iY
value is less than or equal to the topBoundary value limit, then you will want to set
the iY value equal to the topBoundary value. The Java code for the .setBoundaries()
method including the four if() statements is shown in Figure 12-18 , and should look
like the following:
private void setBoundaries() {
if (iX >= rightBoundary) { iX=rightBoundary; }
if (iX <= leftBoundary) { iX=leftBoundary; }
if (iY >= bottomBoundary) { iY=bottomBoundary; }
if (iY <= topBoundary)
{ iY=topBoundary;
}
}
Figure 12-18 . Create a private void .setBoundaries() method and four if() statements to ascertain and set boundaries
Next, let's test all of this code to see if it does what we think that it logically should
do! The code is quite well organized and very logical, so I don't see any problems with
 
 
Search WWH ::




Custom Search