Game Development Reference
In-Depth Information
than -1. In the body of the if() statement, collisionDetect Boolean flag is set to true of
any data is present ( signified by != -1). The Java code for the conditional if() statement
should look like the following:
if(intersection. getBoundsInLocal().getWidth() != -1 ) {
collisionDetect = true; }
To test the collision code, I put the invinciBagel.playiSound0() method call inside
of the if(collisionDetect){} conditional statement. This is why I commented out that
.playAudioClip() method call in the .update() method, so that the only thing that I will
hear during a collision is the audio playback. This is a quick, easy, and effective way to
test the collision code, at least for now. Since this is the public boolean collide(Actor
object) method, I am also going to put a return true; line of code at the end of
the if() body, that returns a true value from the method call. I am placing the statement
inside of this conditional if() construct, so that if needed, we can use this true Boolean
value returned from the .collide() method call in the .update() method for other pro-
cessing, if we want to. The very nature of this .collide() method is to detect if a colli-
sion has occurred and then return a value, so we could do further processing inside of
the .collide() method, or more efficiently do this on-collision processing inside of the
.checkCollision() method, using an
if(collide(object)=true){invinciBagel.playiSound0();} con-
struct, instead of the way that we are doing this here with the statement processing in-
side of the .collide() method. The reason I am doing it this way, at least for now, is be-
cause I am testing this .collide() method, so I'm putting the statements that allow me to
test the .collide() method inside of that .collide() method since that is where I'm work-
ing within the IDE right now. The Java code looks like this:
if( collisionDetect ) {
invinciBagel.playiSound0();
return true ;
}
return false;
The complete .collide(Actor object) method structure, before we get into manipu-
lating the CastingDirector class and object List<Actor> objects, should look like the
following, which can also be seen in Figure 16-32 :
@Override
public boolean collide(Actor object ) {
 
Search WWH ::




Custom Search