Small fixes

This commit is contained in:
Paul Mathieu 2021-12-25 02:28:06 -08:00
parent 86a65fc39c
commit 0c381e26d3
2 changed files with 12 additions and 8 deletions

17
game.js
View File

@ -71,6 +71,7 @@ function handleKeys(params) {
const ori = se3.roty(params.camera.orientation[1]);
const tf = se3.apply(ori, dir);
const maxSpeed = 0.1;
const airMovement = 0.08;
if (params.flying) {
params.camera.position[0] += tf[0];
@ -80,14 +81,16 @@ function handleKeys(params) {
params.camera.velocity[0] = tf[0];
params.camera.velocity[2] = tf[2];
} else {
params.camera.velocity[0] += tf[0] / 60;
params.camera.velocity[2] += tf[2] / 60;
const vel = params.camera.velocity;
if (Math.abs(params.camera.velocity[0]) > maxSpeed) {
params.camera.velocity[0] = Math.sign(params.camera.velocity[0]) * maxSpeed;
}
if (Math.abs(params.camera.velocity[2]) > maxSpeed) {
params.camera.velocity[2] = Math.sign(params.camera.velocity[2]) * maxSpeed;
vel[0] += tf[0] * airMovement;
vel[2] += tf[2] * airMovement;
const curVel = Math.sqrt(vel[0] * vel[0] + vel[2] * vel[2]);
if (curVel > maxSpeed) {
vel[0] *= maxSpeed / curVel;
vel[2] *= maxSpeed / curVel;
}
}
};

View File

@ -115,9 +115,10 @@ function makeChunk(z, x) {
data.set(Array(waterHeight - currentHeight).fill(BlockType.WATER), offset + currentHeight);
currentHeight = waterHeight;
} else {
data[offset + grassHeight - 1] = BlockType.GRASS;
if (hasATree(seed, z + i, x + j)) {
trees.push([i, j, currentHeight]);
} else {
data[offset + grassHeight - 1] = BlockType.GRASS;
}
}
data.set(Array(256 - currentHeight).fill(BlockType.AIR), offset + currentHeight);