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

Figure 16-30. Comment out the playAudioClip() method call to turn off all audio and add a checkCollision() method call<br />

Create an empty public void checkCollision(){} method body, which will remove that wavy red error<br />

highlighting that you see in Figure 16-30, so that we can begin to put the code into place that will look through the<br />

CURRENT_CAST List object, so that we can ascertain if any of the cast members intersect (have collided<br />

with) the primary InvinciBagel character on the game Stage.<br />

Inside of this .checkCollision() method, we will need a <strong>Java</strong> for “counter” loop structure. This structure will be<br />

used to traverse through your CURRENT_CAST List array of objects; in this case, these are Prop objects, to<br />

check for any collisions (intersections) with the InvinciBagel object. The first part of the for loop is the iterator variable<br />

declaration and initialization, in our case, int i=0; to declare the integer type iterator variable named “i,” initialized<br />

to a count value of zero.<br />

The second part of the for loop is the iteration condition, which, in this case, is “iterate until you reach the<br />

end of the CURRENT_CAST List object, or i

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

Saved successfully!

Ooh no, something went wrong!