This commit is contained in:
koneko 2024-12-24 20:45:38 +01:00
parent a14cca27ac
commit cd2c16f7f5
7 changed files with 48 additions and 39 deletions

View File

@ -6,25 +6,25 @@
}, },
"gameMap": { "gameMap": {
"rows": 17, "rows": 17,
"columns": 30, "columns": 25,
"cells": [ "cells": [
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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],
[5, 27],
[5, 28],
[5, 29]
] ]
] ]
}, },

View File

@ -41,7 +41,7 @@ export default class GameAssets {
src: '/assets/gui/heart.png', src: '/assets/gui/heart.png',
}); });
GameAssets.GoldTexture = await PIXI.Assets.load({ GameAssets.GoldTexture = await PIXI.Assets.load({
src: '/assets/gui/star.png', src: '/assets/gui/money.png',
}); });
GameAssets.BasicCreepTexture = await PIXI.Assets.load({ GameAssets.BasicCreepTexture = await PIXI.Assets.load({
src: '/assets/creeps/basic.jpg', src: '/assets/creeps/basic.jpg',

View File

@ -19,6 +19,7 @@ export default class Creep extends GameObject {
private pathIndex: number = 0; private pathIndex: number = 0;
private speed: number; private speed: number;
public health: number; public health: number;
public maxHealth: number;
public escaped: boolean = false; public escaped: boolean = false;
public died: boolean = false; public died: boolean = false;
public x: number; // X and Y are local to the grid, not canvas public x: number; // X and Y are local to the grid, not canvas
@ -37,6 +38,7 @@ export default class Creep extends GameObject {
this.sprite.height = 64; this.sprite.height = 64;
this.speed = this.stats.speed; this.speed = this.stats.speed;
this.health = this.stats.health; this.health = this.stats.health;
this.maxHealth = this.stats.health;
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;

View File

@ -38,7 +38,7 @@ export class Cell extends GameObject {
this.container.addChild(g); this.container.addChild(g);
this.container.x = this.bb.x; this.container.x = this.bb.x;
this.container.y = this.bb.y; this.container.y = this.bb.y;
if (!GameAssets.DebuggingEnabled) return; // if (!GameAssets.DebuggingEnabled) return;
const text = new PIXI.Text({ const text = new PIXI.Text({
text: `${this.row}|${this.column}`, text: `${this.row}|${this.column}`,
style: new PIXI.TextStyle({ style: new PIXI.TextStyle({

View File

@ -6,6 +6,8 @@ import * as PIXI from 'pixi.js';
export default class MissionStats extends GameObject { export default class MissionStats extends GameObject {
private hp: number = 100; private hp: number = 100;
private gold: number = 0; private gold: number = 0;
private goldText: PIXI.Text;
private healthText: PIXI.Text;
public getHP() { public getHP() {
return this.hp; return this.hp;
@ -13,14 +15,17 @@ export default class MissionStats extends GameObject {
public setHP(hp: number) { public setHP(hp: number) {
this.hp = hp; this.hp = hp;
this.healthText.text = 'HP: ' + this.hp;
} }
public takeDamage(damage: number) { public takeDamage(damage: number) {
this.hp -= damage; this.hp -= damage;
this.healthText.text = 'HP: ' + this.hp;
} }
public setGold(gold: number) { public setGold(gold: number) {
this.gold = gold; this.gold = gold;
this.goldText.text = 'Gold: ' + this.gold;
} }
constructor(initialHP: number, initialGold: number) { constructor(initialHP: number, initialGold: number) {
@ -30,7 +35,7 @@ export default class MissionStats extends GameObject {
this.container.x = 0; this.container.x = 0;
this.container.y = 20; this.container.y = 20;
Globals.app.stage.addChild(this.container); Globals.app.stage.addChild(this.container);
const healthText = new PIXI.Text({ this.healthText = new PIXI.Text({
text: `HP: ${this.hp}`, text: `HP: ${this.hp}`,
style: new PIXI.TextStyle({ style: new PIXI.TextStyle({
fill: 'white', fill: 'white',
@ -39,8 +44,8 @@ export default class MissionStats extends GameObject {
dropShadow: true, dropShadow: true,
}), }),
}); });
healthText.x = 200; this.healthText.x = 200;
const goldText = new PIXI.Text({ this.goldText = new PIXI.Text({
text: `Gold: ${this.gold}`, text: `Gold: ${this.gold}`,
style: new PIXI.TextStyle({ style: new PIXI.TextStyle({
fill: 'white', fill: 'white',
@ -49,8 +54,8 @@ export default class MissionStats extends GameObject {
dropShadow: true, dropShadow: true,
}), }),
}); });
goldText.x = 200; this.goldText.x = 200;
goldText.y = 30; this.goldText.y = 30;
const healthSprite = new PIXI.Sprite(Assets.HealthTexture); const healthSprite = new PIXI.Sprite(Assets.HealthTexture);
healthSprite.x = 165; healthSprite.x = 165;
@ -63,8 +68,8 @@ export default class MissionStats extends GameObject {
goldSprite.width = 30; goldSprite.width = 30;
goldSprite.height = 26; goldSprite.height = 26;
goldSprite.y = 30; goldSprite.y = 30;
this.container.addChild(healthText); this.container.addChild(this.healthText);
this.container.addChild(goldText); this.container.addChild(this.goldText);
this.container.addChild(healthSprite); this.container.addChild(healthSprite);
this.container.addChild(goldSprite); this.container.addChild(goldSprite);
} }

View File

@ -21,7 +21,7 @@ export default class Sidebar extends GuiObject {
this.sidebarSprite.x = 40; this.sidebarSprite.x = 40;
this.sidebarSprite.y = -40; this.sidebarSprite.y = -40;
this.sidebarSprite.width = this.bounds.width + 40; this.sidebarSprite.width = this.bounds.width + 40;
this.sidebarSprite.height = this.bounds.height + 80; this.sidebarSprite.height = this.bounds.height + 41;
this.container.addChild(this.sidebarSprite); this.container.addChild(this.sidebarSprite);
} }
} }

View File

@ -18,9 +18,13 @@ enum RoundMode {
export class GameScene extends Scene { export class GameScene extends Scene {
public mission: MissionDefinition; public mission: MissionDefinition;
public missionIndex: number; public missionIndex: number;
public MissionStats: MissionStats;
public roundMode: RoundMode; public roundMode: RoundMode;
public ticker: PIXI.Ticker; public ticker: PIXI.Ticker;
public changeRoundButton: Button; public changeRoundButton: Button;
public sidebar: Sidebar;
public hideSidebarButton: Button;
public sidebarHidden: boolean = false;
private currentRound: number = 0; private currentRound: number = 0;
constructor(name: string) { constructor(name: string) {
@ -39,8 +43,7 @@ export class GameScene extends Scene {
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 - 350, 0, 350, Globals.app.canvas.height); const SidebarRect = new PIXI.Rectangle(64 * 30 - 350, 0, 350, Globals.app.canvas.height);
const changeRoundButtonRect = new PIXI.Rectangle(64 * 30 - 200, Globals.app.canvas.height - 100, 200, 100); const changeRoundButtonRect = new PIXI.Rectangle(50, Globals.app.canvas.height - 100, 300, 100);
new Grid(this.mission.gameMap, this.missionIndex); new Grid(this.mission.gameMap, this.missionIndex);
new WaveManager(this.mission.rounds, this.mission.gameMap.paths); new WaveManager(this.mission.rounds, this.mission.gameMap.paths);
Globals.WaveManager.events.on(WaveManagerEvents.CreepSpawned, (creep: Creep) => { Globals.WaveManager.events.on(WaveManagerEvents.CreepSpawned, (creep: Creep) => {
@ -49,8 +52,10 @@ export class GameScene extends Scene {
this.onCreepEscaped(creep); this.onCreepEscaped(creep);
}); });
}); });
new Sidebar(SidebarRect); this.sidebar = new Sidebar(SidebarRect);
this.changeRoundButton = new Button(changeRoundButtonRect, 'Start', ButtonTexture.Button01, true); this.changeRoundButton = new Button(changeRoundButtonRect, 'Start', ButtonTexture.Button01, true);
this.changeRoundButton.container.removeFromParent();
this.sidebar.container.addChild(this.changeRoundButton.container);
this.changeRoundButton.onClick = () => { this.changeRoundButton.onClick = () => {
console.log('clicked'); console.log('clicked');
this.changeRoundButton.setEnabled(false); this.changeRoundButton.setEnabled(false);
@ -58,13 +63,15 @@ export class GameScene extends Scene {
this.setRoundMode(RoundMode.Combat); this.setRoundMode(RoundMode.Combat);
}; };
new MissionStats(100, 200); this.MissionStats = new MissionStats(100, 200);
} }
public update(elapsedMS) { public update(elapsedMS) {
Globals.WaveManager.update(elapsedMS); Globals.WaveManager.update(elapsedMS);
Globals.Grid.update(elapsedMS); Globals.Grid.update(elapsedMS);
} }
public onCreepEscaped(creep: Creep) {} public onCreepEscaped(creep: Creep) {
this.MissionStats.takeDamage(creep.health);
}
private setRoundMode(roundMode: RoundMode) { private setRoundMode(roundMode: RoundMode) {
this.roundMode = roundMode; this.roundMode = roundMode;