| 258 | const renderPos = { x: 0, y: 0, z: 0 }; |
| 259 | |
| 260 | function renderBlocks(): void { |
| 261 | const renderDist = 32; |
| 262 | const minX = Math.max(0, Math.floor(camX - renderDist)); |
| 263 | const maxX = Math.min(worldSizeX - 1, Math.floor(camX + renderDist)); |
| 264 | const minZ = Math.max(0, Math.floor(camZ - renderDist)); |
| 265 | const maxZ = Math.min(worldSizeZ - 1, Math.floor(camZ + renderDist)); |
| 266 | |
| 267 | for (let y = 0; y < WORLD_HEIGHT; y++) { |
| 268 | for (let z = minZ; z <= maxZ; z++) { |
| 269 | for (let x = minX; x <= maxX; x++) { |
| 270 | const block = getBlock(x, y, z); |
| 271 | if (block === BLOCK_AIR) continue; |
| 272 | if ( |
| 273 | getBlock(x-1, y, z) !== BLOCK_AIR && getBlock(x+1, y, z) !== BLOCK_AIR && |
| 274 | getBlock(x, y-1, z) !== BLOCK_AIR && getBlock(x, y+1, z) !== BLOCK_AIR && |
| 275 | getBlock(x, y, z-1) !== BLOCK_AIR && getBlock(x, y, z+1) !== BLOCK_AIR |
| 276 | ) continue; |
| 277 | renderPos.x = x + 0.5; renderPos.y = y + 0.5; renderPos.z = z + 0.5; |
| 278 | drawCube(renderPos, 1, 1, 1, BLOCK_COLORS[block]); |
| 279 | } |
| 280 | } |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | function drawHUD(): void { |
| 285 | const cx = SCREEN_WIDTH / 2; |