Guest User

Untitled

a guest
Apr 23rd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. // If you want to make a full featured game, you can.
  2. // This is the basic framework that sets up a 2 stage game.
  3.  
  4. // Stage is a specialized state
  5. Stage = function(){};
  6. Stage.prototype = Engine.extend(Engine.State, {
  7. enter : function() {
  8. // what happens on entering this stage
  9. },
  10.  
  11. run : function() {
  12. // runs every loop for this stage
  13. if(this.isStageEnded()){
  14. this.game.advanceStage();
  15. }
  16. },
  17.  
  18. exit : function() {
  19. // what happens on exiting this stage
  20. }
  21. });
  22.  
  23. // Game Inherits from StateMachine
  24. Game = function(){};
  25. Game.prototype = Engine.extend(Engine.StateMachine.prototype, {
  26. init : funciton(){
  27. // instantiate 2 stages
  28. stage1 = new Stage("stage1");
  29. stage2 = new Stage("stage2");
  30.  
  31. // add stages to state machine
  32. this.addState(stage1);
  33. this.addState(stage2);
  34.  
  35. // set transition rules
  36. // this means from stage1 can only advance to stage2
  37. this.addTransition("advanceStage", stage1, stage2);
  38.  
  39. // set initial stage
  40. this.setInitialState("stage1");
  41. },
  42. // runs the current state
  43. run : function(){
  44. this.getCurrentState().run();
  45. }
  46. });
Add Comment
Please, Sign In to add comment