Game Development Reference
In-Depth Information
We also need to override the systemGameOver function of Main.as to support Mochi leader
boards. This is where we will use the lastScore variable we created in GameFrameWork. To
make the leader boards work, we need to create and set a variable named lastScore in the game
class that we can reference from Main (you will see this used in Tunnel Panic a bit later). We then
set nextSystemState to FrameWorkStates.STATE_SYSTEM_MOCHI_HIGHSCORES, so that the
function described next will be called. We will implement the following code when we create the
Main.as for Tunnel Panic.
override public function systemGameOver():void {
super.systemGameOver();
lastScore = game.lastScore;
nextSystemState = FrameWorkStates.STATE_SYSTEM_MOCHI_HIGHSCORES;
}
Finally, we will need to add in the systemMochiHighscores and mochiHighscores functions. The
heart of these is the call to MochiScore.showLeaderBoard . This call is standard function call that
Mochi provides. There are many other functions in the Mochi Services API, but this is the most
basic way to support a leader board. Add these lines to the GameFrameWork.as file in the
com.efg.framework package.
public function systemMochiHighscores():void {
var resolution:String = stage.width + "x" + stage.height;
var o:Object = { n: [15, 15, 14, 2, 13, 14, 0, 10, 14, 2, 2, 1, 10, 7, 15, 4],
f: function (i:Number,s:String):String { if (s.length == 16) return s;
return this.f(i+1,s + this.n[i].toString(16));}};
MochiScores.showLeaderboard({boardID: mochiBoardId, score: lastScore,
onClose:mochiHighscoresComplete, res:resolution });
switchSystemState(FrameWorkStates.STATE_SYSTEM_WAIT_FOR_CLOSE);
nextSystemState = FrameWorkStates.STATE_SYSTEM_TITLE;
}
//*** new Function for Mochi ads chapter 12
public function mochiHighscoresComplete():void {
switchSystemState(nextSystemState);
}
When the user has finished submitting a score or closes the leader board without submitting, the
mochiHighscoresComplete function is called. This function simply sets the state machine back to
the FrameWorkStates.STATE_SYSTEM_TITLE state.
Creating our own viral game
Let's take a closer look at a real-world scenario that might actually occur in the viral Flash game
industry. We are going to assume that you have made some other games and have created your
own framework and reusable class structure similar to the one presented in the first 11 chapters
of this topic (and the first section of this chapter).
A client e-mail arrives on a Sunday evening at about 6:00 PM. In the e-mail is an urgent
request for a simple game engine and a 48-hour deadline. The client wants an arcade-style
game with no shooting and the game play time should last no more than about 60 seconds for
each session. You are also told that the controls must be very easy and simple. You are given
Search WWH ::




Custom Search