Advertisement
Guest User

Untitled

a guest
May 28th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package
  2. {
  3.     import org.flixel.*;
  4.  
  5.     public class PlayState extends FlxState
  6.     {
  7.         private var player:FlxSprite = new FlxSprite;
  8.         private var floor:FlxSprite = new FlxSprite;
  9.         private var leftWall:FlxSprite = new FlxSprite;
  10.         private var rightWall:FlxSprite = new FlxSprite;
  11.         private var playerSpeed:int = 400;
  12.         private var s:FlxSprite = new FlxSprite;
  13.         private const blur:Number = 0.35;
  14.         private var helper:FlxSprite;
  15.         private var score:int = 0;
  16.         private var scoreText:FlxText;
  17.         private var playerWidth:int = 16;
  18.        
  19.         override public function create():void
  20.         {
  21.             scoreText = new FlxText((FlxG.width / 2)-100, 20, 100, "Score: " + score + "");
  22.             scoreText.alignment = "center";
  23.             add(scoreText);
  24.            
  25.             helper = new FlxSprite;
  26.             helper.createGraphic(FlxG.width, FlxG.height, 0xFF000000, true);
  27.             helper.alpha = blur;
  28.            
  29.             player.createGraphic(playerWidth, 8, 0xFFFF8000, true);
  30.             add(player);
  31.             player.y = 220;
  32.             player.x = 50
  33.             player.acceleration.y = 300;
  34.             player.drag.x = 100;
  35.             player.drag.y = 100;
  36.             player.maxVelocity.x = player.maxVelocity.y = 200;
  37.            
  38.             rightWall.createGraphic(5, FlxG.height, 0xFFFFFFFF);
  39.             rightWall.fixed = true;
  40.             rightWall.x = FlxG.width - 5;
  41.             add(rightWall);
  42.            
  43.             leftWall.createGraphic(5, FlxG.height, 0xFFFFFFFF);
  44.             leftWall.fixed = true;
  45.             add(leftWall);
  46.            
  47.             floor.createGraphic(FlxG.width, 5, 0xFFFFFFFF);
  48.             floor.x = 0;
  49.             floor.y = 235;
  50.             floor.fixed = true;
  51.             add(floor)
  52.            
  53.             var e:FlxEmitter = new FlxEmitter;
  54.             e.width = (FlxG.width - 30);
  55.             e.x = (FlxG.width / 2);
  56.             e.y = -10;
  57.             e.delay = 2;
  58.             e.gravity = 1;
  59.             e.setXSpeed();
  60.             e.minRotation = -20;
  61.             e.maxRotation = 20;
  62.             e.setYSpeed(0, 20);
  63.             var particles:int = 19;
  64.             for (var i:uint = 0; i < particles; i ++)
  65.             {
  66.                 s.createGraphic(10, 10, 0xFFFF8000);
  67.                 s.exists = false;
  68.                 e.add(s);
  69.             }
  70.             e.start(false);
  71.             add(e);
  72.            
  73.            
  74.         }
  75.         override public function update():void
  76.         {
  77.             if (FlxG.keys.RIGHT)
  78.                 player.velocity.x += playerSpeed * FlxG.elapsed;
  79.             if (FlxG.keys.LEFT)
  80.                 player.velocity.x -= playerSpeed * FlxG.elapsed;
  81.             FlxU.collide(floor, player);
  82.             FlxU.collide(leftWall, player);
  83.             FlxU.collide(rightWall, player);
  84.             if (FlxU.collide(s, floor))
  85.                 s.exists = false;
  86.             if (FlxU.collide(s, player))
  87.             {
  88.                 s.exists = false;
  89.                 score ++;
  90.                 playerWidth = player.width + 8;
  91.             }
  92.             scoreText.text = "Score: " + score + "";
  93.             player.width = playerWidth;
  94.             super.update();
  95.         }
  96.         override public function preProcess():void
  97.         {
  98.             screen.draw(helper);
  99.         }
  100.     }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement