Fix various clamping boundary issues
This commit is contained in:
1 parent
8c4ca98fd4
commit
db371ef07a
2 files changed
+4
-4
No files matched your search
@@ -79,7 +79,7 @@ function update() {
|
|||||||
let ai = AI_TYPES[player.ai];
|
let ai = AI_TYPES[player.ai];
|
||||||
const plan = ai.decide();
|
const plan = ai.decide();
|
||||||
const a = player.a = wrap(0, plan.a, 180);
|
const a = player.a = wrap(0, plan.a, 180);
|
||||||
const p = player.p = wrap(0, plan.p, maxPower);
|
const p = player.p = clamp(0, plan.p, maxPower);
|
||||||
shoot = {a, p};
|
shoot = {a, p};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -366,7 +366,7 @@ function drawTrajectories() {
|
|||||||
|
|
||||||
function drawProjectile() {
|
function drawProjectile() {
|
||||||
if (!projectile) return;
|
if (!projectile) return;
|
||||||
plot(foreground, clamp(0, projectile.x, W), clamp(0, projectile.y, H), 'white');
|
plot(foreground, clamp(0, projectile.x, W-1), clamp(0, projectile.y, H-1), 'white');
|
||||||
}
|
}
|
||||||
|
|
||||||
function fadeTrajectories(amount) {
|
function fadeTrajectories(amount) {
|
||||||
|
|||||||
+2
-2
@@ -29,8 +29,8 @@ const TERRAIN_TYPES = {
|
|||||||
for (let x=0; x<width; x++) {
|
for (let x=0; x<width; x++) {
|
||||||
if (x % stepSize === 0) dy = ((random(.3, .7) * height) - cy) / stepSize;
|
if (x % stepSize === 0) dy = ((random(.3, .7) * height) - cy) / stepSize;
|
||||||
if (x % (stepSize/16) === 0) dy = dy - random(-1, 1);
|
if (x % (stepSize/16) === 0) dy = dy - random(-1, 1);
|
||||||
const ty = clamp(0, cy + dy, height);
|
const ty = clamp(0, cy+dy, height-1);
|
||||||
const wy = clamp(70, ty, height-70);
|
const wy = clamp(70, ty, height-70-1);
|
||||||
cy = wy + (ty-wy) * 0.5;
|
cy = wy + (ty-wy) * 0.5;
|
||||||
drawRect(ctx, x, cy, 1, height-cy, ctx.color);
|
drawRect(ctx, x, cy, 1, height-cy, ctx.color);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user