Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package
- {
- import org.flixel.*;
- public class Player extends FlxSprite
- {
- // horizontal spritesheet
- [Embed(source="player.png")] private var _sprite:Class;
- [Embed(source="player_suit.png")] private var _sprite_suit:Class;
- [Embed(source="player_passed_out.png")] private var _sprite_passed_out:Class;
- public var _jump:int;
- public var _climb:int;
- public var climbing:Boolean = false;
- public var ladderdragX:Number;
- public var ladderdragY:Number;
- public var interacting:Boolean = false;
- public var walking:Boolean = false;
- public var shooting:Boolean = false;
- public function Player(X:Number=0, Y:Number=0):void {
- super(632, 632);
- //super(8,8);
- //loadGraphic(_sprite, true, false, 17, 7);
- loadGraphic(_sprite, true, false, 6, 17);
- //loadGraphic(_sprite_suit, true, false, 7, 18);
- //player physics
- var runSpeed:uint = 45;
- drag.x = runSpeed*8;
- ladderdragX = 15;
- ladderdragY = 30;
- _jump = 70;
- _climb = 5;
- maxVelocity.x = runSpeed;
- maxVelocity.y = _jump;
- addAnimation("walkr", [0,1,2], 10, true);
- addAnimation("walkl", [3,4,5], 10, true);
- addAnimation("idler", [0]);
- addAnimation("idlel", [3]);
- addAnimation("climb", [6,7], 5, true);
- addAnimation("interact", [8]);
- addAnimation("falling", [8]);
- addAnimation("shootr", [09,10,11], 6, false);
- }
- override public function update():void {
- //super.update();
- walking = false;
- climbing = false;
- interacting = false;
- if( climbing ){
- play("climb");
- acceleration.y = 0;
- velocity.y = 0;
- if(FlxG.keys.UP){
- velocity.y = -ladderdragY;
- } else if(FlxG.keys.DOWN){
- velocity.y = ladderdragY;
- }
- if(FlxG.keys.LEFT){
- velocity.x = -maxVelocity.x/1.23;
- } else if(FlxG.keys.RIGHT){
- velocity.x = maxVelocity.x/1.23;
- }
- }
- if( !climbing ) {
- if(FlxG.keys.LEFT && !interacting){
- play("walkl");
- velocity.x = -maxVelocity.x;
- facing = FlxSprite.LEFT;
- } else if(FlxG.keys.RIGHT && !interacting){
- play("walkr");
- velocity.x = maxVelocity.x;
- facing = FlxSprite.RIGHT;
- }
- if( FlxG.keys.UP && velocity.x == 0 ){
- play("interact");
- } else {
- if(velocity.x == 0) {
- if( facing == LEFT ) {
- play("idlel");
- } else if( facing == RIGHT) {
- play("idler");
- }
- }
- }
- }
- if( climbing ){
- acceleration.y = 0;
- drag.y = 200;
- } else {
- acceleration.y = 720;
- acceleration.x = 0;
- if(velocity.x == 0) {
- if( facing == LEFT) {
- //play("idlel");y
- } else if( facing == RIGHT) {
- //play("idler");
- }
- if(velocity.x > 0) {
- play("walkr");
- facing = RIGHT;
- } else if( velocity.x < 0) {
- play("walkl");
- facing = LEFT;
- }
- }
- }
- //
- if(velocity.y != 0) {
- play("climb");
- if(climbing) {
- play("falling");
- }
- //
- }
- // else if(velocity.x == 0) {
- // if( facing == LEFT) {
- // play("idlel");
- // } else if( facing == RIGHT) {
- // play("idler");
- // }
- // }
- // else {
- // if(velocity.x > 0) {
- // play("walkr");
- // facing = RIGHT;
- // } else if( velocity.x < 0) {
- // play("walkl");
- // facing = LEFT;
- // }
- // }
- //update last
- super.update();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement