Game Development Reference
In-Depth Information
Choosing a Category
A player chooses a category to score on by clicking an available category button in the scorecard container. These event
listeners are already set on each button, and their handler function is shown in Listing 7-24.
Listing 7-24. The onScoreCardBtnClick Marks the Score in the Appropriate Category
function onScoreCardBtnClick(e) {
var btn = e.target;
btn.mouseEnabled = false;
scoreCard.mouseEnabled = false;
var score = 100;
btn.gotoAndStop(btn.name + '_score');
updateScore(btn, score);
updateScoreboard();
evalGame();
}
The category clicked is first referenced and set to btn . It is immediately disabled to prevent it from being clicked
on for the remainder of the game. The scorecard itself is then disabled to prevent any other category from also
being pressed.
This next line is temporary. Every score will be set to 100 for the time being. There is quite a bit of scoring logic
to determine the category score, but you can hold off on that now and finish the game logic first. This score will be
accessed by calling on a Scoring object, or class, that will be built during the “Calculating the Scores” section later in
this chapter.
With the score statically set, the value needs to be displayed in the category to which it belongs. As you know,
each category button is a sprite with multiple frames. In the sprite sheet object, each animation has a corresponding
frame that uses its same name with an appended _score at the end.
"ones":{frames:[158, 159, 160, 161, ...177] },
"ones_score":{frames:[178] }
This extra frame is a clone of the animation's last frame, only without the text in the graphic. This leaves room to
place a text object on top with the score value. Figure 7-13 shows this frame.
Figure 7-13. The frame used for the fours category button when chosen to score on
A series of functions are next called, which will add text objects to each category, update the scoreboard, and
evaluate the game.
 
Search WWH ::




Custom Search