refactor: helpers

This commit is contained in:
cha0s 2019-05-18 21:24:16 -05:00
parent 8a5cfd2112
commit c80ce9e8f7

View File

@ -531,33 +531,29 @@ function positionedEntityJSON(uri, position) {
};
}
function randomPosition() {
return [
Math.floor(Math.random() * (roomSize[0] - 100)) + 50,
Math.floor(Math.random() * (roomSize[1] - 100)) + 50,
];
}
function addEntityWithRandomPosition(uri) {
const position = randomPosition();
roomJSON.layers[0].entities.push(positionedEntityJSON(uri, position));
}
for (let i = 0; i < 50; ++i) {
const x = Math.floor(Math.random() * (roomSize[0] - 100)) + 50;
const y = Math.floor(Math.random() * (roomSize[1] - 100)) + 50;
roomJSON.layers[0].entities.push(
positionedEntityJSON('/flower-barrel.entity.json', [x, y])
);
addEntityWithRandomPosition('/flower-barrel.entity.json');
}
for (let i = 0; i < 5; ++i) {
const x = Math.floor(Math.random() * (roomSize[0] - 100)) + 50;
const y = Math.floor(Math.random() * (roomSize[1] - 100)) + 50;
roomJSON.layers[0].entities.push(
positionedEntityJSON('/mama-kitty-spawner.entity.json', [x, y])
);
addEntityWithRandomPosition('/mama-kitty-spawner.entity.json');
}
for (let i = 0; i < 60; ++i) {
const x = Math.floor(Math.random() * (roomSize[0] - 100)) + 50;
const y = Math.floor(Math.random() * (roomSize[1] - 100)) + 50;
roomJSON.layers[0].entities.push(
positionedEntityJSON('/fire.entity.json', [x, y])
);
addEntityWithRandomPosition('/fire.entity.json');
}
for (let i = 0; i < 5; ++i) {
const x = Math.floor(Math.random() * (roomSize[0] - 100)) + 50;
const y = Math.floor(Math.random() * (roomSize[1] - 100)) + 50;
roomJSON.layers[0].entities.push(
positionedEntityJSON('/blue-fire.entity.json', [x, y])
);
addEntityWithRandomPosition('/blue-fire.entity.json');
}
export function createRoom() {