Advertisement
Guest User

Untitled

a guest
May 27th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package
  2. {
  3.     import org.flixel.*;
  4.     import org.flixel.data.*;
  5.  
  6.     public class PlayState extends FlxState
  7.     {
  8.  
  9.         [Embed(source='../lib/tile.png')]
  10.         private var ImgTiles:Class;
  11.         [Embed(source = '../lib/map.txt',mimeType = "application/octet-stream")]
  12.         private var DataMap:Class;
  13.         private var _player:Player;
  14.         private var _map:FlxTilemap;
  15.         public var coins:FlxGroup = new FlxGroup  ;
  16.         public static var goodCoins:int = 0;
  17.         public var badCoins:int = 5;
  18.         public var bCoin:FlxGroup = new FlxGroup  ;
  19.         public var lyrStage:FlxGroup = new FlxGroup  ;
  20.         public var lyrSprites:FlxGroup = new FlxGroup  ;
  21.         public var lyrHUD:FlxGroup = new FlxGroup  ;
  22.         private var timeVar:Number = 300;
  23.         private var previousTime:int = timeVar;
  24.         private var timerText:FlxText = new FlxText(0, 0, FlxG.width, "" + (timeVar) );
  25.         private var totalRedCoins:int = 0;
  26.         public var s:Coin = new Coin(true);
  27.  
  28.  
  29.         override public function create():void
  30.         {
  31.             //FlxG.showBounds = true;
  32.             s.exists = false;
  33.             _map = new FlxTilemap  ;
  34.             _map.drawIndex = 0;// drawIndex need to be set before loadMap()
  35.             _map.loadMap(new DataMap  ,ImgTiles,16);
  36.             _map.collideIndex = 1;
  37.             lyrStage.add(_map);
  38.             _player = new Player(20, 20);
  39.  
  40.  
  41.            
  42.             var e:FlxEmitter = new FlxEmitter();
  43.                 e.width = 1;
  44.                 e.y = 48
  45.                 e.x = 48
  46.                 e.delay = 5;
  47.                 e.gravity = 0;
  48.                 e.setXSpeed(-1,50);
  49.                 e.setYSpeed( -1, 50);
  50.                 e.maxRotation = 0;
  51.                 e.minRotation = 0;
  52.                 var particles:uint = 100;
  53.                 for(var i:uint = 0; i < particles; i++)
  54.                 {
  55.                    
  56.                    
  57.                     e.add(s);
  58.                 }
  59.                 e.start(false);
  60.                 add(e);
  61.                
  62.                
  63.  
  64.             lyrSprites.add(e);
  65.             lyrSprites.add(bCoin);
  66.             lyrSprites.add(_player);
  67.             lyrHUD.add(timerText);
  68.             timerText.scrollFactor.x = timerText.scrollFactor.y = 0;
  69.             add(lyrStage);
  70.             add(lyrSprites);
  71.             add(lyrHUD);
  72.              
  73.         }
  74.  
  75.  
  76.         override public function update():void
  77.         {
  78.            
  79.  
  80.             if (previousTime > int(timeVar))
  81.             {
  82.                 timerText.text = int(timeVar) + " seconds left  " + "level " + _player.sprite + "    " + badCoins + " red till devolve"
  83.                 previousTime = int(timeVar);
  84.                 trace(timerText.text);
  85.             }
  86.             timeVar -= FlxG.elapsed;
  87.            
  88.            
  89.        
  90.             super.update();
  91.  
  92.             _player.scale.x = _player.scale.y = 2;
  93.             FlxU.overlap(_player,coins,hitCoin);
  94.             FlxU.overlap(_player,bCoin,hitBadCoin);
  95.             _map.collide(_player);
  96.  
  97.             _map.collide(coins);
  98.  
  99.             trace(int(_player.x), int(_player.y));
  100.            
  101.             FlxG.follow(_player,2.5);
  102.             FlxG.followAdjust(0.5,0.5);
  103.             FlxG.followBounds(1,1,1936 - 1,496 - 1);
  104.  
  105.             if ((_player.sprite == 0 && badCoins == 0) || previousTime ==0)
  106.             {
  107.                 FlxG.state = new DeadState  ;
  108.             }
  109.             if (_player.sprite == 9 && goodCoins >= 60)
  110.             {
  111.                 FlxG.state = new WinState  ;
  112.             }
  113.  
  114.             if (_player.sprite < 9 && goodCoins == 55)
  115.             {
  116.                 FlxG.state = new StarveState  ;
  117.             }
  118.         }
  119.         public function hitCoin(player:Player,coin:FlxObject):void
  120.         {
  121.             trace("hit good coin");
  122.             coin.exists = false;
  123.             goodCoins++;
  124.             trace(goodCoins);
  125.             if (goodCoins % 10 == 0 && _player.sprite < 3)
  126.             {
  127.                 player.sprite++;
  128.                 trace(player.sprite);
  129.                 badCoins == 5;
  130.                 timeVar -= FlxG.elapsed;
  131.                 timeVar = 300;
  132.                 previousTime = int(timeVar);
  133.  
  134.             }
  135.            
  136.  
  137.         }
  138.         public function hitBadCoin(player:Player,cy:FlxObject):void
  139.         {
  140.             trace("hit bad coin");
  141.  
  142.             cy.exists = false;
  143.             if (FlxG.kong)
  144.             {
  145.                 FlxG.kong.API.stats.submit( "Total Red Fish Eaten", 1 );
  146.             }
  147.             trace(badCoins);
  148.             badCoins --;
  149.             if (badCoins == 0)
  150.             {
  151.                 player.sprite--;
  152.                 trace(player.sprite);
  153.                 badCoins = 5;
  154.                
  155.             }
  156.         }
  157.     }
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement