Game Development Reference
In-Depth Information
.getiY() getter method, and then use in the .setTranslateY() method call. We are using
integer (rather than double) as the iBagelLocation data type, so we'll need to “cast” the
double data value we get from the .getiY() method, so that it is compatible with the
iBagelLocation variable. The Java code, shown in Figure 17-57 , should look like the
following:
int iBagelLocation ;
iBagelLocation = (int) invinciBagel.iBagel. getiY() ;
spriteFrame.setTranslateY( iBagelLocation );
randomOffset = iBagelLocation + 5;
Figure 17-57 . Declare iBagelLocation integer variable, cast a double iY variable to it, and use it to create ran-
domOffset
If you use your Run Project work process to test your code, you will see that
the projectiles now target the InvinciBagel character, no matter where you might posi-
tion him on the screen! This is great for attacks that utilize the deadly iBullet Projectile
Actor object, but makes it too easy to score points when the iCheese Projectile Actor
object is used by the auto-attack engine. Therefore, we will need to add another layer
of code that uses the randomLocation variable, if the auto-attack engine is going to
shoot a Cream Cheese Ball, and the iBagelLocation variable, if the auto-attack engine
is going to shoot a deadly (real) bullet. We will put this logic structure up in the .up-
date() method where we create both the randomLocation and iBagelLocation variable
values (using .nextBoolean() or .getiY() method calls), right after the bulletType is de-
termined, using a .nextBoolean() method call off of the randomNum Random object.
 
 
Search WWH ::




Custom Search