ants/src/WorldInit.ts

23 lines
762 B
TypeScript

import { MAT_HOME, MAT_SAND } from "./constants";
export function generateSideViewWorld(worldSize: number): Float32Array {
const data = new Float32Array(worldSize * worldSize * 4);
const sandHeight = Math.floor(worldSize * 0.6);
const surfaceRow = sandHeight - 1;
// fill bottom 60% with sand
for (let y = 0; y < sandHeight; y++) {
for (let x = 0; x < worldSize; x++) {
const idx = (y * worldSize + x) * 4;
data[idx] = MAT_SAND;
}
}
// top 40% stays MAT_AIR (Float32Array is zero-initialized)
// place home on surface near center
const centerX = Math.floor(worldSize / 2);
const homeIdx = (surfaceRow * worldSize + centerX) * 4;
data[homeIdx] = MAT_HOME;
return data;
}