Advertisement
davehale23

GameState.as

Jun 24th, 2013
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package
  2. {
  3.     import citrus.core.starling.StarlingState;
  4.     import citrus.objects.platformer.box2d.Platform;
  5.     import citrus.objects.platformer.box2d.Sensor;
  6.     import citrus.physics.box2d.Box2D;
  7.     import starling.display.Quad;
  8.    
  9.     /**
  10.      * ...
  11.      * @author david.hale
  12.      */
  13.     public class GameState extends StarlingState
  14.     {
  15.        
  16.         public function GameState()
  17.         {
  18.             super();
  19.         }
  20.        
  21.         override public function initialize():void
  22.         {
  23.             super.initialize();
  24.            
  25.             //add physics
  26.             var physics:Box2D = new Box2D("box2d");
  27.             physics.visible = true; //this adds the box outlines           
  28.             add(physics);
  29.            
  30.             //add a Box2D platform
  31.             var floor:Platform = new Platform("floor", {x: 512, y: 750, width: 1024, height: 40});
  32.             floor.view = new Quad(1024, 40, 0x000000);
  33.             add(floor);
  34.            
  35.             //this is the Platform that we are climbing up to
  36.             var p1:Platform = new Platform("p1", {x: 874, y: 151, width: 300, height: 40});
  37.             p1.view = new Quad(300, 40, 0x222222);         
  38.             add(p1);
  39.            
  40.             //a Box2D Sensor
  41.             var ladder1:Sensor = new Sensor("ladder1", {x: 874, y: 410, width: 20, height: 580});
  42.             ladder1.view = new Quad(20, 580, 0x555500);
  43.             //this is how we set this platform to be a ladder
  44.             ladder1.isLadder = true;
  45.             add(ladder1);
  46.            
  47.             //our modified Hero
  48.             var hero:ladderHero = new ladderHero("hero", {x: 50, y: 50, width: 80, height: 80});           
  49.             //I have this in a separate function in case the level that I'm building doesn't actually have ladders, I can save a couple cycles
  50.             hero.setHeroCanClimbLadders(true);
  51.             add(hero);
  52.            
  53.            
  54.            
  55.         }
  56.    
  57.     }
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement