From 698967c98710c1f0e194f69b820efb3a1cba2534 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dalibor=20=C4=8Carapi=C4=87?= Date: Sat, 28 Sep 2024 19:52:29 +0200 Subject: [PATCH] WIP --- src/base/Definitions.ts | 2 +- src/components/Grid.ts | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/base/Definitions.ts b/src/base/Definitions.ts index a90b442..5ff1b14 100644 --- a/src/base/Definitions.ts +++ b/src/base/Definitions.ts @@ -23,7 +23,7 @@ export type WaveDefinition = { creeps: CreepType[]; }; -export type PathDefinition = [row: number, column: number]; +export type PathDefinition = [[row: number, column: number]]; export enum CreepType { Basic = 0, diff --git a/src/components/Grid.ts b/src/components/Grid.ts index db03fc3..f7f39a9 100644 --- a/src/components/Grid.ts +++ b/src/components/Grid.ts @@ -6,17 +6,20 @@ export class Cell extends GameObject { public type: TerrainType; public row: number; public column: number; + public isPath: boolean = false; constructor( type: TerrainType, row: number, column: number, + isPath: boolean, bounds?: PIXI.Rectangle ) { super(bounds); this.type = type; this.row = row; this.column = column; + this.isPath = isPath; this.draw(); } @@ -45,9 +48,15 @@ export class Grid extends GameObject { constructor(map: GameMapDefinition, bounds?: PIXI.Rectangle) { super(bounds); this.gameMap = map; + console.log(this.gameMap.paths); for (let y = 0; y < this.gameMap.rows; y++) { for (let x = 0; x < this.gameMap.columns; x++) { - let cell = new Cell(this.gameMap.cells[x][y], x, y); + let type = this.gameMap.cells[x][y]; + const isPath = this.gameMap.paths.some((path) => + path.some((p) => p[0] === x && p[1] === y) + ); + if (isPath) type = TerrainType.Restricted; + let cell = new Cell(type, x, y, isPath); this.cells.push(cell); } }