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 />

Figure 17-38. Add an if(onScreen) level of processing inside the if(takeSides) logic to animate a sprite from the left side<br />

Weaponizing the Enemy: Shooting Projectile Objects<br />

Now that we have the Enemy animating onto (and off of) both sides of the screen, the next level of complexity that<br />

we need to add is the shooting of Projectile objects. We’ll first implement iBullet objects (negative score generation)<br />

and later iCheese objects (positive score generation), both of which will require our Enemy.java class to have visibility<br />

into the InvinciBagel class. Thus, the first thing that we’ll need to do is to modify the Enemy() constructor method to<br />

accept an InvinciBagel object using the <strong>Java</strong> this keyword, much like we did with our Bagel() constructor method. Go<br />

into the InvinciBagel.java class and add a this keyword to the front end of (beginning of) your Enemy() constructor<br />

parameter list, as shown highlighted in Figure 17-39, using the following amended Enemy() constructor method call:<br />

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

www.it-ebooks.info<br />

429

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

Saved successfully!

Ooh no, something went wrong!