Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.39 KB | None | 0 0
  1. package
  2. {
  3. import org.flixel.*;
  4.  
  5. public class Player extends FlxSprite
  6. {
  7.  
  8. // horizontal spritesheet
  9. [Embed(source="player.png")] private var _sprite:Class;
  10. [Embed(source="player_suit.png")] private var _sprite_suit:Class;
  11. [Embed(source="player_passed_out.png")] private var _sprite_passed_out:Class;
  12.  
  13. public var _jump:int;
  14. public var _climb:int;
  15. public var climbing:Boolean = false;
  16. public var ladderdragX:Number;
  17. public var ladderdragY:Number;
  18.  
  19. public var interacting:Boolean = false;
  20. public var walking:Boolean = false;
  21. public var shooting:Boolean = false;
  22.  
  23. public function Player(X:Number=0, Y:Number=0):void {
  24. super(632, 632);
  25. //super(8,8);
  26.  
  27. //loadGraphic(_sprite, true, false, 17, 7);
  28. loadGraphic(_sprite, true, false, 6, 17);
  29. //loadGraphic(_sprite_suit, true, false, 7, 18);
  30.  
  31. //player physics
  32. var runSpeed:uint = 45;
  33. drag.x = runSpeed*8;
  34. ladderdragX = 15;
  35. ladderdragY = 30;
  36. _jump = 70;
  37. _climb = 5;
  38. maxVelocity.x = runSpeed;
  39. maxVelocity.y = _jump;
  40.  
  41.  
  42.  
  43. addAnimation("walkr", [0,1,2], 10, true);
  44. addAnimation("walkl", [3,4,5], 10, true);
  45. addAnimation("idler", [0]);
  46. addAnimation("idlel", [3]);
  47. addAnimation("climb", [6,7], 5, true);
  48. addAnimation("interact", [8]);
  49. addAnimation("falling", [8]);
  50. addAnimation("shootr", [09,10,11], 6, false);
  51.  
  52. }
  53.  
  54. override public function update():void {
  55.  
  56.  
  57. //super.update();
  58. walking = false;
  59. climbing = false;
  60. interacting = false;
  61.  
  62. if( climbing ){
  63. play("climb");
  64. acceleration.y = 0;
  65. velocity.y = 0;
  66. if(FlxG.keys.UP){
  67. velocity.y = -ladderdragY;
  68. } else if(FlxG.keys.DOWN){
  69. velocity.y = ladderdragY;
  70. }
  71. if(FlxG.keys.LEFT){
  72. velocity.x = -maxVelocity.x/1.23;
  73. } else if(FlxG.keys.RIGHT){
  74. velocity.x = maxVelocity.x/1.23;
  75. }
  76. }
  77. if( !climbing ) {
  78. if(FlxG.keys.LEFT && !interacting){
  79. play("walkl");
  80. velocity.x = -maxVelocity.x;
  81. facing = FlxSprite.LEFT;
  82. } else if(FlxG.keys.RIGHT && !interacting){
  83. play("walkr");
  84. velocity.x = maxVelocity.x;
  85. facing = FlxSprite.RIGHT;
  86. }
  87.  
  88. if( FlxG.keys.UP && velocity.x == 0 ){
  89. play("interact");
  90. } else {
  91. if(velocity.x == 0) {
  92. if( facing == LEFT ) {
  93. play("idlel");
  94. } else if( facing == RIGHT) {
  95. play("idler");
  96. }
  97. }
  98. }
  99. }
  100.  
  101.  
  102. if( climbing ){
  103. acceleration.y = 0;
  104. drag.y = 200;
  105. } else {
  106. acceleration.y = 720;
  107. acceleration.x = 0;
  108. if(velocity.x == 0) {
  109. if( facing == LEFT) {
  110. //play("idlel");y
  111. } else if( facing == RIGHT) {
  112. //play("idler");
  113. }
  114. if(velocity.x > 0) {
  115. play("walkr");
  116. facing = RIGHT;
  117. } else if( velocity.x < 0) {
  118. play("walkl");
  119. facing = LEFT;
  120. }
  121. }
  122. }
  123.  
  124. //
  125. if(velocity.y != 0) {
  126. play("climb");
  127. if(climbing) {
  128. play("falling");
  129. }
  130. //
  131. }
  132. // else if(velocity.x == 0) {
  133. // if( facing == LEFT) {
  134. // play("idlel");
  135. // } else if( facing == RIGHT) {
  136. // play("idler");
  137. // }
  138. // }
  139. // else {
  140. // if(velocity.x > 0) {
  141. // play("walkr");
  142. // facing = RIGHT;
  143. // } else if( velocity.x < 0) {
  144. // play("walkl");
  145. // facing = LEFT;
  146. // }
  147. // }
  148. //update last
  149. super.update();
  150.  
  151. }
  152.  
  153. }
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement