Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // If you want to make a full featured game, you can.
- // This is the basic framework that sets up a 2 stage game.
- // Stage is a specialized state
- Stage = function(){};
- Stage.prototype = Engine.extend(Engine.State, {
- enter : function() {
- // what happens on entering this stage
- },
- run : function() {
- // runs every loop for this stage
- if(this.isStageEnded()){
- this.game.advanceStage();
- }
- },
- exit : function() {
- // what happens on exiting this stage
- }
- });
- // Game Inherits from StateMachine
- Game = function(){};
- Game.prototype = Engine.extend(Engine.StateMachine.prototype, {
- init : funciton(){
- // instantiate 2 stages
- stage1 = new Stage("stage1");
- stage2 = new Stage("stage2");
- // add stages to state machine
- this.addState(stage1);
- this.addState(stage2);
- // set transition rules
- // this means from stage1 can only advance to stage2
- this.addTransition("advanceStage", stage1, stage2);
- // set initial stage
- this.setInitialState("stage1");
- },
- // runs the current state
- run : function(){
- this.getCurrentState().run();
- }
- });
Add Comment
Please, Sign In to add comment