diff --git a/public/assets/missions/mission_01.json b/public/assets/missions/mission_01.json index ac67b3a..ab69c4d 100644 --- a/public/assets/missions/mission_01.json +++ b/public/assets/missions/mission_01.json @@ -2,32 +2,46 @@ "name": "Mission 1", "description": "This is the first mission", "gameMap": { - "rows": 10, - "columns": 10, + "rows": 15, + "columns": 15, "cells": [ - [1, 1, 1, 1, 1, 1, 1, 1, 1, 0], - [1, 1, 1, 1, 1, 1, 1, 1, 1, 0], - [1, 1, 1, 1, 1, 1, 1, 1, 0, 1], - [1, 1, 1, 1, 1, 0, 0, 0, 1, 1], - [1, 1, 1, 1, 1, 0, 0, 1, 1, 1], - [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], - [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], - [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], - [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], - [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] + [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], + [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], + [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], + [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], + [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], + [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], + [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], + [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], + [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], + [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], + [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], + [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], + [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], + [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], + [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], + [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], + [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], + [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], + [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], + [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], + [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] ], "paths": [ [ - [0, 2], - [1, 2], - [2, 2], + [0, 3], + [1, 3], + [2, 3], + [3, 3], [3, 2], [4, 2], [5, 2], [6, 2], [7, 2], - [8, 2], - [9, 2] + [7, 3], + [7, 4], + [8, 4], + [9, 4] ] ] }, diff --git a/src/base/Definitions.ts b/src/base/Definitions.ts index d49be9f..5ae1cb2 100644 --- a/src/base/Definitions.ts +++ b/src/base/Definitions.ts @@ -3,7 +3,7 @@ export type MissionDefinition = { description: string; mapImageUrl: string; gameMap: GameMapDefinition; - missionRounds: MissionRoundDefinition[]; + rounds: MissionRoundDefinition[]; }; export type GameMapDefinition = { diff --git a/src/base/Game.ts b/src/base/Game.ts index 607894d..8801beb 100644 --- a/src/base/Game.ts +++ b/src/base/Game.ts @@ -4,13 +4,17 @@ import GameScene from '../scenes/GameScene'; import GameObject from './GameObject'; import * as PIXI from 'pixi.js'; import SceneBase from '../scenes/SceneBase'; +import Assets from './Assets'; export default class Game extends GameObject { private _currentScene: SceneBase | null = null; constructor(bounds: PIXI.Rectangle) { super(bounds); - this.onMainMenu(); + let params = new URLSearchParams(location.href); + if (params.entries().next().value[1] == 'game') { + this.setScene(new GameScene(Assets.Missions[0], this.bounds)); + } else this.onMainMenu(); } private onMainMenu() { diff --git a/src/components/Creep.ts b/src/components/Creep.ts index cbc427c..c4fb37e 100644 --- a/src/components/Creep.ts +++ b/src/components/Creep.ts @@ -1,10 +1,56 @@ +import { CreepType, PathDefinition } from '../base/Definitions'; import GameObject from '../base/GameObject'; import * as PIXI from 'pixi.js'; -export default class Creep extends GameObject { - constructor(bounds?: PIXI.Rectangle) { - super(bounds); +export function CreepStats(ctype: CreepType): object { + switch (ctype) { + case CreepType.Basic: + return { + health: 2, + speed: 0.45, + special: null, + resistance: { + physical: 0, + divine: 0, + fire: 0, + ice: 0, + frostfire: 0, + }, + }; + case CreepType.Fast: + throw new Error('Fast creep not defined.'); + default: + return { + health: null, + speed: null, + special: null, + resistance: { + physical: null, + divine: null, + fire: null, + ice: null, + frostfire: null, + }, + }; } +} +export default class Creep extends GameObject { + public creepType: CreepType; + private path: PathDefinition; + private pathIndex: number = 0; + private health: number; + private x: number; // X and Y are local to the grid, not canvas + private y: number; + constructor( + creepType: CreepType, + path: PathDefinition, + bounds?: PIXI.Rectangle + ) { + super(bounds); + this.creepType = creepType; + this.path = path; + } + public update() {} protected draw() { this.container.removeChildren(); diff --git a/src/components/WaveManager.ts b/src/components/WaveManager.ts new file mode 100644 index 0000000..e14418f --- /dev/null +++ b/src/components/WaveManager.ts @@ -0,0 +1,36 @@ +import { + CreepType, + MissionRoundDefinition, + PathDefinition, +} from '../base/Definitions'; +import Creep from './Creep'; + +export default class WaveManager { + // Doesn't need to extend GameObject since it does not render + private currentWave: number; + private creeps: Creep[] = []; + private rounds: MissionRoundDefinition[]; + private paths: PathDefinition[]; + private spawnIntervalTicks: number; + private firstCreepSpawnTick: number; + public ticks: number = 0; + constructor(rounds: MissionRoundDefinition[], paths: PathDefinition[]) { + this.rounds = rounds; + this.paths = paths; + } + private updateCreeps() { + this.creeps.forEach((creep) => { + creep.update(); + // TODO: updating here is fine, change to make spawning emit an event + // which GameScene will catch and send to Grid who will draw the creep + // based on the coordinates that the creep calculates. + }); + } + public update(fps): void { + if (this.creeps.length != 0) this.updateCreeps(); + this.ticks++; + if (this.ticks == 200) { + this.creeps.push(new Creep(CreepType.Basic, this.paths[0])); + } + } +} diff --git a/src/components/WaveManger.ts b/src/components/WaveManger.ts deleted file mode 100644 index c2d529d..0000000 --- a/src/components/WaveManger.ts +++ /dev/null @@ -1,13 +0,0 @@ -import Creep from './Creep'; - -export default class WaveManager { - // Doesn't need to extend GameObject since it does not render - private totalWaves: number; - private currentWave: number; - private creeps: Creep[]; - private spawnIntervalTicks: number; - private firstCreepSpawnTick: number; - constructor(totalWaves) { - this.totalWaves = totalWaves; - } -} diff --git a/src/scenes/GameScene.ts b/src/scenes/GameScene.ts index 64d1d38..f9fb443 100644 --- a/src/scenes/GameScene.ts +++ b/src/scenes/GameScene.ts @@ -2,7 +2,7 @@ import Button from '../base/Button'; import { MissionDefinition } from '../base/Definitions'; import { Grid } from '../components/Grid'; import MissionStats from '../components/MissionStats'; -import WaveManager from '../components/WaveManger'; +import WaveManager from '../components/WaveManager'; import SceneBase from './SceneBase'; import * as PIXI from 'pixi.js'; @@ -10,19 +10,21 @@ export default class GameScene extends SceneBase { private ticker: PIXI.Ticker; private stats: MissionStats; private grid: Grid; - private WaveManager: WaveManager; + public waveManager: WaveManager; constructor(mission: MissionDefinition, bounds: PIXI.Rectangle) { super(bounds); - this.ticker = new PIXI.Ticker(); + this.waveManager = new WaveManager( + mission.rounds, + mission.gameMap.paths + ); + this.stats = new MissionStats(100, 200); + this.grid = new Grid(mission.gameMap); this.ticker = new PIXI.Ticker(); this.ticker.maxFPS = 60; this.ticker.minFPS = 30; - this.ticker.add(this.update); + this.ticker.add(() => this.update(this.ticker.FPS)); // bruh this.ticker.start(); - this.stats = new MissionStats(100, 200); - this.grid = new Grid(mission.gameMap); - this.WaveManager = new WaveManager(mission); this.draw(); } @@ -47,7 +49,9 @@ export default class GameScene extends SceneBase { this.ticker.destroy(); } - public update() {} + public update(fps) { + this.waveManager.update(fps); + } protected draw() { console.log('Drawing Game Scene ', this.bounds);