diff options
Diffstat (limited to 'test-client')
| -rw-r--r-- | test-client/movement.ts | 34 | 
1 files changed, 20 insertions, 14 deletions
| diff --git a/test-client/movement.ts b/test-client/movement.ts index 6c2e573d..38f4b47b 100644 --- a/test-client/movement.ts +++ b/test-client/movement.ts @@ -34,24 +34,30 @@ export function player_movement_update(p: PlayerData, dt: number, input: V2) {  }  function collide_player(p: PlayerData, dt: number) { -    for (const [_, tile] of tiles) { -        if (!data.tile_collide[tile.kind]) continue +    for (let xo = -1; xo <= 1; xo++) { +        for (let yo = -1; yo <= 1; yo++) { +            const x = Math.floor(p.x) + xo +            const y = Math.floor(p.y) + yo -        const d = aabb_point_distance(tile.x, tile.y, tile.x + 1, tile.y + 1, p.x, p.y) -        if (d > PLAYER_SIZE) continue +            const tile = tiles.get([x, y].toString()) +            if (tile && !data.tile_collide[tile.kind]) continue -        const h = 0.01 -        const d_sample_x = aabb_point_distance(tile.x, tile.y, tile.x + 1, tile.y + 1, p.x + h, p.y) -        const d_sample_y = aabb_point_distance(tile.x, tile.y, tile.x + 1, tile.y + 1, p.x, p.y + h) -        const grad_x = (d_sample_x - d) / h -        const grad_y = (d_sample_y - d) / h +            const d = aabb_point_distance(x, y, x + 1, y + 1, p.x, p.y) +            if (d > PLAYER_SIZE) continue -        p.x += (PLAYER_SIZE - d) * grad_x -        p.y += (PLAYER_SIZE - d) * grad_y +            const h = 0.01 +            const d_sample_x = aabb_point_distance(x, y, x + 1, y + 1, p.x + h, p.y) +            const d_sample_y = aabb_point_distance(x, y, x + 1, y + 1, p.x, p.y + h) +            const grad_x = (d_sample_x - d) / h +            const grad_y = (d_sample_y - d) / h -        const vdotn = (grad_x * p.vel.x) + (grad_y * p.vel.y) -        p.vel.x -= grad_x * vdotn -        p.vel.y -= grad_y * vdotn +            p.x += (PLAYER_SIZE - d) * grad_x +            p.y += (PLAYER_SIZE - d) * grad_y + +            const vdotn = (grad_x * p.vel.x) + (grad_y * p.vel.y) +            p.vel.x -= grad_x * vdotn +            p.vel.y -= grad_y * vdotn +        }      }      for (const [_, player] of players) { | 
