import {Vector} from '@avocado/math'; function tileData(size) { const tileCount = Vector.area(size); const tileData = []; for (let i = 0; i < tileCount; ++i) { // 75% chance it's grass. if (Math.random() > 0.25) { tileData.push(Math.floor(Math.random() * 4) + 1); } else { // Otherwise, 50/50 between stone and dirt. tileData.push(Math.floor(Math.random() * 2) + 5); } } return tileData; } // Room. export function kittyFireJSON() { const roomTileSize = [24, 24]; const roomSize = Vector.mul([16, 16], roomTileSize); const roomJSON = { size: roomSize, layers: [ { entities: [], tiles: { size: roomTileSize, data: tileData(roomTileSize), }, tilesetUri: '/tileset.json', }, ], }; function positionedEntityJSON(uri, position) { return { uri, traits: { positioned: { state: { x: position[0], y: position[1], }, }, }, }; } 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 < 20; ++i) { // addEntityWithRandomPosition('/rock.entity.json'); // } for (let i = 0; i < 30; ++i) { addEntityWithRandomPosition('/flower-barrel.entity.json'); } for (let i = 0; i < 5; ++i) { addEntityWithRandomPosition('/mama-kitty-spawner.entity.json'); } for (let i = 0; i < 50; ++i) { addEntityWithRandomPosition('/fire.entity.json'); } for (let i = 0; i < 5; ++i) { addEntityWithRandomPosition('/blue-fire.entity.json'); } return roomJSON; }