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 16 ■ Collision Detection: Creating SVG Polygons for the Game Actors and Writing Code to Detect Collision<br />

of the way that we are doing this here with the statement processing inside of the .collide() method. The reason I am<br />

doing it this way, at least for now, is because I am testing this .collide() method, so I’m putting the statements that<br />

allow me to test the .collide() method inside of that .collide() method since that is where I’m working within the IDE<br />

right now. The <strong>Java</strong> code looks like this:<br />

if(collisionDetect) {<br />

invinciBagel.playiSound0();<br />

return true;<br />

}<br />

return false;<br />

The complete .collide(Actor object) method structure, before we get into manipulating the CastingDirector class<br />

and object List objects, should look like the following, which can also be seen in Figure 16-32:<br />

@Override<br />

public boolean collide(Actor object) {<br />

boolean collisionDetect = false;<br />

if ( invinciBagel.iBagel.spriteFrame.getBoundsInParent().intersects(<br />

object.getSpriteFrame().getBoundsInParent() ) ) {<br />

Shape intersection =<br />

SVGPath.intersect(invinciBagel.iBagel.getSpriteBound(), object.getSpriteBound());<br />

if (intersection.getBoundsInLocal().getWidth() != -1) {<br />

collisionDetect = true;<br />

}<br />

}<br />

if(collisionDetect) {<br />

invinciBagel.playiSound0();<br />

return true;<br />

}<br />

return false;<br />

}<br />

www.it-ebooks.info<br />

377

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

Saved successfully!

Ooh no, something went wrong!