diff --git a/src/gameobjects/enemy.ts b/src/gameobjects/enemy.ts index e5058d6..5a9aac7 100644 --- a/src/gameobjects/enemy.ts +++ b/src/gameobjects/enemy.ts @@ -1,7 +1,8 @@ import { Sprite, Tag } from '../constants' import type { Player } from '../types' -const ENEMY_SPEED = 200 +const ENEMY_SPEED_MIN = 100 +const ENEMY_SPEED_MAX = 300 export function addEnemy(x: number, y: number, player: Player) { const enemy = add([ @@ -16,7 +17,7 @@ export function addEnemy(x: number, y: number, player: Player) { enemy.onUpdate(() => { const dir = player.pos.sub(enemy.pos).unit() - enemy.move(dir.scale(ENEMY_SPEED)) + enemy.move(dir.scale(rand(ENEMY_SPEED_MIN, ENEMY_SPEED_MAX))) }) enemy.onHurt(() => { diff --git a/src/scenes/game.ts b/src/scenes/game.ts index 9883e79..ac5af7d 100644 --- a/src/scenes/game.ts +++ b/src/scenes/game.ts @@ -7,8 +7,28 @@ scene(Scene.Game, () => { add([text('Press arrow keys', { width: width() / 2 }), pos(12, 12)]) loop(5, () => { - const x = rand(0, width()) - const y = rand(0, height()) - addEnemy(x, y, player) + if (coinflip()) { + // right + addEnemy(width(), rand(0, height()), player) + } + + if (coinflip()) { + // left + addEnemy(-32, rand(0, height()), player) + } + + if (coinflip()) { + // top + addEnemy(rand(0, width()), height(), player) + } + + if (coinflip()) { + // bottom + addEnemy(rand(0, width()), -32, player) + } }) }) + +function coinflip() { + return Boolean(randi(2)) +}