Game Development Reference
In-Depth Information
by doing it this way, we have a more optimized game, as we are only using one single
.collide() method (remember that each Hero object has a .collide() method implemen-
ted) for our JavaFX pulse event engine to process. When I convert this game into a
multi-player game (the code for this is beyond the Beginner nature of this title), I
would want to make the Enemy class a Hero subclass, so that the Enemy character
could collide with things, such as Treasure and Projectiles, just like the InvinciBagel
can. Since the Enemy class still has an .update() method, it can be moved around on the
screen, where it can (and will) come out of hiding and shoot bullets (negative effect)
and balls of cream cheese (positive effect) at the InvinciBagel character. The only thing
that differentiates the Hero class is the .collide() method, and for this version of the
game, having one .collide() method to process per pulse allows us to optimize the game
play processing, while still having a game with the different game features that an arca-
de game would include. As you can see in the Enemy() constructor method, the Enemy
character isAlive , isBonus , and hasValue , and so all of these properties or characterist-
ics of the Enemy will be set to a boolean value of true inside of the constructor meth-
od, after the sprite location has been set using .setTranslateX() and .setTranslateY(),
and after the SVG data, Image, and initial X,Y location data is passed up to the Actor()
constructor using the super() constructor. The Java code for the Enemy.java class can
be seen error-free in Figure 17-18 , and should look like the following Java class struc-
ture:
package invincibagel;
import javafx.scene.image.Image;
public class Enemy extends Actor {
public Enemy (String SVGdata, double xLocation, double
yLocation, Image... spriteCels) {
super(SVGdata, xLocation, yLocation, spriteCels);
spriteFrame.setTranslateX(xLocation);
spriteFrame.setTranslateY(yLocation);
isAlive = true;
isBonus = true;
hasValu = true;
}
@Override
public void update () {
// Currently Empty Method
}
}
 
Search WWH ::




Custom Search