Guest User

Untitled

a guest
Aug 17th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.60 KB | None | 0 0
  1. Actionscript 3.0 - enemies do not move right in my game
  2. // If the Player's not on the ground (not touching the 'floor' MovieClip)...
  3. if (!onGround) {
  4. // Disable ducking
  5. downKeyPressed = false;
  6. // Increase the Player's 'y' position by his 'y' velocity
  7. player.y += playerYVel;
  8. }
  9.  
  10. // Increase the 'playerYVel' variable so that the Player will fall
  11. // progressively faster down the screen. This code technically
  12. // runs "all the time" but in reality it only affects the player
  13. // when he's off the ground.
  14. playerYVel += gravity;
  15.  
  16. // Give the Player a terminal velocity of 15 px/frame
  17. if (playerYVel > 15) {
  18. playerYVel = 15;
  19. }
  20.  
  21. // If the Player has not hit the 'floor,' increase his falling
  22. //speed
  23. if (! floor.hitTestPoint(player.x, player.y, true)) {
  24. player.y += playerYVel;
  25. // The Player is not on the ground when he's not touching it
  26. onGround = false;
  27. }
  28.  
  29. // Move all of the Skull Demons using this method
  30. protected function moveSkullDemons():void {
  31. // Go through the whole 'skullDemonContainer'
  32. for (var skullDi:int = 0; skullDi < skullDemonContainer.numChildren; skullDi++) {
  33. // Set the SkullDemon 'instance' variable to equal the current SkullDemon
  34. skullDIns = SkullDemon(skullDemonContainer.getChildAt(skullDi));
  35.  
  36. // For now, just move the Skull Demons left at 5 units per second
  37. skullDIns.x -= 5;
  38.  
  39. // If the Skull Demon has not hit the 'floor,' increase his falling
  40. //speed
  41. if (! floor.hitTestPoint(skullDIns.x, skullDIns.y, true)) {
  42. // Increase the Skull Demon's 'y' position by his 'y' velocity
  43. skullDIns.y += skullDIns.sdYVel;
  44. // The Skull Demon is not on the ground when he's not touching it
  45. skullDIns.sdOnGround = false;
  46. }
  47.  
  48. // Increase the 'sdYVel' variable so that the Skull Demon will fall
  49. // progressively faster down the screen. This code technically
  50. // runs "all the time" but in reality it only affects the Skull Demon
  51. // when he's off the ground.
  52. if (! skullDIns.sdOnGround) {
  53. skullDIns.sdYVel += skullDIns.sdGravity;
  54.  
  55. // Give the Skull Demon a terminal velocity of 15 px/frame
  56. if (skullDIns.sdYVel > 15) {
  57. skullDIns.sdYVel = 15;
  58. }
  59. }
  60.  
  61. // What happens when the Skull Demon lands on the ground after a fall?
  62. // The Skull Demon is only on the ground ('onGround == true') when
  63. // the ground is touching the Skull Demon MovieClip's origin point,
  64. // which is at the Skull Demon's bottom centre
  65. for (var i:int = 0; i < 10; i++) {
  66. // The Skull Demon is only on the ground ('onGround == true') when
  67. // the ground is touching the Skull Demon MovieClip's origin point,
  68. // which is at the Skull Demon's bottom centre
  69. if (floor.hitTestPoint(skullDIns.x, skullDIns.y, true)) {
  70. skullDIns.y = skullDIns.y;
  71. // Set the Skull Demon's y-axis speed to 0
  72. skullDIns.sdYVel = 0;
  73. // The Skull Demon is on the ground again
  74. skullDIns.sdOnGround = true;
  75. }
  76. }
  77. }
  78. } // End of 'moveSkullDemons()' function
Add Comment
Please, Sign In to add comment