Guest User

Untitled

a guest
Apr 25th, 2012
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package  {import org.flixel.*;public class Player extends FlxSprite{[Embed (source = "../data/player_nothing.png")] private var img_player_nothing:Class;[Embed (source = "../data/step0.mp3")] private var snd_step0:Class;[Embed (source = "../data/step1.mp3")] private var snd_step1:Class;[Embed (source = "../data/step2.mp3")] private var snd_step2:Class;[Embed (source = "../data/step3.mp3")] private var snd_step3:Class;[Embed (source = "../data/land.mp3")] private var snd_land:Class;[Embed (source = "../data/grab.mp3")] private var snd_grab:Class;[Embed (source = "../data/throw.mp3")] private var snd_throw:Class;public var speed:Number = 700;public var maxSpeed:Number = 220;public var ballString:String = "";public var holdingBall:Boolean = false;public var throwTimer:Number = 0;public var offGroundTime:Number = 0;public var timeSinceThrow:Number = 0;public var lastFrame:uint = 0;public var willPlayLandSound:Boolean = false;public var spinTimer:Number = 0;public function Player(x:int, y:int) {super(x, y);loadGraphic(img_player_nothing, true, true, 90, 100); addAnimation("idle", [0], 0, true);addAnimation("walk", [1, 2, 3, 4], 6, true);addAnimation("jump", [5, 6, 7], 5, true);addAnimation("idle_ball", [8], 0, true);addAnimation("walk_ball", [9, 10, 11, 12], 6, true);addAnimation("jump_ball", [13, 14, 15], 5, true);addAnimation("throw", [16], 6, true);play("idle");acceleration.y = 500;width = 40;offset.x = 25;height = 78;offset.y = 20;timeSinceThrow = -0.25;}override public function update():void {super.update();}override public function update():void {if (FlxG.state is PlayState){updateThrowing();ballString = holdingBall ? "_ball" : "";}updateMovement();if (justTouched(FLOOR) && willPlayLandSound){willPlayLandSound = false;FlxG.play(snd_land);}if (velocity.y >= 100) { willPlayLandSound = true; }if (lastFrame != _curFrame){if ((_curFrame == 1 || _curFrame == 3) && _curAnim.name.indexOf("walk") == 0){var r:int = Math.random() * 4;if (r == 0) { FlxG.play(snd_step0, 0.6); }if (r == 1) { FlxG.play(snd_step1, 0.6); }if (r == 2) { FlxG.play(snd_step2, 0.6); }if (r == 3) { FlxG.play(snd_step3, 0.6); }}lastFrame = _curFrame;}super.update();}public function updateThrowing():void{timeSinceThrow += FlxG.elapsed;if (FlxG.keys.justPressed("C")){var e:Earth = (FlxG.state as PlayState).earthif (holdingBall  && timeSinceThrow > 0.5){holdingBall = false;throwTimer = 0.25;var xv:Number = 420;var yv:Number = -130;if (FlxG.keys.UP){if (FlxG.keys.LEFT || FlxG.keys.RIGHT){xv = 340;yv = -300;}else{xv = 0;yv = -350;}}if (FlxG.keys.DOWN){if (FlxG.keys.LEFT || FlxG.keys.RIGHT){xv = 240;yv = 90;}else{xv = 0;yv = 250;}}if ((FlxG.state is Level1) || (FlxG.state is Level2)) { xv = 0; yv = 0; throwTimer = 0}e.spawn(x + (facing == LEFT ? 12 : 20), y + 22, new FlxPoint((facing == LEFT ? -xv : xv), yv));velocity.x += (facing == LEFT ? xv / 4 : -xv / 4);velocity.y += -yv / 4;timeSinceThrow = 0;if (xv != 0 || yv != 0){FlxG.play(snd_throw);}}else{var dx:Number = (e.x + e.width / 2) - (x + width / 2);var dy:Number = (e.y + e.height / 2) - (y + height / 2);if (dx * dx + dy * dy <= 110 * 110 && timeSinceThrow > 0.5){e.alive = false;e.visible = false;holdingBall = true;e.neverTouched = false;FlxG.play(snd_grab);e.buzz.stop();}}}if (throwTimer > 0){throwTimer -= FlxG.elapsed;play("throw");}}public function updateMovement():void{if (throwTimer > 0) { return; }var vx:Number = velocity.x;var vxChange:Number = 0;var moveKey:Boolean = false;if (FlxG.keys.LEFT){if (velocity.x > 0) { vxChange = -speed * FlxG.elapsed * (isTouching(FLOOR) ? 10 : 2);  }vx -= speed * FlxG.elapsed * (isTouching(FLOOR) ? 10 : 2);if (vx <= -maxSpeed) { vx = -maxSpeed; }if (isTouching(FLOOR)){play("walk" + ballString);}facing = LEFT;moveKey = true;}if (FlxG.keys.RIGHT){if (velocity.x < 0) { vxChange = speed * FlxG.elapsed * (isTouching(FLOOR) ? 10 : 2);  }vx += speed * FlxG.elapsed * (isTouching(FLOOR) ? 10 : 2);if (vx >= maxSpeed) { vx = maxSpeed; }if (isTouching(FLOOR)){play("walk" + ballString);}facing = RIGHT;moveKey = true;}if (Math.abs(velocity.x) > maxSpeed){velocity.x += vxChange;}else{velocity.x = vx;}if (!moveKey){if (isTouching(FLOOR)){velocity.x *= 0.8;if(Math.abs(velocity.x) < speed / 2){play("idle" + ballString);}}}if (!isTouching(FLOOR)){offGroundTime += FlxG.elapsed;}else{offGroundTime = 0;}if (offGroundTime > 0.25){play("jump" + ballString);}if (FlxG.keys.justPressed("X") && offGroundTime < 0.25){velocity.y = -320;offGroundTime = 0.26;y -= 1;}}}}
Advertisement
Add Comment
Please, Sign In to add comment