feat: Enhance terrain generation with new types and drawing mechanics
This commit is contained in:
31
render.js
31
render.js
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user