From 3e4622fa0e7459649005f6599b3ca36c940bd2be Mon Sep 17 00:00:00 2001 From: "Kacper Kostka (aider)" Date: Wed, 2 Apr 2025 13:50:38 +0200 Subject: [PATCH] feat: Add wolf packs spawning at map corners --- game.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/game.js b/game.js index 1c650e6..4bdc5f8 100644 --- a/game.js +++ b/game.js @@ -103,6 +103,38 @@ const WOLF_SPEED = 0.7; // Faster than rabbits /********************************************************************** * INIT WORLD **********************************************************************/ +// Function to spawn wolves at the corners of the map +function spawnWolvesAtCorners() { + const corners = [ + { x: -1800, y: -1800 }, + { x: -1800, y: 1800 }, + { x: 1800, y: -1800 }, + { x: 1800, y: 1800 } + ]; + + corners.forEach(corner => { + // Try to find valid placement near the corner + let x, y; + let attempts = 0; + do { + x = corner.x + randInt(-100, 100); + y = corner.y + randInt(-100, 100); + attempts++; + // Give up after too many attempts + if (attempts > 20) break; + } while (!isValidPlacement(x, y)); + + // If we found a valid spot, spawn 3 wolves there + if (attempts <= 20) { + for (let i = 0; i < 3; i++) { + const wolf = createAnimal("Wolf", x + randInt(-50, 50), y + randInt(-50, 50)); + animals.push(wolf); + } + logAction(`A pack of wolves has appeared near (${Math.floor(x)}, ${Math.floor(y)})!`); + } + }); +} + function initWorld() { // Normal trees - only on land for(let i=0; i<15; i++) { @@ -152,6 +184,9 @@ function initWorld() { } while (!isValidPlacement(x, y)); animals.push(createAnimal("Wolf", x, y)); } + + // Spawn wolves at the corners of the map + spawnWolvesAtCorners(); requestAnimationFrame(update); }