diff options
author | metamuffin <metamuffin@disroot.org> | 2024-06-23 14:21:25 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-06-23 19:32:37 +0200 |
commit | 70a6107085d921a3020d2037a09abdaa40970722 (patch) | |
tree | 052a1e784f87ce2cab77230b674e3871da5a5f79 /test-client/main.ts | |
parent | 78696ae1a7a31b597984aa783253c1b00a043291 (diff) | |
download | hurrycurry-70a6107085d921a3020d2037a09abdaa40970722.tar hurrycurry-70a6107085d921a3020d2037a09abdaa40970722.tar.bz2 hurrycurry-70a6107085d921a3020d2037a09abdaa40970722.tar.zst |
cant move too quickly
Diffstat (limited to 'test-client/main.ts')
-rw-r--r-- | test-client/main.ts | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/test-client/main.ts b/test-client/main.ts index 7146a3d1..d3d1eb54 100644 --- a/test-client/main.ts +++ b/test-client/main.ts @@ -2,7 +2,7 @@ import { player_movement_update } from "./movement.ts"; import { Gamedata, ItemIndex, Message, PacketC, PacketS, PlayerID, TileIndex } from "./protocol.ts"; -import { V2, add_v2, lerp_exp_v2_mut, normalize, lerp_exp } from "./util.ts"; +import { V2, add_v2, lerp_exp_v2_mut, normalize, lerp_exp, sub_v2, length } from "./util.ts"; import { draw_ingame, draw_wait } from "./visual.ts"; export let ctx: CanvasRenderingContext2D; @@ -76,7 +76,7 @@ export const items_removed = new Set<ItemData>() export let data: Gamedata = { item_names: [], tile_names: [], spawn: [0, 0], tile_collide: [], tile_interact: [] } -let my_id: PlayerID = -1 +export let my_id: PlayerID = -1 export const camera: V2 = { x: 0, y: 0 } export const interact_target_anim: V2 = { x: 0, y: 0 } export let interact_possible_anim: number = 0 @@ -109,10 +109,12 @@ function packet(p: PacketC) { players.delete(p.id) break; case "position": { - if (p.player == my_id) return; // we know better where we are const pl = players.get(p.player)! - pl.x = p.pos[0] - pl.y = p.pos[1] + const pos = { x: p.pos[0], y: p.pos[1] } + const dist = length(sub_v2(pl, pos)); + if (p.player == my_id && dist < 1) return; // we know better where we are + pl.x = pos.x + pl.y = pos.y pl.rot = p.rot break; } |