Game Development Reference
In-Depth Information
Figure 17-32 . Use a randomNum Random object inside of the .setTranslateY() method and use a period to call se-
lector
The next thing that you will want to do is to declare an integer variable named at-
tackBoundary that will be referenced inside of your .nextInt() method call, so that
you can change your Y axis (bottom of screen) boundary later on if you wish, in one
easy-to-edit location at the top of the Enemy.java class. The Java statement should look
like this:
int attackBoundary = 300;
Now we're ready to finish writing the Java code that flips the iBeagle Enemy Actor
(sprite) so he is facing the correct direction, and then we can test the code. It is import-
ant to write complex Java code in logical, digestible steps. In this way, you can test
your code as you write it, making sure that each component of the programming logic
works, before adding additional complexity. You will see this work process during this
chapter, as we develop a robust auto-attack algorithm inside of the Enemy.java class.
This auto-attack code can be used for any of the Enemy objects that you create in the
future; thus the code that you're writing during this chapter will cover a plethora of bad
guy attacks!
It is important to note here that since takeSides is boolean and can only have two
values - true or false, we'll only need to implement a simple conditional if-else struc-
ture. This is because if our if(takeSides) condition equates to being true, then we know
 
Search WWH ::




Custom Search