28.04.2019 Views

[JAVA][Beginning Java 8 Games Development]

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 17 ■ Enhancing Game Play: Creating a Scoring Engine, Adding Treasure and an Enemy Auto-Attack Engine<br />

The next step in the work process is to use GIMP to create the collision polygon for the Enemy object, as is seen<br />

in Figure 17-19, using only nine data points. Use the SVG data creation work process you learned in Chapter 16.<br />

Figure 17-19. Use GIMP to create a nine-point collision polygon for your Enemy Actor<br />

Before we go into the InvinciBagel.java class to declare and instantiate an Enemy object named iBeagle, let’s<br />

create the Projectile.java class, so that our Enemy object has Projectile objects to shoot at the InvinciBagel character!<br />

Creating Cream Cheese Bullets: Coding a Projectile.java Class<br />

Now that we have added positive (Treasure) elements to our game, let’s add some negative (Enemy and Projectile)<br />

elements to the game, so that we remain “balanced” in our development work process! Create a Projectile.java class<br />

and constructor method that sets isFixed to false (since projectiles fly) and isBonus and hasValu to true, so the object<br />

properties are set. The <strong>Java</strong> code for this Projectile.java class can be seen in Figure 17-20, and looks like the following:<br />

package invincibagel;<br />

import javafx.scene.image.Image;<br />

public class Projectile extends Actor {<br />

public Projectile(String SVGdata, double xLocation, double yLocation, Image... spriteCels) {<br />

super(SVGdata, xLocation, yLocation, spriteCels);<br />

spriteFrame.setTranslateX(xLocation);<br />

spriteFrame.setTranslateY(yLocation);<br />

www.it-ebooks.info<br />

409

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!