diff options
-rw-r--r-- | html/mountain/game.js | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/html/mountain/game.js b/html/mountain/game.js index 8cbfa4d..7db1892 100644 --- a/html/mountain/game.js +++ b/html/mountain/game.js @@ -30,6 +30,11 @@ const PARTITION_RATIO = 0.3; const MIN_PLATFORM_SPACING = 100; const DEADLY_BORDER_HEIGHT = 7; +const ENEMY_SPEED = 2; + +const FALLING_PLATFORM_DELAY = 800; +const FALLING_PLATFORM_GRAVITY = 0.5; + const FPS = 60; const FRAME_TIME = 1000 / FPS; @@ -44,11 +49,6 @@ const DEATH_PARTICLE_SIZE = 4; const DEATH_PARTICLE_LIFETIME = 50; const DEATH_ANIMATION_DURATION = 55; -const ENEMY_SPEED = 2; - -const FALLING_PLATFORM_DELAY = 800; -const FALLING_PLATFORM_GRAVITY = 0.5; - const PLATFORM_PARTICLE_COUNT = 30; const PLATFORM_PARTICLE_SPEED = 8; const PLATFORM_PARTICLE_SIZE = 4; @@ -154,12 +154,23 @@ function platformsOverlap(platform1, platform2) { function createParticle(x, y, velocityY) { return { + // Randomly places particles around the player, within the player's width x: x + PLAYER_SIZE / 2 + (Math.random() - 0.5) * PLAYER_SIZE, + + // Put particles to the top or bottom of the player depending on the direction + // the player is moving y: y + (velocityY > 0 ? 0 : PLAYER_SIZE), + + // Zoot out to the left and right of the player velocityX: (Math.random() - 0.5) * PARTICLE_SPEED * 2, + + // Zoot up or down, matching the player's direction velocityY: (Math.random() * PARTICLE_SPEED) * Math.sign(velocityY), + + // Add some variety to the particle sizes size: PARTICLE_SIZE + Math.random() * 2, - life: PARTICLE_LIFETIME, + + life: PARTICLE_LIFETIME, initialOpacity: 0.3 + Math.random() * 0.7 }; } |