Game Development Reference
In-Depth Information
As you can see in the left half of Figure 17-15 , all Treasure objects are visible in
the Scene, and we're ready to start enhancing our .scoringEngine() method, to support
negative scoring as well as add in Treasure scoring values.
Figure 17-15 . Check Treasure placement (left) and test negative collision values (right) and Treasure collision de-
tection
As you'll soon see (and is seen on the right side of Figure 17-15 ), a Java int (in-
teger) data type supports negative values, so all you have to do in your .scorin-
gEngine() method is to change += to -= for Actor objects that you want the game play-
er to avoid. In our development scenario here, we'll use collision with Prop objects to
give a negative score.
Adding Treasure Collision Detection: Updating .scor-
ingEngine()
Change your Prop Actor objects scoring to reduce the scoreboard value by changing
the += values to -=1 or -=2, and then add an else-if{} section at the end of the existing
if-else-if chain, to support Treasure objects, which we will score at +=5, to add five
points. The Java code to do this, which you can see in Figure 17-16 , should look like
the following:
private void scoringEngine(Actor object ) {
if(object instanceof Prop)
{
invinciBagel.gameScore -=1 ;
invinciBagel.playiSound0();
} else if(object instanceof PropV) {
 
 
 
Search WWH ::




Custom Search