feat: Add wolf packs spawning at map corners
This commit is contained in:
parent
854ac99f52
commit
3e4622fa0e
35
game.js
35
game.js
@ -103,6 +103,38 @@ const WOLF_SPEED = 0.7; // Faster than rabbits
|
|||||||
/**********************************************************************
|
/**********************************************************************
|
||||||
* INIT WORLD
|
* 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() {
|
function initWorld() {
|
||||||
// Normal trees - only on land
|
// Normal trees - only on land
|
||||||
for(let i=0; i<15; i++) {
|
for(let i=0; i<15; i++) {
|
||||||
@ -152,6 +184,9 @@ function initWorld() {
|
|||||||
} while (!isValidPlacement(x, y));
|
} while (!isValidPlacement(x, y));
|
||||||
animals.push(createAnimal("Wolf", x, y));
|
animals.push(createAnimal("Wolf", x, y));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Spawn wolves at the corners of the map
|
||||||
|
spawnWolvesAtCorners();
|
||||||
|
|
||||||
requestAnimationFrame(update);
|
requestAnimationFrame(update);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user