feat: Prevent placing entities on water and improve land generation
This commit is contained in:
44
game.js
44
game.js
@@ -97,27 +97,53 @@ const WOLF_SPEED = 0.7; // Faster than rabbits
|
||||
* INIT WORLD
|
||||
**********************************************************************/
|
||||
function initWorld() {
|
||||
// Normal trees
|
||||
// Normal trees - only on land
|
||||
for(let i=0; i<15; i++) {
|
||||
resources.push(createResource("Tree", randInt(-1000,1000), randInt(-1000,1000), 100));
|
||||
let x, y;
|
||||
do {
|
||||
x = randInt(-1000,1000);
|
||||
y = randInt(-1000,1000);
|
||||
} while (!isValidPlacement(x, y));
|
||||
resources.push(createResource("Tree", x, y, 100));
|
||||
}
|
||||
// Fruit trees
|
||||
|
||||
// Fruit trees - only on land
|
||||
for(let i=0; i<10; i++) {
|
||||
resources.push(createResource("FruitTree", randInt(-1000,1000), randInt(-1000,1000), FRUIT_TREE_START_AMOUNT));
|
||||
let x, y;
|
||||
do {
|
||||
x = randInt(-1000,1000);
|
||||
y = randInt(-1000,1000);
|
||||
} while (!isValidPlacement(x, y));
|
||||
resources.push(createResource("FruitTree", x, y, FRUIT_TREE_START_AMOUNT));
|
||||
}
|
||||
|
||||
// Start with 1 citizen => always a "Builder"
|
||||
let c = createCitizen(randomName(), randInt(-200,200), randInt(-200,200), "Builder");
|
||||
// Start with 1 citizen => always a "Builder" - only on land
|
||||
let cx, cy;
|
||||
do {
|
||||
cx = randInt(-200,200);
|
||||
cy = randInt(-200,200);
|
||||
} while (!isValidPlacement(cx, cy));
|
||||
let c = createCitizen(randomName(), cx, cy, "Builder");
|
||||
citizens.push(c);
|
||||
logAction(`Initial Citizen joined: ${c.name} [Builder]`);
|
||||
|
||||
// Spawn some animals
|
||||
// Spawn some animals - only on land
|
||||
for(let i=0; i<STARTING_RABBITS; i++) {
|
||||
animals.push(createAnimal("Rabbit", randInt(-1000,1000), randInt(-1000,1000)));
|
||||
let x, y;
|
||||
do {
|
||||
x = randInt(-1000,1000);
|
||||
y = randInt(-1000,1000);
|
||||
} while (!isValidPlacement(x, y));
|
||||
animals.push(createAnimal("Rabbit", x, y));
|
||||
}
|
||||
|
||||
for(let i=0; i<STARTING_WOLVES; i++) {
|
||||
animals.push(createAnimal("Wolf", randInt(-1000,1000), randInt(-1000,1000)));
|
||||
let x, y;
|
||||
do {
|
||||
x = randInt(-1000,1000);
|
||||
y = randInt(-1000,1000);
|
||||
} while (!isValidPlacement(x, y));
|
||||
animals.push(createAnimal("Wolf", x, y));
|
||||
}
|
||||
|
||||
requestAnimationFrame(update);
|
||||
|
||||
Reference in New Issue
Block a user