This commit is contained in:
Dalibor Čarapić 2024-09-28 19:52:29 +02:00
parent 7e9e178dc3
commit 698967c987
2 changed files with 11 additions and 2 deletions

View File

@ -23,7 +23,7 @@ export type WaveDefinition = {
creeps: CreepType[]; creeps: CreepType[];
}; };
export type PathDefinition = [row: number, column: number]; export type PathDefinition = [[row: number, column: number]];
export enum CreepType { export enum CreepType {
Basic = 0, Basic = 0,

View File

@ -6,17 +6,20 @@ export class Cell extends GameObject {
public type: TerrainType; public type: TerrainType;
public row: number; public row: number;
public column: number; public column: number;
public isPath: boolean = false;
constructor( constructor(
type: TerrainType, type: TerrainType,
row: number, row: number,
column: number, column: number,
isPath: boolean,
bounds?: PIXI.Rectangle bounds?: PIXI.Rectangle
) { ) {
super(bounds); super(bounds);
this.type = type; this.type = type;
this.row = row; this.row = row;
this.column = column; this.column = column;
this.isPath = isPath;
this.draw(); this.draw();
} }
@ -45,9 +48,15 @@ export class Grid extends GameObject {
constructor(map: GameMapDefinition, bounds?: PIXI.Rectangle) { constructor(map: GameMapDefinition, bounds?: PIXI.Rectangle) {
super(bounds); super(bounds);
this.gameMap = map; this.gameMap = map;
console.log(this.gameMap.paths);
for (let y = 0; y < this.gameMap.rows; y++) { for (let y = 0; y < this.gameMap.rows; y++) {
for (let x = 0; x < this.gameMap.columns; x++) { 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); this.cells.push(cell);
} }
} }