feat: Add terrain rendering with water and grass generation
This commit is contained in:
13
terrain.js
13
terrain.js
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user