Fix: simplified landscape generation
This commit is contained in:
1 parent
99827e420b
commit
df19192118
1 file changed
+10
-26
+10
-26
@@ -64,12 +64,12 @@
|
||||
|
||||
class Landscape {
|
||||
constructor() {
|
||||
this.gridSize = 60;
|
||||
this.gridRange = 40;
|
||||
this.offsetX = -this.gridRange * this.gridSize;
|
||||
this.offsetZ = -this.gridRange * this.gridSize;
|
||||
this.gridSize = 80;
|
||||
this.gridRange = 50;
|
||||
this.offsetX = 0;
|
||||
this.offsetZ = 0;
|
||||
this.points = new Map();
|
||||
this.waterLevel = -15;
|
||||
this.waterLevel = -10;
|
||||
this.updateOffset();
|
||||
}
|
||||
|
||||
@@ -78,14 +78,13 @@
|
||||
}
|
||||
|
||||
generateHeight(x, z) {
|
||||
const nx = x / 80;
|
||||
const nz = z / 80;
|
||||
const nx = x / 100;
|
||||
const nz = z / 100;
|
||||
let y = 0;
|
||||
y += Math.sin(nx) * 25;
|
||||
y += Math.cos(nz) * 25;
|
||||
y += Math.sin(nx) * 30;
|
||||
y += Math.cos(nz) * 30;
|
||||
y += Math.sin(nx * 2 + nz * 0.5) * 15;
|
||||
y += Math.cos(nz * 2 - nx) * 15;
|
||||
y += Math.sin(nx * 3 - nz * 2) * 8;
|
||||
return y;
|
||||
}
|
||||
|
||||
@@ -95,35 +94,20 @@
|
||||
|
||||
updateOffset() {
|
||||
this.offsetX -= 1;
|
||||
this.offsetZ -= 0.5;
|
||||
if (this.offsetX < -this.gridSize) {
|
||||
this.offsetX = 0;
|
||||
}
|
||||
this.offsetZ -= 1;
|
||||
}
|
||||
|
||||
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 worldZ = z * this.gridSize + this.offsetZ;
|
||||
const y = this.generateHeight(worldX, worldZ);
|
||||
const point = new Point3D(worldX, y, worldZ);
|
||||
point.isWater = this.isWater(worldX, worldZ, y);
|
||||
this.points.set(key, point);
|
||||
return point;
|
||||
}
|
||||
|
||||
update() {
|
||||
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() {
|
||||
|
||||
Reference in new issue
Block a user