summaryrefslogtreecommitdiff
path: root/test-client
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-07-01 16:24:21 +0200
committermetamuffin <metamuffin@disroot.org>2024-07-01 16:24:21 +0200
commitcd41deaf64d5b5f4f6e2488396fbf29778c4f91c (patch)
tree70691e65bbefae8b48f2869c21daac2f6a5f0199 /test-client
parent17024786036868b66a86caaf967a65d77dc2bd15 (diff)
downloadhurrycurry-cd41deaf64d5b5f4f6e2488396fbf29778c4f91c.tar
hurrycurry-cd41deaf64d5b5f4f6e2488396fbf29778c4f91c.tar.bz2
hurrycurry-cd41deaf64d5b5f4f6e2488396fbf29778c4f91c.tar.zst
game ends with timer
Diffstat (limited to 'test-client')
-rw-r--r--test-client/main.ts4
-rw-r--r--test-client/protocol.ts2
-rw-r--r--test-client/visual.ts5
3 files changed, 9 insertions, 2 deletions
diff --git a/test-client/main.ts b/test-client/main.ts
index 38b9e730..aeca8084 100644
--- a/test-client/main.ts
+++ b/test-client/main.ts
@@ -99,6 +99,7 @@ export const items_removed = new Set<ItemData>()
export let data: Gamedata = { item_names: [], tile_names: [], spawn: [0, 0], tile_collide: [], tile_interact: [] }
+export let time_remaining: number | null = null
export let global_message: MessageData | undefined = undefined
let global_message_clear: number | undefined = undefined
export let my_id: PlayerID = -1
@@ -204,6 +205,7 @@ function packet(p: PacketC) {
demands_completed = p.demands_completed
demands_failed = p.demands_failed
points = p.points
+ time_remaining = p.time_remaining ?? null
break;
case "error":
if (global_message_clear) clearTimeout(global_message_clear)
@@ -288,6 +290,8 @@ function frame_update(dt: number) {
const p = players.get(my_id)
if (!p) return
+ if (time_remaining != null) time_remaining -= dt
+
const input = normalize({
x: (+keys_down.has(KEY_RIGHT) - +keys_down.has(KEY_LEFT)),
y: (+keys_down.has(KEY_DOWN) - +keys_down.has(KEY_UP))
diff --git a/test-client/protocol.ts b/test-client/protocol.ts
index 81a0d1a4..1e76700a 100644
--- a/test-client/protocol.ts
+++ b/test-client/protocol.ts
@@ -49,7 +49,7 @@ export type PacketC =
| { type: "update_map", tile: Vec2, kind: TileIndex | null, neighbors: [TileIndex | null] } // A map tile was changed
| { type: "communicate", player: PlayerID, message?: Message, persist: boolean } // A player wants to communicate something, message is null when cleared
| { type: "server_message", text: string } // Text message from the server
- | { type: "score", points: number, demands_failed: number, demands_completed: number, } // Supplies information for score OSD
+ | { type: "score", points: number, demands_failed: number, demands_completed: number, time_remaining?: number } // Supplies information for score OSD
| { type: "set_ingame", state: boolean } // Set to false when entering the game or switching maps
| { type: "error", message: string } // Your client did something wrong.
diff --git a/test-client/visual.ts b/test-client/visual.ts
index e966b5cf..dd676435 100644
--- a/test-client/visual.ts
+++ b/test-client/visual.ts
@@ -15,7 +15,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-import { ItemData, MessageData, PlayerData, TileData, camera, camera_scale, canvas, ctx, data, demands_completed, demands_failed, get_interact_target, global_message, interact_active_anim, interact_possible_anim, interact_target_anim, items_removed, keys_down, my_id, players, points, tiles } from "./main.ts";
+import { ItemData, MessageData, PlayerData, TileData, camera, camera_scale, canvas, ctx, data, demands_completed, demands_failed, get_interact_target, global_message, interact_active_anim, interact_possible_anim, interact_target_anim, items_removed, keys_down, my_id, players, points, tiles, time_remaining } from "./main.ts";
import { PLAYER_SIZE } from "./movement.ts";
import { FALLBACK_TILE, ITEMS, TILES, FALLBACK_ITEM } from "./tiles.ts";
import { V2, ceil_v2, floor_v2 } from "./util.ts";
@@ -79,6 +79,9 @@ export function draw_ingame() {
ctx.fillStyle = "white"
ctx.textAlign = "left"
ctx.textBaseline = "bottom"
+ ctx.font = "20px sans-serif"
+ if (time_remaining != undefined)
+ ctx.fillText(`Time remaining: ${time_remaining?.toFixed(2)}`, 10, canvas.height - 90)
ctx.font = "30px sans-serif"
ctx.fillText(`Points: ${points}`, 10, canvas.height - 60)
ctx.font = "20px sans-serif"