diff options
Diffstat (limited to 'test-client/movement.ts')
-rw-r--r-- | test-client/movement.ts | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/test-client/movement.ts b/test-client/movement.ts index 9102d7c2..1bbb9569 100644 --- a/test-client/movement.ts +++ b/test-client/movement.ts @@ -17,7 +17,7 @@ */ import { data } from "./main.ts"; -import { tiles, players } from "./main.ts"; +import { tiles } from "./main.ts"; import { V2, normalize, length, sub_v2, lerp_exp_v2_mut } from "./util.ts"; export const PLAYER_SIZE = 0.4 @@ -36,24 +36,23 @@ export interface MovementBase { stamina: number } -export function update_movement(p: MovementBase, dt: number, input: V2, boost: boolean) { - if (length(input) > 0.1) lerp_exp_v2_mut(p.facing, input, dt * 10.) +export function update_movement(p: MovementBase, dt: number, direction: V2, boost: boolean) { + if (length(direction) > 0.1) lerp_exp_v2_mut(p.facing, direction, dt * 10.) p.rot = Math.atan2(p.facing.x, p.facing.y) - boost &&= length(input) > 0.1 + boost &&= length(direction) > 0.1 p.boosting = boost && (p.boosting || p.stamina >= 1) && p.stamina > 0 if (p.boosting) p.stamina -= dt / BOOST_DURATION else p.stamina += dt / BOOST_RESTORE p.stamina = Math.max(Math.min(p.stamina, 1), 0) const speed = PLAYER_SPEED * (p.boosting ? BOOST_FACTOR : 1) - p.vel.x += input.x * dt * speed - p.vel.y += input.y * dt * speed + p.vel.x += direction.x * dt * speed + p.vel.y += direction.y * dt * speed p.position.x += p.vel.x * dt p.position.y += p.vel.y * dt collide_player(p, dt) lerp_exp_v2_mut(p.vel, { x: 0, y: 0 }, dt * PLAYER_FRICTION) } - -function collide_player(p: MovementBase, dt: number) { +function collide_player(p: MovementBase, _dt: number) { for (let xo = -1; xo <= 1; xo++) { for (let yo = -1; yo <= 1; yo++) { const x = Math.floor(p.position.x) + xo @@ -79,17 +78,16 @@ function collide_player(p: MovementBase, dt: number) { p.vel.y -= grad_y * vdotn } } - - for (const [_, player] of players) { - const diff = sub_v2(p.position, player.position) - const d = length(diff) - if (d < 0.01) continue - if (d >= PLAYER_SIZE * 2) continue - const norm = normalize(diff); - const f = 100 / (1 + d) - p.vel.x += norm.x * f * dt - p.vel.y += norm.y * f * dt - } +} +export function collide_player_player(a: MovementBase, b: MovementBase, dt: number) { + const diff = sub_v2(a.position, b.position) + const d = length(diff) + if (d < 0.01) return + if (d >= PLAYER_SIZE * 2) return + const norm = normalize(diff); + const f = 100 / (1 + d) + a.vel.x += norm.x * f * dt + a.vel.y += norm.y * f * dt } export function aabb_point_distance( |