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-48. Create loadBullet(), loadCheese() and loadEnemy() methods, to add another Enemy or Projectile to game<br />

Now that all these methods are in place, we can call them inside of the .initiateAttack() auto-attack method<br />

body and put them to work checking to see if we need to add a Projectile or Enemy object before we mount the next<br />

attack. The proper place to invoke these method calls would be after the Enemy object is onScreen, and the Projectile<br />

object has been launched, which means that these method calls need to go at the end of the if(onScreen && launchIt)<br />

structure’s else{} body of code. The <strong>Java</strong> code for implementing these three method calls can be seen in Figure 17-49,<br />

and should look like the following:<br />

if(onScreen && launchIt) {<br />

destination = 700;<br />

if(spriteMoveR

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

Saved successfully!

Ooh no, something went wrong!