basic animation management + global var rename
This commit is contained in:
parent
f4ec26776d
commit
94caafa020
@ -1,6 +1,6 @@
|
|||||||
import * as PIXI from 'pixi.js';
|
import * as PIXI from 'pixi.js';
|
||||||
import { CreepStatsDefinition, MissionDefinition, TowerDefinition } from './Definitions';
|
import { CreepStatsDefinition, MissionDefinition, TowerDefinition } from './Definitions';
|
||||||
import { Globals } from './Bastion';
|
import { Engine } from './Bastion';
|
||||||
|
|
||||||
export default class GameAssets {
|
export default class GameAssets {
|
||||||
public static async LoadAssets() {
|
public static async LoadAssets() {
|
||||||
@ -12,10 +12,10 @@ export default class GameAssets {
|
|||||||
fontSize: 50,
|
fontSize: 50,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
text.x = Globals.app.canvas.width / 2;
|
text.x = Engine.app.canvas.width / 2;
|
||||||
text.y = Globals.app.canvas.height / 2;
|
text.y = Engine.app.canvas.height / 2;
|
||||||
text.anchor.set(0.5, 0.5);
|
text.anchor.set(0.5, 0.5);
|
||||||
Globals.app.stage.addChild(text);
|
Engine.app.stage.addChild(text);
|
||||||
GameAssets.Button01Texture = await PIXI.Assets.load({
|
GameAssets.Button01Texture = await PIXI.Assets.load({
|
||||||
src: '/assets/gui/button_01.png',
|
src: '/assets/gui/button_01.png',
|
||||||
});
|
});
|
||||||
|
@ -6,8 +6,9 @@ import { Grid } from './game/Grid';
|
|||||||
import WaveManager from './game/WaveManager';
|
import WaveManager from './game/WaveManager';
|
||||||
import TowerManager from './game/TowerManager';
|
import TowerManager from './game/TowerManager';
|
||||||
import { GameScene } from '../scenes/Game';
|
import { GameScene } from '../scenes/Game';
|
||||||
|
import AnimationManager from './game/AnimationManager';
|
||||||
|
|
||||||
export class Globals {
|
export class Engine {
|
||||||
public static app: PIXI.Application;
|
public static app: PIXI.Application;
|
||||||
public static GameMaster: GameMaster;
|
public static GameMaster: GameMaster;
|
||||||
public static WindowHeight: number;
|
public static WindowHeight: number;
|
||||||
@ -16,6 +17,7 @@ export class Globals {
|
|||||||
public static Grid: Grid;
|
public static Grid: Grid;
|
||||||
public static WaveManager: WaveManager;
|
public static WaveManager: WaveManager;
|
||||||
public static TowerManager: TowerManager;
|
public static TowerManager: TowerManager;
|
||||||
|
public static AnimationManager: AnimationManager;
|
||||||
public static GameScene: GameScene;
|
public static GameScene: GameScene;
|
||||||
public static latestCommit: string;
|
public static latestCommit: string;
|
||||||
}
|
}
|
||||||
@ -26,17 +28,17 @@ export default class GameMaster {
|
|||||||
private GameObjects: GameObject[] = [];
|
private GameObjects: GameObject[] = [];
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
Globals.GameMaster = this;
|
Engine.GameMaster = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public _CreateGuiObject(object: GuiObject) {
|
public _CreateGuiObject(object: GuiObject) {
|
||||||
this.currentScene.gui.push(object);
|
this.currentScene.gui.push(object);
|
||||||
Globals.app.stage.addChild(object.container);
|
Engine.app.stage.addChild(object.container);
|
||||||
}
|
}
|
||||||
|
|
||||||
public _RemoveGuiObject(object: GuiObject) {
|
public _RemoveGuiObject(object: GuiObject) {
|
||||||
this.currentScene.gui.splice(this.currentScene.gui.indexOf(object), 1);
|
this.currentScene.gui.splice(this.currentScene.gui.indexOf(object), 1);
|
||||||
Globals.app.stage.removeChild(object.container);
|
Engine.app.stage.removeChild(object.container);
|
||||||
}
|
}
|
||||||
|
|
||||||
public changeScene(newScene: Scene) {
|
public changeScene(newScene: Scene) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import * as PIXI from 'pixi.js';
|
import * as PIXI from 'pixi.js';
|
||||||
import { Globals } from './Bastion';
|
import { Engine } from './Bastion';
|
||||||
|
|
||||||
export default abstract class GuiObject {
|
export default abstract class GuiObject {
|
||||||
public readonly name: string = this.constructor.name;
|
public readonly name: string = this.constructor.name;
|
||||||
@ -37,7 +37,7 @@ export default abstract class GuiObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
constructor(interactive?: boolean) {
|
constructor(interactive?: boolean) {
|
||||||
Globals.GameMaster._CreateGuiObject(this);
|
Engine.GameMaster._CreateGuiObject(this);
|
||||||
if (!interactive) return;
|
if (!interactive) return;
|
||||||
this._container.interactive = true;
|
this._container.interactive = true;
|
||||||
this._container.onwheel = (e) => {
|
this._container.onwheel = (e) => {
|
||||||
|
59
src/classes/game/AnimationManager.ts
Normal file
59
src/classes/game/AnimationManager.ts
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
import * as PIXI from 'pixi.js';
|
||||||
|
|
||||||
|
class Animateable {
|
||||||
|
public finished: boolean = false;
|
||||||
|
protected callbackFn: Function;
|
||||||
|
|
||||||
|
public Finish() {
|
||||||
|
this.finished = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public update(ms) {
|
||||||
|
if (this.finished) return this.callbackFn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class FadeInOut extends Animateable {
|
||||||
|
public fadeType: 'in' | 'out';
|
||||||
|
public fadeTime: number;
|
||||||
|
public pixiObject: PIXI.Container;
|
||||||
|
private ticks: number = 0;
|
||||||
|
|
||||||
|
constructor(type: 'in' | 'out', timeInFrames: number, object: PIXI.Container, callbackFn: Function) {
|
||||||
|
super();
|
||||||
|
this.fadeType = type;
|
||||||
|
this.fadeTime = timeInFrames;
|
||||||
|
this.pixiObject = object;
|
||||||
|
this.callbackFn = callbackFn;
|
||||||
|
if (type == 'in') {
|
||||||
|
this.pixiObject.alpha = 0;
|
||||||
|
} else {
|
||||||
|
this.pixiObject.alpha = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public update(ms) {
|
||||||
|
super.update(ms);
|
||||||
|
this.ticks++;
|
||||||
|
if (this.fadeType == 'in') {
|
||||||
|
this.pixiObject.alpha = this.ticks / this.fadeTime;
|
||||||
|
} else {
|
||||||
|
this.pixiObject.alpha -= 1 / this.fadeTime;
|
||||||
|
}
|
||||||
|
console.log(this.pixiObject.alpha);
|
||||||
|
if (this.ticks >= this.fadeTime) this.Finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class AnimationManager {
|
||||||
|
public AnimationQueue: Animateable[] = [];
|
||||||
|
public Animate(animatable: Animateable) {
|
||||||
|
this.AnimationQueue.push(animatable);
|
||||||
|
}
|
||||||
|
public update(ms) {
|
||||||
|
this.AnimationQueue.forEach((anim) => {
|
||||||
|
if (anim.finished) this.AnimationQueue.splice(this.AnimationQueue.indexOf(anim), 1);
|
||||||
|
anim.update(ms);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
import GameAssets from '../Assets';
|
import GameAssets from '../Assets';
|
||||||
import Assets from '../Assets';
|
import Assets from '../Assets';
|
||||||
import { Globals } from '../Bastion';
|
import { Engine } from '../Bastion';
|
||||||
import { CreepStatsDefinition, CreepType, PathDefinition } from '../Definitions';
|
import { CreepStatsDefinition, CreepType, PathDefinition } from '../Definitions';
|
||||||
import GameObject from '../GameObject';
|
import GameObject from '../GameObject';
|
||||||
import * as PIXI from 'pixi.js';
|
import * as PIXI from 'pixi.js';
|
||||||
@ -48,17 +48,17 @@ export default class Creep extends GameObject {
|
|||||||
this.path = path;
|
this.path = path;
|
||||||
this.x = path[0][1] * 64 + 32; // centered
|
this.x = path[0][1] * 64 + 32; // centered
|
||||||
this.y = path[0][0] * 64 + 32;
|
this.y = path[0][0] * 64 + 32;
|
||||||
Globals.GameScene.events.on(CreepEvents.TakenDamage, (creepID, damage) => {
|
Engine.GameScene.events.on(CreepEvents.TakenDamage, (creepID, damage) => {
|
||||||
if (creepID != this.id) return;
|
if (creepID != this.id) return;
|
||||||
this.health -= damage;
|
this.health -= damage;
|
||||||
});
|
});
|
||||||
Globals.Grid.container.addChild(this.container);
|
Engine.Grid.container.addChild(this.container);
|
||||||
this.container.addChild(this.sprite);
|
this.container.addChild(this.sprite);
|
||||||
}
|
}
|
||||||
public update(elapsedMS: number) {
|
public update(elapsedMS: number) {
|
||||||
if (this.dead) return;
|
if (this.dead) return;
|
||||||
if (this.health <= 0) {
|
if (this.health <= 0) {
|
||||||
Globals.GameScene.events.emit(CreepEvents.Died, this.maxHealth, this);
|
Engine.GameScene.events.emit(CreepEvents.Died, this.maxHealth, this);
|
||||||
this.destroy();
|
this.destroy();
|
||||||
this.dead = true;
|
this.dead = true;
|
||||||
return;
|
return;
|
||||||
|
@ -2,7 +2,7 @@ import * as PIXI from 'pixi.js';
|
|||||||
import GameObject from '../GameObject';
|
import GameObject from '../GameObject';
|
||||||
import { GameMapDefinition, TerrainType } from '../Definitions';
|
import { GameMapDefinition, TerrainType } from '../Definitions';
|
||||||
import GameAssets from '../Assets';
|
import GameAssets from '../Assets';
|
||||||
import { Globals } from '../Bastion';
|
import { Engine } from '../Bastion';
|
||||||
import Creep, { CreepEvents } from './Creep';
|
import Creep, { CreepEvents } from './Creep';
|
||||||
|
|
||||||
export class Cell extends GameObject {
|
export class Cell extends GameObject {
|
||||||
@ -23,7 +23,7 @@ export class Cell extends GameObject {
|
|||||||
this.bb.y = this.row * 64;
|
this.bb.y = this.row * 64;
|
||||||
this.bb.width = 64;
|
this.bb.width = 64;
|
||||||
this.bb.height = 64;
|
this.bb.height = 64;
|
||||||
Globals.Grid.container.addChild(this.container);
|
Engine.Grid.container.addChild(this.container);
|
||||||
this.container.x = this.bb.x;
|
this.container.x = this.bb.x;
|
||||||
this.container.y = this.bb.y;
|
this.container.y = this.bb.y;
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ export class Cell extends GameObject {
|
|||||||
this.clickDetector.fill({ color: 0xff0000, alpha: 0 });
|
this.clickDetector.fill({ color: 0xff0000, alpha: 0 });
|
||||||
this.container.addChild(this.clickDetector);
|
this.container.addChild(this.clickDetector);
|
||||||
this.clickDetector.onpointerdown = (e) => {
|
this.clickDetector.onpointerdown = (e) => {
|
||||||
Globals.Grid._gridCellClicked(row, column);
|
Engine.Grid._gridCellClicked(row, column);
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!GameAssets.DebuggingEnabled) return;
|
if (!GameAssets.DebuggingEnabled) return;
|
||||||
@ -89,12 +89,12 @@ export class Grid extends GameObject {
|
|||||||
constructor(map: GameMapDefinition, missionIndex) {
|
constructor(map: GameMapDefinition, missionIndex) {
|
||||||
super();
|
super();
|
||||||
this.gameMap = map;
|
this.gameMap = map;
|
||||||
Globals.Grid = this;
|
Engine.Grid = this;
|
||||||
this.bb.x = 0;
|
this.bb.x = 0;
|
||||||
this.bb.y = 0;
|
this.bb.y = 0;
|
||||||
this.bb.width = 64 * 30;
|
this.bb.width = 64 * 30;
|
||||||
this.bb.height = 64 * 17;
|
this.bb.height = 64 * 17;
|
||||||
Globals.app.stage.addChild(this.container);
|
Engine.app.stage.addChild(this.container);
|
||||||
|
|
||||||
let background = new PIXI.Sprite(GameAssets.MissionBackgrounds[missionIndex]);
|
let background = new PIXI.Sprite(GameAssets.MissionBackgrounds[missionIndex]);
|
||||||
background.x = 0;
|
background.x = 0;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import Assets from '../Assets';
|
import Assets from '../Assets';
|
||||||
import { Globals } from '../Bastion';
|
import { Engine } from '../Bastion';
|
||||||
import GameObject from '../GameObject';
|
import GameObject from '../GameObject';
|
||||||
import * as PIXI from 'pixi.js';
|
import * as PIXI from 'pixi.js';
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ export default class MissionStats extends GameObject {
|
|||||||
this.gold = initialGold;
|
this.gold = initialGold;
|
||||||
this.container.x = 0;
|
this.container.x = 0;
|
||||||
this.container.y = 20;
|
this.container.y = 20;
|
||||||
Globals.app.stage.addChild(this.container);
|
Engine.app.stage.addChild(this.container);
|
||||||
this.healthText = new PIXI.Text({
|
this.healthText = new PIXI.Text({
|
||||||
text: `${this.hp}`,
|
text: `${this.hp}`,
|
||||||
style: new PIXI.TextStyle({
|
style: new PIXI.TextStyle({
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import * as PIXI from 'pixi.js';
|
import * as PIXI from 'pixi.js';
|
||||||
import GameObject from '../GameObject';
|
import GameObject from '../GameObject';
|
||||||
import { Globals } from '../Bastion';
|
import { Engine } from '../Bastion';
|
||||||
import Creep, { CreepEvents } from './Creep';
|
import Creep, { CreepEvents } from './Creep';
|
||||||
|
|
||||||
export function calculateAngleToPoint(x, y, targetX, targetY) {
|
export function calculateAngleToPoint(x, y, targetX, targetY) {
|
||||||
@ -30,7 +30,7 @@ export default class Projectile extends GameObject {
|
|||||||
this.container.x = this.x;
|
this.container.x = this.x;
|
||||||
this.container.y = this.y;
|
this.container.y = this.y;
|
||||||
this.container.addChild(this.sprite);
|
this.container.addChild(this.sprite);
|
||||||
Globals.app.stage.addChild(this.container);
|
Engine.app.stage.addChild(this.container);
|
||||||
|
|
||||||
this.angle = angle;
|
this.angle = angle;
|
||||||
this.speed = 0.9;
|
this.speed = 0.9;
|
||||||
@ -43,7 +43,7 @@ export default class Projectile extends GameObject {
|
|||||||
public update(elapsedMS) {
|
public update(elapsedMS) {
|
||||||
if (this.deleteMe) return;
|
if (this.deleteMe) return;
|
||||||
if (this.x > 2000 || this.x < 0 || this.y > 2000 || this.y < 0 || this.timeToLive <= 0) return this.destroy();
|
if (this.x > 2000 || this.x < 0 || this.y > 2000 || this.y < 0 || this.timeToLive <= 0) return this.destroy();
|
||||||
Globals.Grid.creeps.forEach((creep) => {
|
Engine.Grid.creeps.forEach((creep) => {
|
||||||
if (this.timeToLive <= 0) return;
|
if (this.timeToLive <= 0) return;
|
||||||
if (creep.container && this.checkCollision(creep)) {
|
if (creep.container && this.checkCollision(creep)) {
|
||||||
this.timeToLive--;
|
this.timeToLive--;
|
||||||
@ -60,7 +60,7 @@ export default class Projectile extends GameObject {
|
|||||||
|
|
||||||
public onCollide(creep) {
|
public onCollide(creep) {
|
||||||
console.log('COLLIDED WITH' + creep);
|
console.log('COLLIDED WITH' + creep);
|
||||||
Globals.GameScene.events.emit(CreepEvents.TakenDamage, creep.id, this.damage);
|
Engine.GameScene.events.emit(CreepEvents.TakenDamage, creep.id, this.damage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public checkCollision(creep: Creep) {
|
public checkCollision(creep: Creep) {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Globals } from '../Bastion';
|
import { Engine } from '../Bastion';
|
||||||
import * as PIXI from 'pixi.js';
|
import * as PIXI from 'pixi.js';
|
||||||
import GameObject from '../GameObject';
|
import GameObject from '../GameObject';
|
||||||
import { TowerDefinition } from '../Definitions';
|
import { TowerDefinition } from '../Definitions';
|
||||||
@ -47,7 +47,7 @@ export class Tower extends GameObject {
|
|||||||
this.behaviour = behaviour;
|
this.behaviour = behaviour;
|
||||||
this.definition = definition;
|
this.definition = definition;
|
||||||
this.ticksUntilNextShot = 0;
|
this.ticksUntilNextShot = 0;
|
||||||
let parent: Cell = Globals.Grid.getCellByRowAndCol(row, column);
|
let parent: Cell = Engine.Grid.getCellByRowAndCol(row, column);
|
||||||
this.sprite = new PIXI.Sprite({
|
this.sprite = new PIXI.Sprite({
|
||||||
texture: texture,
|
texture: texture,
|
||||||
height: 64,
|
height: 64,
|
||||||
@ -63,10 +63,10 @@ export class Tower extends GameObject {
|
|||||||
parent.clickDetector.onmouseleave = (e) => {
|
parent.clickDetector.onmouseleave = (e) => {
|
||||||
this.graphics.clear();
|
this.graphics.clear();
|
||||||
};
|
};
|
||||||
Globals.app.stage.addChild(this.graphics);
|
Engine.app.stage.addChild(this.graphics);
|
||||||
}
|
}
|
||||||
public GetCreepsInRange() {
|
public GetCreepsInRange() {
|
||||||
let creeps = Globals.Grid.creeps;
|
let creeps = Engine.Grid.creeps;
|
||||||
return creeps.filter((creep) => {
|
return creeps.filter((creep) => {
|
||||||
const x = creep.x;
|
const x = creep.x;
|
||||||
const y = creep.y;
|
const y = creep.y;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import * as PIXI from 'pixi.js';
|
import * as PIXI from 'pixi.js';
|
||||||
import { Globals } from '../Bastion';
|
import { Engine } from '../Bastion';
|
||||||
import { TerrainType, TowerDefinition } from '../Definitions';
|
import { TerrainType, TowerDefinition } from '../Definitions';
|
||||||
import GameAssets from '../Assets';
|
import GameAssets from '../Assets';
|
||||||
import GameObject from '../GameObject';
|
import GameObject from '../GameObject';
|
||||||
@ -15,11 +15,11 @@ export default class TowerManager {
|
|||||||
private selectedTower: TowerDefinition | null = null;
|
private selectedTower: TowerDefinition | null = null;
|
||||||
private towers: Tower[] = [];
|
private towers: Tower[] = [];
|
||||||
constructor() {
|
constructor() {
|
||||||
Globals.TowerManager = this;
|
Engine.TowerManager = this;
|
||||||
}
|
}
|
||||||
public ToggleChoosingTowerLocation(towerName: string) {
|
public ToggleChoosingTowerLocation(towerName: string) {
|
||||||
if (!this.canPlaceTowers) return;
|
if (!this.canPlaceTowers) return;
|
||||||
Globals.Grid.toggleGrid();
|
Engine.Grid.toggleGrid();
|
||||||
if (!this.isPlacingTower) {
|
if (!this.isPlacingTower) {
|
||||||
GameAssets.Towers.forEach((item) => {
|
GameAssets.Towers.forEach((item) => {
|
||||||
if (item.name == towerName) {
|
if (item.name == towerName) {
|
||||||
@ -54,21 +54,21 @@ export default class TowerManager {
|
|||||||
if (item.sprite == definition.sprite) idx = index;
|
if (item.sprite == definition.sprite) idx = index;
|
||||||
});
|
});
|
||||||
const sprite = GameAssets.TowerSprites[idx];
|
const sprite = GameAssets.TowerSprites[idx];
|
||||||
if (!Globals.GameScene.MissionStats.hasEnoughGold(definition.stats.cost) && !ignoreCost)
|
if (!Engine.GameScene.MissionStats.hasEnoughGold(definition.stats.cost) && !ignoreCost)
|
||||||
return console.warn('Does not have enough gold.');
|
return console.warn('Does not have enough gold.');
|
||||||
if (
|
if (
|
||||||
!this.GetTowerByRowAndCol(row, column) &&
|
!this.GetTowerByRowAndCol(row, column) &&
|
||||||
Globals.Grid.getCellByRowAndCol(row, column).type != TerrainType.Path &&
|
Engine.Grid.getCellByRowAndCol(row, column).type != TerrainType.Path &&
|
||||||
Globals.Grid.getCellByRowAndCol(row, column).type != TerrainType.Restricted
|
Engine.Grid.getCellByRowAndCol(row, column).type != TerrainType.Restricted
|
||||||
) {
|
) {
|
||||||
Globals.GameScene.MissionStats.spendGold(definition.stats.cost);
|
Engine.GameScene.MissionStats.spendGold(definition.stats.cost);
|
||||||
let tower = new Tower(row, column, sprite, definition, behaviour);
|
let tower = new Tower(row, column, sprite, definition, behaviour);
|
||||||
this.towers.push(tower);
|
this.towers.push(tower);
|
||||||
this.ToggleChoosingTowerLocation('RESET');
|
this.ToggleChoosingTowerLocation('RESET');
|
||||||
console.log('SHOULDVE PLACED TOWER');
|
console.log('SHOULDVE PLACED TOWER');
|
||||||
console.log(this.selectedTower);
|
console.log(this.selectedTower);
|
||||||
this.selectedTower = null;
|
this.selectedTower = null;
|
||||||
Globals.GameScene.events.emit(TowerEvents.TowerPlacedEvent, definition.name);
|
Engine.GameScene.events.emit(TowerEvents.TowerPlacedEvent, definition.name);
|
||||||
} else {
|
} else {
|
||||||
console.warn('Can not place tower on occupied spot or path. Try again.');
|
console.warn('Can not place tower on occupied spot or path. Try again.');
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { CreepType, MissionRoundDefinition, PathDefinition } from '../Definitions';
|
import { CreepType, MissionRoundDefinition, PathDefinition } from '../Definitions';
|
||||||
import * as PIXI from 'pixi.js';
|
import * as PIXI from 'pixi.js';
|
||||||
import Creep, { CreepEvents } from './Creep';
|
import Creep, { CreepEvents } from './Creep';
|
||||||
import { Globals } from '../Bastion';
|
import { Engine } from '../Bastion';
|
||||||
|
|
||||||
export enum WaveManagerEvents {
|
export enum WaveManagerEvents {
|
||||||
CreepSpawned = 'creepSpawned',
|
CreepSpawned = 'creepSpawned',
|
||||||
@ -25,7 +25,7 @@ export default class WaveManager {
|
|||||||
public events = new PIXI.EventEmitter();
|
public events = new PIXI.EventEmitter();
|
||||||
private internalCreepId: number = 0;
|
private internalCreepId: number = 0;
|
||||||
constructor(rounds: MissionRoundDefinition[], paths: PathDefinition[]) {
|
constructor(rounds: MissionRoundDefinition[], paths: PathDefinition[]) {
|
||||||
Globals.WaveManager = this;
|
Engine.WaveManager = this;
|
||||||
this.rounds = rounds;
|
this.rounds = rounds;
|
||||||
this.paths = paths;
|
this.paths = paths;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import * as PIXI from 'pixi.js';
|
import * as PIXI from 'pixi.js';
|
||||||
import GuiObject from '../GuiObject';
|
import GuiObject from '../GuiObject';
|
||||||
import GameAssets from '../Assets';
|
import GameAssets from '../Assets';
|
||||||
import { Globals } from '../Bastion';
|
import { Engine } from '../Bastion';
|
||||||
import { TowerEvents } from '../game/Tower';
|
import { TowerEvents } from '../game/Tower';
|
||||||
|
|
||||||
class TowerButton extends GuiObject {
|
class TowerButton extends GuiObject {
|
||||||
@ -33,7 +33,7 @@ class TowerButton extends GuiObject {
|
|||||||
});
|
});
|
||||||
this.container.addChild(this.frameSprite);
|
this.container.addChild(this.frameSprite);
|
||||||
parent.addChild(this.container);
|
parent.addChild(this.container);
|
||||||
Globals.GameScene.events.on(TowerEvents.TowerPlacedEvent, (name) => {
|
Engine.GameScene.events.on(TowerEvents.TowerPlacedEvent, (name) => {
|
||||||
this.frameSprite.tint = 0xffffff; // reset the tint after a tower has been placed
|
this.frameSprite.tint = 0xffffff; // reset the tint after a tower has been placed
|
||||||
});
|
});
|
||||||
this.container.onmouseenter = (e) => {
|
this.container.onmouseenter = (e) => {
|
||||||
@ -45,7 +45,7 @@ class TowerButton extends GuiObject {
|
|||||||
public onClick(e: PIXI.FederatedPointerEvent): void {
|
public onClick(e: PIXI.FederatedPointerEvent): void {
|
||||||
if (this.frameSprite.tint == 0x00ff00) this.frameSprite.tint = 0xffffff;
|
if (this.frameSprite.tint == 0x00ff00) this.frameSprite.tint = 0xffffff;
|
||||||
else this.frameSprite.tint = 0x00ff00;
|
else this.frameSprite.tint = 0x00ff00;
|
||||||
Globals.TowerManager.ToggleChoosingTowerLocation(this.towerName);
|
Engine.TowerManager.ToggleChoosingTowerLocation(this.towerName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
33
src/main.ts
33
src/main.ts
@ -1,13 +1,14 @@
|
|||||||
import * as PIXI from 'pixi.js';
|
import * as PIXI from 'pixi.js';
|
||||||
import GameMaster, { Globals } from './classes/Bastion';
|
import GameMaster, { Engine } from './classes/Bastion';
|
||||||
import Assets from './classes/Assets';
|
import Assets from './classes/Assets';
|
||||||
import { MainScene } from './scenes/Main';
|
import { MainScene } from './scenes/Main';
|
||||||
import { GameScene } from './scenes/Game';
|
import { GameScene } from './scenes/Game';
|
||||||
import { log } from './utils';
|
import { log } from './utils';
|
||||||
|
import AnimationManager from './classes/game/AnimationManager';
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const app = new PIXI.Application();
|
const app = new PIXI.Application();
|
||||||
Globals.app = app;
|
Engine.app = app;
|
||||||
log('main - init()');
|
log('main - init()');
|
||||||
await app.init({
|
await app.init({
|
||||||
width: 1920, // Base width
|
width: 1920, // Base width
|
||||||
@ -24,43 +25,37 @@ import { log } from './utils';
|
|||||||
function resize() {
|
function resize() {
|
||||||
const windowWidth = window.innerWidth;
|
const windowWidth = window.innerWidth;
|
||||||
const windowHeight = window.innerHeight;
|
const windowHeight = window.innerHeight;
|
||||||
Globals.WindowHeight = windowHeight;
|
|
||||||
Globals.WindowWidth = windowWidth;
|
|
||||||
|
|
||||||
// Calculate scale factor to maintain aspect ratio
|
|
||||||
const scaleX = windowWidth / app.screen.width;
|
const scaleX = windowWidth / app.screen.width;
|
||||||
const scaleY = windowHeight / app.screen.height;
|
const scaleY = windowHeight / app.screen.height;
|
||||||
const scale = Math.min(scaleX, scaleY); // Use the smaller scale to fit
|
const scale = Math.min(scaleX, scaleY);
|
||||||
|
|
||||||
// Calculate new canvas size
|
|
||||||
const gameWidth = Math.round(app.screen.width * scale);
|
const gameWidth = Math.round(app.screen.width * scale);
|
||||||
const gameHeight = Math.round(app.screen.height * scale);
|
const gameHeight = Math.round(app.screen.height * scale);
|
||||||
log(`main - resize(); window: ${window.innerWidth}x${window.innerHeight}}; game ${gameWidth}x${gameHeight}`);
|
|
||||||
|
|
||||||
// Center the canvas
|
|
||||||
const marginHorizontal = (windowWidth - gameWidth) / 2;
|
const marginHorizontal = (windowWidth - gameWidth) / 2;
|
||||||
const marginVertical = (windowHeight - gameHeight) / 2;
|
const marginVertical = (windowHeight - gameHeight) / 2;
|
||||||
|
|
||||||
// Apply styles to canvas
|
|
||||||
app.canvas.style.width = `${gameWidth}px`;
|
app.canvas.style.width = `${gameWidth}px`;
|
||||||
app.canvas.style.height = `${gameHeight}px`;
|
app.canvas.style.height = `${gameHeight}px`;
|
||||||
app.canvas.style.marginLeft = `${marginHorizontal}px`;
|
app.canvas.style.marginLeft = `${marginHorizontal}px`;
|
||||||
app.canvas.style.marginTop = `${marginVertical}px`;
|
app.canvas.style.marginTop = `${marginVertical}px`;
|
||||||
app.canvas.style.marginRight = `0`; // Prevent unnecessary margin
|
app.canvas.style.marginRight = `0`;
|
||||||
app.canvas.style.marginBottom = `0`; // Prevent unnecessary margin
|
app.canvas.style.marginBottom = `0`;
|
||||||
app.canvas.style.display = 'block'; // Prevent inline-block spacing issues
|
app.canvas.style.display = 'block';
|
||||||
}
|
}
|
||||||
Globals.latestCommit = await fetch('/latest_commit').then((res) => res.text());
|
Engine.latestCommit = await fetch('/latest_commit').then((res) => res.text());
|
||||||
window.addEventListener('resize', resize);
|
window.addEventListener('resize', resize);
|
||||||
resize();
|
resize();
|
||||||
await Assets.LoadAssets();
|
await Assets.LoadAssets();
|
||||||
new GameMaster();
|
new GameMaster();
|
||||||
globalThis.Globals = Globals;
|
Engine.AnimationManager = new AnimationManager();
|
||||||
Globals.GameMaster.changeScene(new MainScene());
|
globalThis.Engine = Engine;
|
||||||
|
PIXI.Ticker.shared.add((ticker) => Engine.AnimationManager.update(ticker.elapsedMS));
|
||||||
|
Engine.GameMaster.changeScene(new MainScene());
|
||||||
let params = new URLSearchParams(location.href);
|
let params = new URLSearchParams(location.href);
|
||||||
if (params.entries().next().value[1] == 'game') Globals.GameMaster.changeScene(new GameScene('Mission 1'));
|
if (params.entries().next().value[1] == 'game') Engine.GameMaster.changeScene(new GameScene('Mission 1'));
|
||||||
|
|
||||||
if (Globals.latestCommit != 'DEVELOPMENT')
|
if (Engine.latestCommit != 'DEVELOPMENT')
|
||||||
window.onbeforeunload = () => {
|
window.onbeforeunload = () => {
|
||||||
return 'You are about to leave.';
|
return 'You are about to leave.';
|
||||||
};
|
};
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import GameAssets from '../classes/Assets';
|
import GameAssets from '../classes/Assets';
|
||||||
import { Globals } from '../classes/Bastion';
|
import { Engine } from '../classes/Bastion';
|
||||||
import { MissionDefinition } from '../classes/Definitions';
|
import { MissionDefinition } from '../classes/Definitions';
|
||||||
import Creep, { CreepEvents } from '../classes/game/Creep';
|
import Creep, { CreepEvents } from '../classes/game/Creep';
|
||||||
import { Grid } from '../classes/game/Grid';
|
import { Grid } from '../classes/game/Grid';
|
||||||
@ -31,7 +31,7 @@ export class GameScene extends Scene {
|
|||||||
|
|
||||||
constructor(name: string) {
|
constructor(name: string) {
|
||||||
super();
|
super();
|
||||||
Globals.GameScene = this;
|
Engine.GameScene = this;
|
||||||
GameAssets.Missions.forEach((mission, index) => {
|
GameAssets.Missions.forEach((mission, index) => {
|
||||||
if (mission.name == name) {
|
if (mission.name == name) {
|
||||||
this.mission = mission;
|
this.mission = mission;
|
||||||
@ -45,23 +45,23 @@ export class GameScene extends Scene {
|
|||||||
this.ticker.minFPS = 30;
|
this.ticker.minFPS = 30;
|
||||||
this.ticker.add(() => this.update(this.ticker.elapsedMS)); // bruh
|
this.ticker.add(() => this.update(this.ticker.elapsedMS)); // bruh
|
||||||
this.ticker.start();
|
this.ticker.start();
|
||||||
const SidebarRect = new PIXI.Rectangle(64 * 30 - 360, 0, 360, Globals.app.canvas.height);
|
const SidebarRect = new PIXI.Rectangle(64 * 30 - 360, 0, 360, Engine.app.canvas.height);
|
||||||
const changeRoundButtonRect = new PIXI.Rectangle(50, Globals.app.canvas.height - 100, 310, 100);
|
const changeRoundButtonRect = new PIXI.Rectangle(50, Engine.app.canvas.height - 100, 310, 100);
|
||||||
new Grid(this.mission.gameMap, this.missionIndex);
|
new Grid(this.mission.gameMap, this.missionIndex);
|
||||||
new TowerManager();
|
new TowerManager();
|
||||||
new WaveManager(this.mission.rounds, this.mission.gameMap.paths);
|
new WaveManager(this.mission.rounds, this.mission.gameMap.paths);
|
||||||
Globals.Grid.onGridCellClicked = (row, column) => {
|
Engine.Grid.onGridCellClicked = (row, column) => {
|
||||||
if (Globals.TowerManager.isPlacingTower) {
|
if (Engine.TowerManager.isPlacingTower) {
|
||||||
Globals.TowerManager.PlayerClickOnGrid(row, column);
|
Engine.TowerManager.PlayerClickOnGrid(row, column);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Globals.WaveManager.events.on(WaveManagerEvents.CreepSpawned, (creep: Creep) => {
|
Engine.WaveManager.events.on(WaveManagerEvents.CreepSpawned, (creep: Creep) => {
|
||||||
Globals.Grid.addCreep(creep);
|
Engine.Grid.addCreep(creep);
|
||||||
creep.events.on(CreepEvents.Escaped, () => {
|
creep.events.on(CreepEvents.Escaped, () => {
|
||||||
this.onCreepEscaped(creep);
|
this.onCreepEscaped(creep);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
Globals.WaveManager.events.on(WaveManagerEvents.Finished, () => {
|
Engine.WaveManager.events.on(WaveManagerEvents.Finished, () => {
|
||||||
this.isWaveManagerFinished = true;
|
this.isWaveManagerFinished = true;
|
||||||
});
|
});
|
||||||
this.events.on(CreepEvents.Died, (playerAward, creepThatDied) => {
|
this.events.on(CreepEvents.Died, (playerAward, creepThatDied) => {
|
||||||
@ -80,10 +80,10 @@ export class GameScene extends Scene {
|
|||||||
this.MissionStats = new MissionStats(100, 200);
|
this.MissionStats = new MissionStats(100, 200);
|
||||||
}
|
}
|
||||||
public update(elapsedMS) {
|
public update(elapsedMS) {
|
||||||
Globals.WaveManager.update(elapsedMS);
|
Engine.WaveManager.update(elapsedMS);
|
||||||
Globals.Grid.update(elapsedMS);
|
Engine.Grid.update(elapsedMS);
|
||||||
Globals.TowerManager.update(elapsedMS);
|
Engine.TowerManager.update(elapsedMS);
|
||||||
if (this.isWaveManagerFinished && Globals.Grid.creeps.length == 0) {
|
if (this.isWaveManagerFinished && Engine.Grid.creeps.length == 0) {
|
||||||
this.changeRoundButton.setEnabled(true);
|
this.changeRoundButton.setEnabled(true);
|
||||||
this.changeRoundButton.setCaption('Start');
|
this.changeRoundButton.setCaption('Start');
|
||||||
this.setRoundMode(RoundMode.Purchase);
|
this.setRoundMode(RoundMode.Purchase);
|
||||||
@ -123,9 +123,9 @@ export class GameScene extends Scene {
|
|||||||
private setRoundMode(roundMode: RoundMode) {
|
private setRoundMode(roundMode: RoundMode) {
|
||||||
this.roundMode = roundMode;
|
this.roundMode = roundMode;
|
||||||
if (this.roundMode == RoundMode.Combat) {
|
if (this.roundMode == RoundMode.Combat) {
|
||||||
Globals.WaveManager.start(this.currentRound);
|
Engine.WaveManager.start(this.currentRound);
|
||||||
} else {
|
} else {
|
||||||
Globals.WaveManager.end();
|
Engine.WaveManager.end();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public NotifyPlayer(notification, notifytype) {
|
public NotifyPlayer(notification, notifytype) {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { Globals } from '../classes/Bastion';
|
import { Engine } from '../classes/Bastion';
|
||||||
|
import { FadeInOut } from '../classes/game/AnimationManager';
|
||||||
import Button, { ButtonTexture } from '../classes/gui/Button';
|
import Button, { ButtonTexture } from '../classes/gui/Button';
|
||||||
import { MissionPickerScene } from './MissionPicker';
|
import { MissionPickerScene } from './MissionPicker';
|
||||||
import Scene from './Scene';
|
import Scene from './Scene';
|
||||||
@ -9,8 +10,8 @@ export class MainScene extends Scene {
|
|||||||
const NewGameButton = {
|
const NewGameButton = {
|
||||||
caption: 'New Game',
|
caption: 'New Game',
|
||||||
rect: new PIXI.Rectangle(
|
rect: new PIXI.Rectangle(
|
||||||
Globals.app.canvas.width / 2 - 300 / 2,
|
Engine.app.canvas.width / 2 - 300 / 2,
|
||||||
Globals.app.canvas.height / 5 + 3 * 80,
|
Engine.app.canvas.height / 5 + 3 * 80,
|
||||||
300,
|
300,
|
||||||
60
|
60
|
||||||
),
|
),
|
||||||
@ -20,16 +21,16 @@ export class MainScene extends Scene {
|
|||||||
const SettingsButton = {
|
const SettingsButton = {
|
||||||
caption: 'Settings',
|
caption: 'Settings',
|
||||||
rect: new PIXI.Rectangle(
|
rect: new PIXI.Rectangle(
|
||||||
Globals.app.canvas.width / 2 - 300 / 2,
|
Engine.app.canvas.width / 2 - 300 / 2,
|
||||||
Globals.app.canvas.height / 5 + 4 * 80,
|
Engine.app.canvas.height / 5 + 4 * 80,
|
||||||
300,
|
300,
|
||||||
60
|
60
|
||||||
),
|
),
|
||||||
texture: ButtonTexture.Button02,
|
texture: ButtonTexture.Button02,
|
||||||
};
|
};
|
||||||
let text = new PIXI.Text({
|
let text = new PIXI.Text({
|
||||||
x: Globals.app.canvas.width / 2 - 300 / 2,
|
x: Engine.app.canvas.width / 2 - 300 / 2,
|
||||||
y: Globals.app.canvas.height / 5 + 1 * 80,
|
y: Engine.app.canvas.height / 5 + 1 * 80,
|
||||||
text: 'BASTION',
|
text: 'BASTION',
|
||||||
style: {
|
style: {
|
||||||
fill: 0xffaa00,
|
fill: 0xffaa00,
|
||||||
@ -38,28 +39,29 @@ export class MainScene extends Scene {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
text.x = text.x - text.width / 5;
|
text.x = text.x - text.width / 5;
|
||||||
Globals.app.stage.addChild(text);
|
Engine.app.stage.addChild(text);
|
||||||
let text2 = new PIXI.Text({
|
let text2 = new PIXI.Text({
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 0,
|
y: 0,
|
||||||
text: 'Latest commit: ' + Globals.latestCommit,
|
text: 'Latest commit: ' + Engine.latestCommit,
|
||||||
style: {
|
style: {
|
||||||
fill: 0x000000,
|
fill: 0x000000,
|
||||||
fontSize: 10,
|
fontSize: 10,
|
||||||
fontWeight: 'bold',
|
fontWeight: 'bold',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
Globals.app.stage.addChild(text2);
|
Engine.app.stage.addChild(text2);
|
||||||
const button01 = new Button(NewGameButton.rect, NewGameButton.caption, NewGameButton.texture, true);
|
const button01 = new Button(NewGameButton.rect, NewGameButton.caption, NewGameButton.texture, true);
|
||||||
button01.onClick = (e) => {
|
button01.onClick = (e) => {
|
||||||
Globals.app.stage.removeChild(text);
|
Engine.app.stage.removeChild(text);
|
||||||
Globals.app.stage.removeChild(text2);
|
Engine.app.stage.removeChild(text2);
|
||||||
Globals.GameMaster.changeScene(new MissionPickerScene());
|
Engine.GameMaster.changeScene(new MissionPickerScene());
|
||||||
};
|
};
|
||||||
|
|
||||||
let b2 = new Button(SettingsButton.rect, SettingsButton.caption, SettingsButton.texture, true);
|
let b2 = new Button(SettingsButton.rect, SettingsButton.caption, SettingsButton.texture, true);
|
||||||
b2.onClick = (e) => {
|
b2.onClick = (e) => {
|
||||||
alert('Does nothing for now, just placeholder.');
|
alert('Does nothing for now, just placeholder.');
|
||||||
};
|
};
|
||||||
|
Engine.AnimationManager.Animate(new FadeInOut('out', 120, b2.container, () => console.log(b2.container.alpha)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import Assets from '../classes/Assets';
|
import Assets from '../classes/Assets';
|
||||||
import { Globals } from '../classes/Bastion';
|
import { Engine } from '../classes/Bastion';
|
||||||
import Button, { ButtonTexture } from '../classes/gui/Button';
|
import Button, { ButtonTexture } from '../classes/gui/Button';
|
||||||
import { GameScene } from './Game';
|
import { GameScene } from './Game';
|
||||||
import { MainScene } from './Main';
|
import { MainScene } from './Main';
|
||||||
@ -10,13 +10,13 @@ export class MissionPickerScene extends Scene {
|
|||||||
public init() {
|
public init() {
|
||||||
const button = new Button(new PIXI.Rectangle(0, 0, 300, 60), 'Back to main', ButtonTexture.Button01);
|
const button = new Button(new PIXI.Rectangle(0, 0, 300, 60), 'Back to main', ButtonTexture.Button01);
|
||||||
button.onClick = (e) => {
|
button.onClick = (e) => {
|
||||||
Globals.GameMaster.changeScene(new MainScene());
|
Engine.GameMaster.changeScene(new MainScene());
|
||||||
};
|
};
|
||||||
Assets.Missions.forEach((mission, index) => {
|
Assets.Missions.forEach((mission, index) => {
|
||||||
const button = new Button(
|
const button = new Button(
|
||||||
new PIXI.Rectangle(
|
new PIXI.Rectangle(
|
||||||
Globals.app.canvas.width / 2 - 300 / 2,
|
Engine.app.canvas.width / 2 - 300 / 2,
|
||||||
Globals.app.canvas.height / 5 + index * 80,
|
Engine.app.canvas.height / 5 + index * 80,
|
||||||
300,
|
300,
|
||||||
60
|
60
|
||||||
),
|
),
|
||||||
@ -24,7 +24,7 @@ export class MissionPickerScene extends Scene {
|
|||||||
ButtonTexture.Button01
|
ButtonTexture.Button01
|
||||||
);
|
);
|
||||||
button.onClick = (e) => {
|
button.onClick = (e) => {
|
||||||
Globals.GameMaster.changeScene(new GameScene(mission.name));
|
Engine.GameMaster.changeScene(new GameScene(mission.name));
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user