[game] I don't know if this is any better honestly.
This commit is contained in:
parent
756a3634c0
commit
20f6c8e878
1 changed files with 47 additions and 41 deletions
|
|
@ -71,13 +71,17 @@ export class Actor {
|
||||||
let cx = props.cx;
|
let cx = props.cx;
|
||||||
let cy = props.cy;
|
let cy = props.cy;
|
||||||
|
|
||||||
// Adjust xr with velocity, check for collisions, etc.
|
let xr = props.xr;
|
||||||
|
let yr = props.yr;
|
||||||
|
|
||||||
// TODO: This code is somewhat wrong because it kinda assumes that we're
|
const steps = Math.ceil(
|
||||||
// the same size as our cell size, which is incorrect.
|
(Math.abs(velocity.x) + Math.abs(velocity.y)) / 0.33
|
||||||
let xr = props.xr + velocity.x;
|
);
|
||||||
do {
|
if (steps > 0) {
|
||||||
// TODO: Cap velocity to 1 tile/frame? Then we wouldn't need this loop...
|
for (let n = 0; n < steps; n++) {
|
||||||
|
xr += velocity.x / steps;
|
||||||
|
if (velocity.x != 0) {
|
||||||
|
// Physics and whatnot.
|
||||||
if (xr >= 0.7 && has_collision(level, cx + 1, cy)) {
|
if (xr >= 0.7 && has_collision(level, cx + 1, cy)) {
|
||||||
xr = 0.7;
|
xr = 0.7;
|
||||||
velocity.x = 0;
|
velocity.x = 0;
|
||||||
|
|
@ -86,18 +90,18 @@ export class Actor {
|
||||||
xr = 0.3;
|
xr = 0.3;
|
||||||
velocity.x = 0;
|
velocity.x = 0;
|
||||||
}
|
}
|
||||||
if (xr > 1) {
|
|
||||||
cx += 1;
|
|
||||||
xr -= 1;
|
|
||||||
}
|
}
|
||||||
if (xr < 0) {
|
while (xr > 1) {
|
||||||
cx -= 1;
|
xr--;
|
||||||
xr += 1;
|
cx++;
|
||||||
|
}
|
||||||
|
while (xr < 0) {
|
||||||
|
xr++;
|
||||||
|
cx--;
|
||||||
}
|
}
|
||||||
} while (xr > 1 || xr < 0);
|
|
||||||
|
|
||||||
let yr = props.yr + velocity.y;
|
yr += velocity.y / steps;
|
||||||
do {
|
if (velocity.y != 0) {
|
||||||
if (yr >= 0.4 && has_collision(level, cx, cy + 1)) {
|
if (yr >= 0.4 && has_collision(level, cx, cy + 1)) {
|
||||||
yr = 0.4;
|
yr = 0.4;
|
||||||
velocity.y = 0;
|
velocity.y = 0;
|
||||||
|
|
@ -106,15 +110,17 @@ export class Actor {
|
||||||
yr = 0.1;
|
yr = 0.1;
|
||||||
velocity.y = 0;
|
velocity.y = 0;
|
||||||
}
|
}
|
||||||
if (yr > 1) {
|
}
|
||||||
|
while (yr > 1) {
|
||||||
cy += 1;
|
cy += 1;
|
||||||
yr -= 1;
|
yr -= 1;
|
||||||
}
|
}
|
||||||
if (yr < 0) {
|
while (yr < 0) {
|
||||||
cy -= 1;
|
cy -= 1;
|
||||||
yr += 1;
|
yr += 1;
|
||||||
}
|
}
|
||||||
} while (yr > 1 || yr < 0);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Entity collision detection
|
// TODO: Entity collision detection
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue