summaryrefslogtreecommitdiff
path: root/client/src/map.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/map.ts
parentghost (diff)
downloadtuxman-f5fcce110a915fca1b114001962170733276e5df.tar.gz
tuxman-f5fcce110a915fca1b114001962170733276e5df.tar.bz2
tuxman-f5fcce110a915fca1b114001962170733276e5df.zip
audio, finalize gameplay, wrap around map, stuff
Diffstat (limited to '')
-rw-r--r--client/src/map.ts17
1 files changed, 11 insertions, 6 deletions
diff --git a/client/src/map.ts b/client/src/map.ts
index 70de0b8..a7bf004 100644
--- a/client/src/map.ts
+++ b/client/src/map.ts
@@ -91,9 +91,9 @@ const genWalls = (
return walls
}
-const canItem = (tile: Tile): boolean => tile != Tile.WALL && tile != Tile.GHOST_WALL && tile != Tile.GHOST_SPAWN
+const canItem = (initial: boolean, tile: Tile): boolean => tile != Tile.WALL && tile != Tile.GHOST_WALL && tile != Tile.GHOST_SPAWN && tile != Tile.GHOST_EXIT && (initial ? tile == Tile.INITIAL_DOT : true)
-export const genItems = (map: Map): Items => {
+export const genItems = (map: Map, initial: boolean = true): Items => {
let width = map.width
let height = map.height
@@ -104,7 +104,7 @@ export const genItems = (map: Map): Items => {
for (let y = 0; y < height; y++) {
for (let x = 0; x < width; x++) {
let tile = getPoint(width, height, data, x, y)
- if (!canItem(tile)) continue
+ if (!canItem(initial, tile)) continue
let item_key = getItemKey(x, y, width)
@@ -123,13 +123,13 @@ export const genItems = (map: Map): Items => {
type = ItemType.DOT
let tile_south = getPoint(width, height, data, x, y + 1)
- if (canItem(tile_south) && tile_south != Tile.FOOD) {
+ if (canItem(initial, tile_south) && tile_south != Tile.FOOD) {
item_key = getItemKey(x, y + .5, width)
items[item_key] = {type, pos: {x, y: y + .5}}
}
let tile_east = getPoint(width, height, data, x + 1, y)
- if (canItem(tile_east) && tile_east != Tile.FOOD) {
+ if (canItem(initial, tile_east) && tile_east != Tile.FOOD) {
item_key = getItemKey(x + .5, y, width)
items[item_key] = {type, pos: {x: x + .5, y}}
}
@@ -166,7 +166,7 @@ export const getMap = (mapId: number): Map | undefined => {
}
export const checkMap = (map: Map): [boolean, string | Vec2[]] => {
- let spawns = new Array(5).fill(undefined)
+ let spawns = new Array(6).fill(undefined)
let hasFood = false
let hasThicc = false
let hasInitial = false
@@ -215,6 +215,11 @@ export const checkMap = (map: Map): [boolean, string | Vec2[]] => {
return [false, "Map cannot have duplicate spawns"]
spawns[SpawnIndex.GHOST_SPAWN] = {x, y}
break
+ case Tile.GHOST_EXIT:
+ if (spawns[SpawnIndex.GHOST_EXIT])
+ return [false, "Map cannot have duplicate spawns"]
+ spawns[SpawnIndex.GHOST_EXIT] = {x, y}
+ break
}
}