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

} else if(object.equals(invinciBagel.iCheese)) {<br />

invinciBagel.gameScore+=5;<br />

invinciBagel.playiSound0;<br />

} else if(object.equals(invinciBagel.iBeagle)) {<br />

invinciBagel.gameScore+=10;<br />

invinciBagel.playiSound0; }<br />

Figure 17-46. Adding the iBullet, iCheese and iBeagle object.equals() if-else structures to the .scoringEngine() method<br />

At this point, if you use a Run ➤ Project work process, you should have an iBeagle shooting a Bullet or Cream<br />

Cheese Ball. When you catch the iBeagle with the InvinciBagel character, you should score ten points, or, if you catch a<br />

Cream Cheese Ball, you should get five points. If you get hit by a Bullet, you should lose five points.<br />

You will notice as you test the InvinciBagel game application that once you get hit by a Bullet, Cream Cheese Ball,<br />

or when you catch the iBeagle, that they do not come back! This is because the collision detection programming logic<br />

removes an object from the game once an InvinciBagel collects it (Treasure) or collides with it (Prop or Projectile).<br />

So the next step in our development will be to add in the programming logic that adds an iBullet, iCheese or<br />

iBeagle object back into the castDirector object once they have been removed by the collision detection programming<br />

logic that you put into place in Chapter 16. To do this, we’ll have to code an enhancement to the CastingDirector.java<br />

class, code the new .loadEnemy(), .loadBullet() and .loadCheese() methods at the bottom of the Enemy.java class, and<br />

add the appropriate programming logic implementing these three new methods into the .initiateAttack() method.<br />

438<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!