From 145247d7ec50c926005adbd30b4ef8713496c7bb Mon Sep 17 00:00:00 2001 From: core Date: Wed, 17 May 2023 21:22:04 -0400 Subject: [PATCH] track angle --- client/play.html | 1 + client/src/gateway.ts | 5 +++++ client/src/index.ts | 11 +++++++++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/client/play.html b/client/play.html index a86f026bff40fc28bfb560307419e47233905b21..8e2864883a1b832221ab01f4e66f5f25fcb8e297 100644 --- a/client/play.html +++ b/client/play.html @@ -14,6 +14,7 @@

Position: NaN, NaN

Velocity: NaN

Relative to Moon: NaN, NaN

+

Track Angle: NaN

diff --git a/client/src/gateway.ts b/client/src/gateway.ts index cc3f1a2bc86e97577b65b03169d20c48466b920b..4bdf1ccfd3ccaab32ae08f5d0709f6e5d49a7e52 100644 --- a/client/src/gateway.ts +++ b/client/src/gateway.ts @@ -153,7 +153,12 @@ export async function gateway_connect(gateway_url: string, username: string): Pr let x_vel = (global.me.x - pkt.players[i].x) / (1 / 20); let y_vel = (global.me.y - pkt.players[i].y) / (1 / 20); let total_vel = Math.sqrt(x_vel * x_vel + y_vel * y_vel); + global.x_vel = x_vel; + global.y_vel = y_vel; global.velocity = total_vel; + + // calc theta + global.direction_radians = Math.atan(global.y_vel / global.x_vel); } global.me = pkt.players[i]; diff --git a/client/src/index.ts b/client/src/index.ts index 3acbcb6a6c619bbf5a4e5291c996086a2bbc7fa0..758906751071de847afadd20ef2090cfcc47815d 100644 --- a/client/src/index.ts +++ b/client/src/index.ts @@ -27,7 +27,10 @@ export interface GlobalData { context: CanvasRenderingContext2D, keys: Keys, velocity: number, - can_beam_out: boolean + x_vel: number, + y_vel: number + can_beam_out: boolean, + direction_radians: number } export interface Keys { @@ -54,7 +57,10 @@ export const global: GlobalData = { right: false }, velocity: 0, - can_beam_out: false + x_vel: 0, + y_vel: 0, + can_beam_out: false, + direction_radians: 0 } async function client_main(server: string, username: string, texture_quality: string) { @@ -234,6 +240,7 @@ async function client_main(server: string, username: string, texture_quality: st document.getElementById("pos")!.innerText = `Position: ${Math.trunc(global.me.x)}, ${Math.trunc(global.me.y)}`; } document.getElementById("vel")!.innerText = `Velocity: ${Math.trunc(global.velocity)}`; + document.getElementById("vel-dir")!.innerText = `Track Angle: ${global.direction_radians}` for (let i = 0; i < global.planets.length; i++) { let planet = global.planets[i];