diff options
Diffstat (limited to 'test-client/main.ts')
| -rw-r--r-- | test-client/main.ts | 47 | 
1 files changed, 3 insertions, 44 deletions
| diff --git a/test-client/main.ts b/test-client/main.ts index 84dfd555..1e6168ed 100644 --- a/test-client/main.ts +++ b/test-client/main.ts @@ -1,11 +1,10 @@  /// <reference lib="dom" /> +import { player_movement_update } from "./movement.ts";  import { Gamedata, ItemIndex, Message, PacketC, PacketS, PlayerID, TileIndex } from "./protocol.ts"; -import { V2, add_v2, length, lerp_exp_v2_mut, normalize, aabb_circle_distance, sub_v2, lerp_exp } from "./util.ts"; +import { V2, add_v2, lerp_exp_v2_mut, normalize, lerp_exp } from "./util.ts";  import { draw_ingame, draw_wait } from "./visual.ts"; -export const PLAYER_SIZE = 0.4; -  export let ctx: CanvasRenderingContext2D;  export let canvas: HTMLCanvasElement;  let ws: WebSocket; @@ -205,14 +204,7 @@ function frame_update(dt: number) {          y: (+keys_down.has("KeyS") - +keys_down.has("KeyW"))      }) -    if (length(input) > 0.1) lerp_exp_v2_mut(p.facing, input, dt * 10.) -    p.rot = Math.atan2(p.facing.x, p.facing.y) -    p.vel.x += input.x * dt * 0.5 -    p.vel.y += input.y * dt * 0.5 -    p.x += p.vel.x -    p.y += p.vel.y -    collide_player(p, dt) -    lerp_exp_v2_mut(p.vel, { x: 0, y: 0 }, dt * 5.) +    player_movement_update(p, dt, input)      const update_item = (item: ItemData) => {          if (item.tracking) lerp_exp_v2_mut(item, item.tracking, dt * 10.) @@ -260,36 +252,3 @@ function draw() {      else throw new Error(`ws state invalid`);      requestAnimationFrame(draw)  } - -function collide_player(p: PlayerData, dt: number) { -    const tiles_ignored = ["floor", "door", "chair"].map(t => data.tile_names.indexOf(t)) -    for (const [_, tile] of tiles) { -        if (tiles_ignored.includes(tile.kind)) continue -        const d = aabb_circle_distance(tile.x, tile.y, tile.x + 1, tile.y + 1, p.x, p.y) -        if (d > PLAYER_SIZE) continue - -        const h = 0.01 -        const d_sample_x = aabb_circle_distance(tile.x, tile.y, tile.x + 1, tile.y + 1, p.x + h, p.y) -        const d_sample_y = aabb_circle_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 - -        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) { -        const diff = sub_v2(p, player) -        const d = length(diff) -        if (d < 0.01) continue -        if (d >= PLAYER_SIZE * 2) continue -        const norm = normalize(diff); -        const f = 1 / (1 + d) -        p.vel.x += norm.x * f * dt -        p.vel.y += norm.y * f * dt -    } -} | 
