aboutsummaryrefslogtreecommitdiff
path: root/test-client/main.ts
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-07-18 12:39:33 +0200
committermetamuffin <metamuffin@disroot.org>2024-07-18 12:39:33 +0200
commit2a31d26fca33789ccf8ea28cdb214d20dd29f85d (patch)
tree426faa4d55905ecacdb9a1a4beca6d5a1ab97953 /test-client/main.ts
parentc4ae8c2df44cac2a8b3e4c8db43c2870b7d2bf69 (diff)
downloadhurrycurry-2a31d26fca33789ccf8ea28cdb214d20dd29f85d.tar
hurrycurry-2a31d26fca33789ccf8ea28cdb214d20dd29f85d.tar.bz2
hurrycurry-2a31d26fca33789ccf8ea28cdb214d20dd29f85d.tar.zst
serve-authorative movement
Diffstat (limited to 'test-client/main.ts')
-rw-r--r--test-client/main.ts17
1 files changed, 12 insertions, 5 deletions
diff --git a/test-client/main.ts b/test-client/main.ts
index 30e67f67..d56cf7e6 100644
--- a/test-client/main.ts
+++ b/test-client/main.ts
@@ -17,7 +17,7 @@
*/
/// <reference lib="dom" />
-import { MovementBase, update_movement } from "./movement.ts";
+import { MovementBase, collide_player_player, update_movement } from "./movement.ts";
import { Gamedata, ItemIndex, ItemLocation, Message, PacketC, PacketS, PlayerID, TileIndex } from "./protocol.ts";
import { V2, lerp_exp_v2_mut, normalize, lerp_exp } from "./util.ts";
import { draw_ingame, draw_wait } from "./visual.ts";
@@ -76,6 +76,7 @@ export interface PlayerData extends MovementBase {
id: number,
name: string,
item?: ItemData,
+ direction: V2,
character: number,
anim_position: V2,
message?: MessageData,
@@ -145,6 +146,7 @@ function packet(p: PacketC) {
rot: 0,
facing: { x: 0, y: 1 },
vel: { x: 0, y: 0 },
+ direction: { x: 0, y: 0 },
stamina: 0,
boosting: false,
})
@@ -294,7 +296,7 @@ function set_interact(edge: boolean) {
function tick_update() {
const p = players.get(my_id)
if (!p) return
- send({ type: "position", pos: [p.position.x, p.position.y], rot: p.rot, boosting: p.boosting })
+ send({ type: "movement", pos: [p.position.x, p.position.y], direction: [p.direction.x, p.direction.y], boosting: p.boosting })
}
function frame_update(dt: number) {
@@ -303,12 +305,17 @@ function frame_update(dt: number) {
if (time_remaining != null) time_remaining -= dt
- const input = normalize({
+ const direction = normalize({
x: (+keys_down.has(KEY_RIGHT) - +keys_down.has(KEY_LEFT)),
y: (+keys_down.has(KEY_DOWN) - +keys_down.has(KEY_UP))
})
- if (interacting) input.x *= 0, input.y *= 0
- update_movement(p, dt, input, keys_down.has("KeyK"))
+ if (interacting) direction.x *= 0, direction.y *= 0
+ p.direction = direction
+ update_movement(p, dt, direction, keys_down.has("KeyK"))
+
+ for (const [_, a] of players)
+ for (const [_, b] of players)
+ collide_player_player(a, b, dt)
const update_item = (item: ItemData) => {
if (item.tracking) lerp_exp_v2_mut(item, item.tracking, dt * 10.)