🔬 The distance threshold 2.6 controls the leaf canopy shape. What happens if you change it to 3.5? To 1.5? Does the tree look rounder or pointier?
for (let lx = -2; lx <= 2; lx++) {
for (let ly = -2; ly <= 1; ly++) {
const tx = x + lx;
const ty = leafY + ly;
if (tx >= 0 && tx < WORLD_WIDTH && ty >= 0 && ty < WORLD_HEIGHT) {
if (dist(lx, ly, 0, 0) < 2.6 && world[tx][ty] === AIR) {
world[tx][ty] = LEAVES;
}
}
}
}
function initWorld() {
world = new Array(WORLD_WIDTH);
for (let x = 0; x < WORLD_WIDTH; x++) {
world[x] = new Array(WORLD_HEIGHT).fill(AIR);
}
const baseHeight = 30;
for (let x = 0; x < WORLD_WIDTH; x++) {
let h = floor(noise(x * 0.12) * 10) + baseHeight;
h = constrain(h, 12, WORLD_HEIGHT - 6);
for (let y = h; y < WORLD_HEIGHT; y++) {
world[x][y] = STONE;
}
if (h - 1 >= 0) world[x][h - 1] = GRASS;
if (h - 2 >= 0) world[x][h - 2] = DIRT;
if (h - 3 >= 0) world[x][h - 3] = DIRT;
if (random() < 0.08 && h - 4 > 0) {
const trunkHeight = 4;
for (let t = 0; t < trunkHeight; t++) {
const ty = h - 2 - t;
if (ty >= 0) world[x][ty] = WOOD;
}
const leafY = h - 2 - trunkHeight;
for (let lx = -2; lx <= 2; lx++) {
for (let ly = -2; ly <= 1; ly++) {
const tx = x + lx;
const ty = leafY + ly;
if (tx >= 0 && tx < WORLD_WIDTH && ty >= 0 && ty < WORLD_HEIGHT) {
if (dist(lx, ly, 0, 0) < 2.6 && world[tx][ty] === AIR) {
world[tx][ty] = LEAVES;
}
}
}
}
}
}
const spawnX1 = floor(WORLD_WIDTH / 2);
let spawnY1 = 0;
for (let y = 0; y < WORLD_HEIGHT; y++) {
if (world[spawnX1][y] !== AIR) {
spawnY1 = y - 1;
break;
}
}
const spawnX2 = spawnX1 + 2;
let spawnY2 = 0;
for (let y = 0; y < WORLD_HEIGHT; y++) {
if (world[spawnX2][y] !== AIR) {
spawnY2 = y - 1;
break;
}
}
players = [
{
x: spawnX1 * TILE_SIZE,
y: spawnY1 * TILE_SIZE - PLAYER_HEIGHT,
w: PLAYER_WIDTH,
h: PLAYER_HEIGHT,
vx: 0,
vy: 0,
onGround: false,
inventory: player1Inventory,
selectedIndex: 0,
controls: PLAYER_CONTROLS[0],
colorBody: PLAYER_CONTROLS[0].colorBody,
colorPants: PLAYER_CONTROLS[0].colorPants
},
{
x: spawnX2 * TILE_SIZE,
y: spawnY2 * TILE_SIZE - PLAYER_HEIGHT,
w: PLAYER_WIDTH,
h: PLAYER_HEIGHT,
vx: 0,
vy: 0,
onGround: false,
inventory: player2Inventory,
selectedIndex: 0,
controls: PLAYER_CONTROLS[1],
colorBody: PLAYER_CONTROLS[1].colorBody,
colorPants: PLAYER_CONTROLS[1].colorPants
}
];
}