28.04.2019 Views

[JAVA][Beginning Java 8 Games Development]

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

You can then refine your collision polygon structure data point by data point, by clicking and dragging these<br />

points with your mouse, as seen in Figure 17-23. If you compare the collision polygon in Figure 17-22 with the one in<br />

Figure 17-23, you can see I that have refined several of the data points to better conform to the outline of the sprite.<br />

Enemy iBeagle;<br />

// Object Declarations go at top of InvinciBagel.java class<br />

Projectile iBullet, iCheese;<br />

private Image iB0, iB1, iB2, iB3, iB4, iB5, iB6, iB7, iB8, iP0, iP1, iT0, iT1, iE0, iC0, iC1;<br />

iE0 = new Image("/enemy.png", 70, 116, true, false, true); // .loadImageAssets() Method<br />

iC0 = new Image("/bullet.png", 64, 24, true, false, true);<br />

iC1 = new Image("/cheese.png", 32, 29, true, false, true);<br />

iBeagle = new Enemy("M0 6 L0 52 70 52 70 70 70 93 115 45 115 0 84 0 68 16 Z", 520, 160, iE0);<br />

iBullet = new Projectile("M0 4 L0 16 64 16 64 4 Z", 8, 8, iC0);<br />

iCheese = new Projectile("M0 0 L0 32 29 32 29 0 Z", 96, 8, iC1); // .createGameActors() Method<br />

root.getChildren().add(iBeagle.spriteFrame);<br />

root.getChildren().add(iBullet.spriteFrame);<br />

// Add Objects to <strong>Java</strong>FX Scene Graph<br />

root.getChildren().add(iCheese.spriteFrame);<br />

castDirector.addCurrentCast(iPR0, iPH0, iPV0, iPB0, iTR0, iTR1, iBeagle, iBullet, iCheese);<br />

Figure 17-23. Instantiate Image and Projectile objects and add them to <strong>Java</strong>FX Scene Graph and CastingDirector object<br />

412<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!