Guest User

Untitled

a guest
Jan 19th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.57 KB | None | 0 0
  1. override public function update():void
  2. {
  3. //do not update the player if we've won
  4. if (Global.completed) { return; }
  5.  
  6. super.update();
  7. if (inControl)
  8. {
  9. FP.camera.y -= Math.round((FP.camera.y + (FP.height - 550)));
  10. if (shootingDirection.x == 1)
  11. {
  12. FP.camera.x -= Math.round((FP.camera.x - (x - FP.width + 600)) / 20);
  13. }
  14. else if (shootingDirection.x == -1)
  15. {
  16. FP.camera.x -= Math.round((FP.camera.x - ((x - 500) - FP.width + 600)) / 20);
  17. }
  18. FP.camera.x = FP.clamp(FP.camera.x, Global.level.minXCamera, Global.level.maxXCamera-800);
  19. //accelerate
  20. if (!dead)
  21. {
  22. setHitbox(64, 96, 32, 48);
  23. while (positionList.length > maxPositions)
  24. {
  25. delete positionList.shift();
  26. }
  27. //shootingDirection.x = 0; shootingDirection.y = 0;
  28.  
  29. if (Input.check(Key.RIGHT))
  30. {
  31. velocity.x += ACCELERATION;
  32. shootingDirection.x = 1;
  33. positionList.push(new Vector2(x, y));
  34. }
  35. else if (Input.check(Key.LEFT))
  36. {
  37. velocity.x -= ACCELERATION;
  38. shootingDirection.x = -1;
  39. positionList.push(new Vector2(x, y));
  40. }
  41. else if(Input.check(Key.UP) || Input.check(Key.DOWN)){
  42. shootingDirection.x = 0;
  43. }
  44. if (Input.check(Key.UP))
  45. {
  46. shootingDirection.y = -1;
  47. }
  48. else if ((Input.check(Key.DOWN) && !collide("Ground", x, y + 1)) ||
  49. (Input.check(Key.DOWN) && shootingDirection.x != 0))
  50. {
  51. shootingDirection.y = 1;
  52. }
  53. else if(Input.check(Key.DOWN) && collide("Ground", x, y+1))
  54. {
  55. shootingDirection.y = 0;
  56. setHitbox(64, 64, 32, 32);
  57. }
  58. else
  59. {
  60. shootingDirection.y = 0;
  61. }
  62. shootingDirection.x = shootingDirection.x == 0 && shootingDirection.y == 0 ? 1 : shootingDirection.x;
  63. //Normal jump. If jump key pressed, and we collide with a wall below us, JUMP
  64. if (Input.pressed(Key.X) && collide("Ground", x, y + 1)) { velocity.y = - 6; jumpSound.play(); }
  65. if ((powerUp.press && Input.check(Key.Z)) || (!powerUp.press && Input.pressed(Key.Z)))
  66. {
  67. attacking = true;
  68. if (inControl)
  69. {
  70. if (powerUp.ammo == 0)
  71. {
  72. world.remove(powerUp);
  73. powerUp = null;
  74. powerUp = defaultPowerUp;
  75. }
  76. else
  77. {
  78. powerUp.shoot(new Vector2(shootingDirection.x * 1000, shootingDirection.y * 1000));
  79. }
  80. }
  81. }
  82. else
  83. {
  84. attacking = false;
  85. powerUp.shootTimer = 0.0;
  86. }
  87. }
  88.  
  89. //friction (if we are NOT moving left/right)
  90. if ((!Input.check(Key.LEFT) && !Input.check(Key.RIGHT)) || dead)
  91. {
  92. //reduce speed
  93. //FP.sign returns -1, 0, or 1 based on the speed.x
  94. velocity.x -= FP.sign(velocity.x) * FRICTION;
  95.  
  96. //if the speed is less than the friction, stop moving (to avoid
  97. //us starting to move in the other direction, which causes a shake/jitter effect)
  98. if (Math.abs(velocity.x) < FRICTION) { velocity.x = 0; }
  99.  
  100. //set the sprite to the right standing position (based on our current direction)
  101. if (shootingDirection.x > 0) { /*sprite.play("StandRight"); } else { sprite.play("StandLeft");*/ }
  102. if (positionList.length > 0)
  103. {
  104. positionList.length = 0;
  105. }
  106. }
  107.  
  108. //maxspeed (stop us from going too fast)
  109. if (Math.abs(velocity.x) > MAXSPEED.x) { velocity.x = FP.sign(velocity.x) * MAXSPEED.x; }
  110. if (Math.abs(velocity.y) > MAXSPEED.y) { velocity.y = FP.sign(velocity.y) * MAXSPEED.y; }
  111.  
  112. //Pixel Perfect Moving
  113. //Loop through the following code for how fast our speed (Left/Right) is
  114. //(ex. if our speed is 3, repeat the following code 3 times)
  115. for (var i:int = 0; i < Math.abs(velocity.x); i ++)
  116. {
  117. //If we DID NOT hit a wall left/right of us (based on our speed (FP.sign)),
  118. //then move a single pixel in the correct direction.
  119. //OTHERWISE (else) set our speed to 0 (we hit a wall)
  120. if (!collide("Ground", x + FP.sign(velocity.x), y)) { x += FP.sign(velocity.x); } else { velocity.x = 0; }
  121.  
  122. }
  123.  
  124. //this loop is exactly the same as the one above, except for moving UP/DOWN
  125. for (var j:int = 0; j < Math.abs(Math.floor(velocity.y)); j ++)
  126. {
  127.  
  128. if (!collide("Ground", x, y + FP.sign(velocity.y))) { y += FP.sign(velocity.y); } else { velocity.y = 0; }
  129.  
  130. }
  131.  
  132. //gravity. increase Y speed so we move down
  133. velocity.y += GRAVITY;
  134. }
  135. else
  136. {
  137. if (positionList.length > 0)
  138. {
  139. positionList.length = 0;
  140. }
  141. }
  142.  
  143. }
Add Comment
Please, Sign In to add comment