Game Development Reference
In-Depth Information
far). If you follow the industry standard Java 8 code formatting practices, the Java
method body that you would use to implement this empty infrastructure can be seen in
Figure 17-31 , and should look like the following:
boolean takeSides = false;
private void initiateAttack() {
if( takeSides ) {
// Empty Statement
} else { // Empty Statement }
}
Figure 17-31 . Add an if-else structure inside of the initiateAttack() method, to alternate between the left and right
sides
Inside the if(takeSides){} structure set the Enemy object (which we named iBeagle
in the InvinciBagel class) to an X location of 500, by using
spriteFrame.setTranslateX(500); and to a random height on the screen,
using a spriteFrame.setTranslateY() method call in conjunction with the random
number generator object we installed in the previous section of the chapter. If you type
in your randomNum object name and then hit the period key, you will be presented
with a number of method call options, which is shown in Figure 17-32 . Double-click
the nextInt(int bound) option, and insert that method call off of the randomNum ob-
ject inside the .setTranslateY() method.
 
 
 
Search WWH ::




Custom Search