Game Development Reference
In-Depth Information
a
break;
statement in a switch-case structure. To optimize this even further, you
would want to place the most common (the highest number of collidable objects in the
Scene of that object type) objects at the
top
of this if-else-if structure, and the least
common objects at the bottom of the structure. All you have to do to accomplish this is
tie your if() condition blocks together by using the Java
else
keyword, as shown in
Fig-
ation structure, and uses fewer lines of Java code:
private void scoringEngine(Actor
object
) {
if(
object
instanceof Prop)
{
invinciBagel.gameScore+=5;
invinciBagel.playiSound0();
}
else if
(object instanceof PropV) {
invinciBagel.gameScore+=4;
invinciBagel.playiSound1();
}
else if
(object instanceof PropH) {
invinciBagel.gameScore+=3;
invinciBagel.playiSound2();
}
else if
(object instanceof PropB) {
invinciBagel.gameScore+=2;
invinciBagel.playiSound3(); }
invinciBagel.scoreText.
setText
(String.valueOf(invinciBagel.
gameScore
));
}