Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package
- {
- import org.flixel.*;
- public class PlayState extends FlxState
- {
- private var player:FlxSprite = new FlxSprite;
- private var floor:FlxSprite = new FlxSprite;
- private var leftWall:FlxSprite = new FlxSprite;
- private var rightWall:FlxSprite = new FlxSprite;
- private var playerSpeed:int = 400;
- private var s:FlxSprite = new FlxSprite;
- private const blur:Number = 0.35;
- private var helper:FlxSprite;
- private var score:int = 0;
- private var scoreText:FlxText;
- private var playerWidth:int = 16;
- override public function create():void
- {
- scoreText = new FlxText((FlxG.width / 2)-100, 20, 100, "Score: " + score + "");
- scoreText.alignment = "center";
- add(scoreText);
- helper = new FlxSprite;
- helper.createGraphic(FlxG.width, FlxG.height, 0xFF000000, true);
- helper.alpha = blur;
- player.createGraphic(playerWidth, 8, 0xFFFF8000, true);
- add(player);
- player.y = 220;
- player.x = 50
- player.acceleration.y = 300;
- player.drag.x = 100;
- player.drag.y = 100;
- player.maxVelocity.x = player.maxVelocity.y = 200;
- rightWall.createGraphic(5, FlxG.height, 0xFFFFFFFF);
- rightWall.fixed = true;
- rightWall.x = FlxG.width - 5;
- add(rightWall);
- leftWall.createGraphic(5, FlxG.height, 0xFFFFFFFF);
- leftWall.fixed = true;
- add(leftWall);
- floor.createGraphic(FlxG.width, 5, 0xFFFFFFFF);
- floor.x = 0;
- floor.y = 235;
- floor.fixed = true;
- add(floor)
- var e:FlxEmitter = new FlxEmitter;
- e.width = (FlxG.width - 30);
- e.x = (FlxG.width / 2);
- e.y = -10;
- e.delay = 2;
- e.gravity = 1;
- e.setXSpeed();
- e.minRotation = -20;
- e.maxRotation = 20;
- e.setYSpeed(0, 20);
- var particles:int = 19;
- for (var i:uint = 0; i < particles; i ++)
- {
- s.createGraphic(10, 10, 0xFFFF8000);
- s.exists = false;
- e.add(s);
- }
- e.start(false);
- add(e);
- }
- override public function update():void
- {
- if (FlxG.keys.RIGHT)
- player.velocity.x += playerSpeed * FlxG.elapsed;
- if (FlxG.keys.LEFT)
- player.velocity.x -= playerSpeed * FlxG.elapsed;
- FlxU.collide(floor, player);
- FlxU.collide(leftWall, player);
- FlxU.collide(rightWall, player);
- if (FlxU.collide(s, floor))
- s.exists = false;
- if (FlxU.collide(s, player))
- {
- s.exists = false;
- score ++;
- playerWidth = player.width + 8;
- }
- scoreText.text = "Score: " + score + "";
- player.width = playerWidth;
- super.update();
- }
- override public function preProcess():void
- {
- screen.draw(helper);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement