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

Invoking a .shootProjectile() Method: Setting shootBullet to True<br />

Inside each of the if(takeSides) conditional if-else structures, in the else portion of the statement, add a bulletOffset<br />

variable setting (480 or 120) and set shootBullet equal to true. The <strong>Java</strong> code, seen in Figure 17-42, will look like this:<br />

if(takeSides) {<br />

spriteFrame.setScaleX(1);<br />

this.setIsFlipH(false);<br />

if(!onScreen) {<br />

destination = 500;<br />

if(spriteMoveR >= destination) {<br />

spriteMoveR-=2;<br />

spriteFrame.setTranslateX(spriteMoveR);<br />

} else {<br />

bulletOffset = 480;<br />

shootBullet = true;<br />

onScreen = true; }<br />

Figure 17-42. Add bulletOffset values and shootBullet=true statements into the sprite-reached-destination else body<br />

www.it-ebooks.info<br />

433

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

Saved successfully!

Ooh no, something went wrong!