aboutsummaryrefslogtreecommitdiff
path: root/test-client/main.ts
diff options
context:
space:
mode:
Diffstat (limited to 'test-client/main.ts')
-rw-r--r--test-client/main.ts17
1 files changed, 14 insertions, 3 deletions
diff --git a/test-client/main.ts b/test-client/main.ts
index 9cafa1f6..a3d5d2f2 100644
--- a/test-client/main.ts
+++ b/test-client/main.ts
@@ -1,7 +1,7 @@
/// <reference lib="dom" />
import { Gamedata, ItemIndex, Message, PacketC, PacketS, PlayerID, TileIndex } from "./protocol.ts";
-import { V2, add_v2, length, lerp_exp_v2_mut, normalize, aabb_circle_distance } from "./util.ts";
+import { V2, add_v2, length, lerp_exp_v2_mut, normalize, aabb_circle_distance, sub_v2 } from "./util.ts";
import { draw_ingame, draw_wait } from "./visual.ts";
export const PLAYER_SIZE = 0.4;
@@ -205,7 +205,7 @@ function frame_update(dt: number) {
p.vel.y += input.y * dt * 0.5
p.x += p.vel.x
p.y += p.vel.y
- collide_player(p)
+ collide_player(p, dt)
lerp_exp_v2_mut(p.vel, { x: 0, y: 0 }, dt * 5.)
const update_item = (item: ItemData) => {
@@ -249,7 +249,7 @@ function draw() {
requestAnimationFrame(draw)
}
-function collide_player(p: PlayerData) {
+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
@@ -269,4 +269,15 @@ function collide_player(p: PlayerData) {
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
+ }
}