feat: Enhance terrain generation with new types and drawing mechanics

This commit is contained in:
Kacper Kostka (aider)
2025-04-02 12:18:52 +02:00
parent 3fa8a695b3
commit a4ef5e0f40
5 changed files with 264 additions and 17 deletions

View File

@@ -87,14 +87,31 @@ function drawTerrain() {
for (let x = startX; x <= endX; x += cellSize) {
for (let y = startY; y <= endY; y += cellSize) {
// Check if this position is water
if (isWater(x, y)) {
ctx.fillStyle = "rgba(0, 100, 255, 0.5)"; // Blue for water
ctx.fillRect(x, y, cellSize, cellSize);
} else {
ctx.fillStyle = "rgba(100, 200, 100, 0.3)"; // Green for grass
ctx.fillRect(x, y, cellSize, cellSize);
// Get terrain type at this position
const terrainType = getTerrainType(x, y);
// Set color based on terrain type
switch(terrainType) {
case TERRAIN_WATER:
ctx.fillStyle = "rgba(0, 100, 255, 0.5)"; // Blue for water
break;
case TERRAIN_GRASS:
ctx.fillStyle = "rgba(100, 200, 100, 0.3)"; // Green for grass
break;
case TERRAIN_SAND:
ctx.fillStyle = "rgba(240, 230, 140, 0.5)"; // Khaki for sand
break;
case TERRAIN_DIRT:
ctx.fillStyle = "rgba(139, 69, 19, 0.3)"; // Brown for dirt
break;
case TERRAIN_STONE:
ctx.fillStyle = "rgba(128, 128, 128, 0.4)"; // Gray for stone
break;
default:
ctx.fillStyle = "rgba(100, 200, 100, 0.3)"; // Default to grass
}
ctx.fillRect(x, y, cellSize, cellSize);
}
}