Game Development Reference
In-Depth Information
Let's use a different approach for these last three object scoring else-if structures, and
instead of using an if(object instanceof Actor) for more general object type comparis-
ons, we will use the more precise .equals() method that allows us to specify the object
itself, such as
if(object.equals(invinciBagel.iBullet)
. You can see the complete if-else
structure in
Figure 17-46
, and the Java code for the last three Enemy objects looks like
the following:
} else if(object.
equals
(invinciBagel.
iBullet
)) {
invinciBagel.gameScore
-=5
;
invinciBagel.playiSound5;
} else if(object.
equals
(invinciBagel.
iCheese
)) {
invinciBagel.gameScore
+=5
;
invinciBagel.playiSound0;
} else if(object.
equals
(invinciBagel.
iBeagle
)) {
invinciBagel.gameScore
+=10
;
invinciBagel.playiSound0;
}
Figure 17-46
.
Adding the iBullet, iCheese and iBeagle object.equals() if-else structures to the .scoringEngine() meth-
od