[game] Tweaks
This commit is contained in:
parent
38f5f95827
commit
756a3634c0
3 changed files with 16 additions and 16 deletions
|
|
@ -56,7 +56,7 @@ export class Actor {
|
|||
// this mean we do some "update" in render?
|
||||
//
|
||||
// TODO: Update physics in a better kind of way rather than an object call.
|
||||
update_physics(level: Level | undefined) {
|
||||
update_physics(level: Level) {
|
||||
// This is very nice: https://deepnight.net/tutorial/a-simple-platformer-engine-part-1-basics/
|
||||
// Apply friction to velocity and zero if we're close enough to zero.
|
||||
const props = this.props;
|
||||
|
|
@ -72,6 +72,9 @@ export class Actor {
|
|||
let cy = props.cy;
|
||||
|
||||
// Adjust xr with velocity, check for collisions, etc.
|
||||
|
||||
// TODO: This code is somewhat wrong because it kinda assumes that we're
|
||||
// the same size as our cell size, which is incorrect.
|
||||
let xr = props.xr + velocity.x;
|
||||
do {
|
||||
// TODO: Cap velocity to 1 tile/frame? Then we wouldn't need this loop...
|
||||
|
|
@ -113,8 +116,7 @@ export class Actor {
|
|||
}
|
||||
} while (yr > 1 || yr < 0);
|
||||
|
||||
// TODO: Collision detection
|
||||
// const { w, h } = this.bounds;
|
||||
// TODO: Entity collision detection
|
||||
|
||||
const new_position = new_v2((cx + xr) * 16, (cy + yr) * 16);
|
||||
|
||||
|
|
@ -167,7 +169,7 @@ export class Robo extends Actor {
|
|||
a.x += 1;
|
||||
}
|
||||
vnorm(a);
|
||||
this.props.velocity = vadd(this.props.velocity, vmul(a, 0.06));
|
||||
this.props.velocity = vadd(this.props.velocity, vmul(a, 0.07));
|
||||
}
|
||||
|
||||
draw(clock: number) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue