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

There are one or two basic changes that we’ll need to make in the InvinciBagel.java class, before we switch over<br />

into the Bagel.java class to implement collision detection. Since we are going to use the CastingDirector object in<br />

the collision code, we’ll have to remove the private access control keyword in the CastingDirector castDirector;<br />

declaration, as shown in Figure 16-28. We are trying to keep as many of the variables in our InvinciBagel class private<br />

as possible, and later make them package protected if we need to access them from another class, such as Bagel.java.<br />

Figure 16-28. Remove the private access control modifier keyword for CastingDirector castDirector object declaration<br />

The next thing that we’ll want to do is to remove the iBagel object from the .addCurrentCast() method call<br />

parameter list in the createCastingDirection() method. We are doing this so that the InvinciBagel, who we are<br />

going to be checking for collision against the rest of the Actor objects, which are contained in the CURRENT_CAST<br />

List object, does not check for collision against itself! The new shorter method call (minus the iBagel object)<br />

should look like the following <strong>Java</strong> code, which is shown highlighted at the bottom of Figure 16-29:<br />

castDirector.addCurrentCast(iPR0, iPH0, iPV0, iPB0);<br />

www.it-ebooks.info<br />

369

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

Saved successfully!

Ooh no, something went wrong!