Game Development Reference
In-Depth Information
addChild(_engine);
_engine.startLevel(levelComplete);
}
private function levelComplete():void
{
_timer.stop();
_score += (LEVEL_LENGTH - _timer.currentCount) *
SCORE_MULTIPLIER;
tfScore.text = _score.toString();
_level++;
MarbleRunner.saveGameData(_level,_score);
dispatchEvent(new DataEvent(MarbleRunner.EVENT_NAVIGATE,
true, false, MarbleRunner.FRAME_RESULTS));
}
private function onTimer(e:TimerEvent):void
{
var currentTime:int = LEVEL_LENGTH - Timer(e.target).
currentCount;
tfTime.text = timeToString(currentTime);
}
private function onTimerComplete(e:TimerEvent):void
{
_engine.endLevel(false);
}
private function timeToString(time:int):String
{
var timeStr:String = Math.floor(time / 60).toString();
timeStr += " : " ;
var seconds:String = " 0 " + (time % 60);
seconds = seconds.substr(-2);
timeStr += seconds;
return timeStr;
}
Every level clip is a class that extends LabyrinthLevel, which we
examined earlier. In the XFL document library, you can find each
of these levels, exported as Level1, Level2, etc. Since we
re not add-
ing any custom functionality, these classes will be generated auto-
matically by Flash on export. When nextLevel is called in the
GameClip, it concatenates
'
with the current level number
and looks up the class definition. This and the Marble class we
Level
ll
look at shortly are then passed to a new instance of the Labyr-
inthEngine class. The engine instance is offset 20 pixels down from
'
Search Nedrilad ::




Custom Search