feat: Add terrain rendering with water and grass generation

This commit is contained in:
Kacper Kostka (aider)
2025-04-02 12:12:06 +02:00
parent 1ce5abc901
commit cde5301c2b
2 changed files with 43 additions and 6 deletions

View File

@@ -109,7 +109,8 @@ function generateTerrain(width, height, scale) {
value /= 1.75; // Normalize
// Determine terrain type based on noise value
if (value < -0.2) {
// Increase water threshold to create more water areas
if (value < 0.0) {
terrain[x][y] = TERRAIN_WATER;
} else {
terrain[x][y] = TERRAIN_GRASS;
@@ -122,8 +123,8 @@ function generateTerrain(width, height, scale) {
// Check if a position is in water
function isWater(x, y) {
// Convert world coordinates to terrain grid coordinates
const gridX = Math.floor((x + 2000) / 10) + 100;
const gridY = Math.floor((y + 2000) / 10) + 100;
const gridX = Math.floor((x + 2000) / 10);
const gridY = Math.floor((y + 2000) / 10);
// Check bounds
if (gridX < 0 || gridX >= terrainWidth || gridY < 0 || gridY >= terrainHeight) {
@@ -134,9 +135,9 @@ function isWater(x, y) {
}
// Terrain dimensions
const terrainWidth = 500;
const terrainHeight = 500;
const terrainScale = 100;
const terrainWidth = 400;
const terrainHeight = 400;
const terrainScale = 50; // Smaller scale = more detailed terrain
// Initialize Perlin noise
const perlin = new Perlin();