Fix: simplified landscape generation

This commit is contained in:
Richard Zink committed 2026-10-06 15:43:22 +02:00
1 parent 99827e420b
commit df19192118
1 file changed
+10 -26
+10 -26
View File
@@ -64,12 +64,12 @@
class Landscape { class Landscape {
constructor() { constructor() {
this.gridSize = 60; this.gridSize = 80;
this.gridRange = 40; this.gridRange = 50;
this.offsetX = -this.gridRange * this.gridSize; this.offsetX = 0;
this.offsetZ = -this.gridRange * this.gridSize; this.offsetZ = 0;
this.points = new Map(); this.points = new Map();
this.waterLevel = -15; this.waterLevel = -10;
this.updateOffset(); this.updateOffset();
} }
@@ -78,14 +78,13 @@
} }
generateHeight(x, z) { generateHeight(x, z) {
const nx = x / 80; const nx = x / 100;
const nz = z / 80; const nz = z / 100;
let y = 0; let y = 0;
y += Math.sin(nx) * 25; y += Math.sin(nx) * 30;
y += Math.cos(nz) * 25; y += Math.cos(nz) * 30;
y += Math.sin(nx * 2 + nz * 0.5) * 15; y += Math.sin(nx * 2 + nz * 0.5) * 15;
y += Math.cos(nz * 2 - nx) * 15; y += Math.cos(nz * 2 - nx) * 15;
y += Math.sin(nx * 3 - nz * 2) * 8;
return y; return y;
} }
@@ -95,35 +94,20 @@
updateOffset() { updateOffset() {
this.offsetX -= 1; this.offsetX -= 1;
this.offsetZ -= 0.5; this.offsetZ -= 1;
if (this.offsetX < -this.gridSize) {
this.offsetX = 0;
}
} }
getPoint(x, z) { getPoint(x, z) {
const key = this.getKey(x + this.offsetX, z + this.offsetZ);
if (this.points.has(key)) {
return this.points.get(key);
}
const worldX = x * this.gridSize + this.offsetX; const worldX = x * this.gridSize + this.offsetX;
const worldZ = z * this.gridSize + this.offsetZ; const worldZ = z * this.gridSize + this.offsetZ;
const y = this.generateHeight(worldX, worldZ); const y = this.generateHeight(worldX, worldZ);
const point = new Point3D(worldX, y, worldZ); const point = new Point3D(worldX, y, worldZ);
point.isWater = this.isWater(worldX, worldZ, y); point.isWater = this.isWater(worldX, worldZ, y);
this.points.set(key, point);
return point; return point;
} }
update() { update() {
this.updateOffset(); this.updateOffset();
this.points.forEach((val, key) => {
const [gx, gz] = key.split(',').map(Number);
if (gx > this.gridRange || gz > this.gridRange) {
this.points.delete(key);
}
});
} }
draw() { draw() {