Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Actionscript 3.0 - enemies do not move right in my game
- // If the Player's not on the ground (not touching the 'floor' MovieClip)...
- if (!onGround) {
- // Disable ducking
- downKeyPressed = false;
- // Increase the Player's 'y' position by his 'y' velocity
- player.y += playerYVel;
- }
- // Increase the 'playerYVel' variable so that the Player will fall
- // progressively faster down the screen. This code technically
- // runs "all the time" but in reality it only affects the player
- // when he's off the ground.
- playerYVel += gravity;
- // Give the Player a terminal velocity of 15 px/frame
- if (playerYVel > 15) {
- playerYVel = 15;
- }
- // If the Player has not hit the 'floor,' increase his falling
- //speed
- if (! floor.hitTestPoint(player.x, player.y, true)) {
- player.y += playerYVel;
- // The Player is not on the ground when he's not touching it
- onGround = false;
- }
- // Move all of the Skull Demons using this method
- protected function moveSkullDemons():void {
- // Go through the whole 'skullDemonContainer'
- for (var skullDi:int = 0; skullDi < skullDemonContainer.numChildren; skullDi++) {
- // Set the SkullDemon 'instance' variable to equal the current SkullDemon
- skullDIns = SkullDemon(skullDemonContainer.getChildAt(skullDi));
- // For now, just move the Skull Demons left at 5 units per second
- skullDIns.x -= 5;
- // If the Skull Demon has not hit the 'floor,' increase his falling
- //speed
- if (! floor.hitTestPoint(skullDIns.x, skullDIns.y, true)) {
- // Increase the Skull Demon's 'y' position by his 'y' velocity
- skullDIns.y += skullDIns.sdYVel;
- // The Skull Demon is not on the ground when he's not touching it
- skullDIns.sdOnGround = false;
- }
- // Increase the 'sdYVel' variable so that the Skull Demon will fall
- // progressively faster down the screen. This code technically
- // runs "all the time" but in reality it only affects the Skull Demon
- // when he's off the ground.
- if (! skullDIns.sdOnGround) {
- skullDIns.sdYVel += skullDIns.sdGravity;
- // Give the Skull Demon a terminal velocity of 15 px/frame
- if (skullDIns.sdYVel > 15) {
- skullDIns.sdYVel = 15;
- }
- }
- // What happens when the Skull Demon lands on the ground after a fall?
- // The Skull Demon is only on the ground ('onGround == true') when
- // the ground is touching the Skull Demon MovieClip's origin point,
- // which is at the Skull Demon's bottom centre
- for (var i:int = 0; i < 10; i++) {
- // The Skull Demon is only on the ground ('onGround == true') when
- // the ground is touching the Skull Demon MovieClip's origin point,
- // which is at the Skull Demon's bottom centre
- if (floor.hitTestPoint(skullDIns.x, skullDIns.y, true)) {
- skullDIns.y = skullDIns.y;
- // Set the Skull Demon's y-axis speed to 0
- skullDIns.sdYVel = 0;
- // The Skull Demon is on the ground again
- skullDIns.sdOnGround = true;
- }
- }
- }
- } // End of 'moveSkullDemons()' function
Add Comment
Please, Sign In to add comment