summaryrefslogtreecommitdiff
path: root/client/src/logic/logic.ts
diff options
context:
space:
mode:
authorTyler Murphy <tylerm@tylerm.dev>2023-06-29 11:40:46 -0400
committerTyler Murphy <tylerm@tylerm.dev>2023-06-29 11:40:46 -0400
commitf5fcce110a915fca1b114001962170733276e5df (patch)
tree6ce82c649d7377b42e75c9feb88d73e4aa15d713 /client/src/logic/logic.ts
parentghost (diff)
downloadtuxman-f5fcce110a915fca1b114001962170733276e5df.tar.gz
tuxman-f5fcce110a915fca1b114001962170733276e5df.tar.bz2
tuxman-f5fcce110a915fca1b114001962170733276e5df.zip
audio, finalize gameplay, wrap around map, stuff
Diffstat (limited to 'client/src/logic/logic.ts')
-rw-r--r--client/src/logic/logic.ts83
1 files changed, 67 insertions, 16 deletions
diff --git a/client/src/logic/logic.ts b/client/src/logic/logic.ts
index d9ac6c8..1c3ec1a 100644
--- a/client/src/logic/logic.ts
+++ b/client/src/logic/logic.ts
@@ -3,7 +3,7 @@ import { updatePlayers } from "./players.js"
import { updateUI } from "./ui.js"
import { updateMovement } from "./movement.js"
import { updateItems } from "./items.js"
-import { GameState, Input } from "../types.js";
+import { GameState, Input, Rotation, SpawnIndex } from "../types.js";
import { updateGhosts } from "./ai.js";
export const InitialState: GameState = {
@@ -14,7 +14,9 @@ export const InitialState: GameState = {
items: {},
mapId: undefined,
frame: 0,
- rng: 0
+ rng: 0,
+ roundTimer: 0,
+ endRoundTimer: undefined
}
export const random = (state: GameState): number => {
@@ -32,36 +34,85 @@ export const onLogic = (
random(data)
let startPressed = updatePlayers(data, input);
+ let playersLeft = 0
+ for (let id in data.players) {
+ let player = data.players[id]
+ if (player.dead) {
+ player.framesDead++
+ } else {
+ playersLeft++
+ }
+ }
if (data.started) {
- updateMovement(data)
- updateItems(data)
- updateGhosts(data)
+ data.roundTimer++
+ if (data.roundTimer < 60 * 5) {
+ // uh do nothing just draw shit
+ } else if (playersLeft > 1) {
+ updateMovement(data)
+ updateItems(data)
+ updateGhosts(data)
+ } else {
+ if (data.endRoundTimer === undefined) {
+ data.endRoundTimer = 60 * 5
+ }
+ data.endRoundTimer--
+ if (data.endRoundTimer < 1) {
+ nextMap(data)
+ }
+ }
} else {
updateUI(data)
}
- if (startPressed && !data.started) {
- initMap(data, 0)
- data.started = true;
+ if (startPressed && !data.started && Object.values(data.players).length > 1) {
+ nextMap(data)
+ data.started = true;
+ }
+
+ let map = getMap(data.mapId)
+ if (map && Object.keys(data.items).length < 1) {
+ data.items = genItems(map, false)
}
return data
}
-const initMap = (gameData: GameState, mapId: number) => {
+const nextMap = (gameData: GameState) => {
- document.getElementById("lobby").style.display = "none"
+ if (gameData.mapId === undefined) {
+ gameData.mapId = 0
+ } else {
+ gameData.mapId++
+ }
- gameData.mapId = mapId
+ if (gameData.mapId > 3) {
+ gameData.mapId = undefined
+ gameData.started = false
+ return
+ }
+
+ gameData.ghosts = [undefined, undefined, undefined, undefined]
- let map = getMap(mapId)
- // if (!map) {
- // let {width, height, data} = decompressMap(maps[mapId])
- // map = genMap(width, height, data, mapId)
- // }
+ let map = getMap(gameData.mapId)
+ let index = SpawnIndex.PAC_SPAWN_1
+ for (let id in gameData.players) {
+ let player = gameData.players[id]
+ player.pos = structuredClone(map.spawns[index++])
+ player.dead = false
+ player.framesDead = 0
+ player.thiccLeft = 0
+ player.atePellets = 0
+ player.moving = false
+ player.moveRotation = Rotation.NOTHING
+ player.inputRotation = Rotation.NOTHING
+ player.velocityRotation = Rotation.NOTHING
+ }
+
gameData.items = genItems(map)
+ gameData.roundTimer = 0
+ gameData.endRoundTimer = undefined
}