From a14cca27ac7244f1704d1c757be3226e3891bb60 Mon Sep 17 00:00:00 2001 From: koneko <67551503+koneko@users.noreply.github.com> Date: Tue, 24 Dec 2024 16:36:09 +0100 Subject: [PATCH] wokring in progres --- public/assets/CreepStats.json | 2 +- public/maps.tiled-session | 17 +++++++- src/classes/Assets.ts | 2 +- src/classes/game/Creep.ts | 2 - src/classes/game/MissionStats.ts | 73 ++++++++++++++++++++++++++++++++ src/scenes/Game.ts | 17 +++++--- 6 files changed, 100 insertions(+), 13 deletions(-) create mode 100644 src/classes/game/MissionStats.ts diff --git a/public/assets/CreepStats.json b/public/assets/CreepStats.json index f672c43..2953501 100644 --- a/public/assets/CreepStats.json +++ b/public/assets/CreepStats.json @@ -1,7 +1,7 @@ [ { "health": 2, - "speed": 0.25, + "speed": 0.04, "special": null, "resistance": { "physical": 0, diff --git a/public/maps.tiled-session b/public/maps.tiled-session index f22f5ad..f9cf226 100644 --- a/public/maps.tiled-session +++ b/public/maps.tiled-session @@ -3,7 +3,7 @@ "height": 4300, "width": 2 }, - "activeFile": "", + "activeFile": "Mission011.tmx", "expandedProjectPaths": [ "." ], @@ -32,8 +32,17 @@ "y": 639.5548342221192 } }, + "Mission011.tmx": { + "scale": 0.5, + "selectedLayer": 0, + "viewCenter": { + "x": 1070, + "y": 448 + } + }, "Tileset.tsx": { - "scaleInDock": 1 + "scaleInDock": 0.5, + "scaleInEditor": 1 } }, "last.externalTilesetPath": "/home/koneko/Programing/js/towerdefense/public", @@ -43,9 +52,13 @@ "map.tileWidth": 64, "map.width": 30, "openFiles": [ + "Tileset.tsx", + "Mission011.tmx" ], "project": "maps.tiled-project", "recentFiles": [ + "Tileset.tsx", + "Mission011.tmx", "Mission01.tmx", "/home/koneko/dumping/tiles/TiledTDThree64.tmx" ], diff --git a/src/classes/Assets.ts b/src/classes/Assets.ts index bbd6a72..d51c81a 100644 --- a/src/classes/Assets.ts +++ b/src/classes/Assets.ts @@ -99,5 +99,5 @@ export default class GameAssets { public static Missions: MissionDefinition[]; public static Towers: TowerDefinition[]; public static CreepStats: CreepStatsDefinition[]; - public static DebuggingEnabled: boolean = true; + public static DebuggingEnabled: boolean = false; } diff --git a/src/classes/game/Creep.ts b/src/classes/game/Creep.ts index ed8ae1c..42aafe1 100644 --- a/src/classes/game/Creep.ts +++ b/src/classes/game/Creep.ts @@ -59,7 +59,6 @@ export default class Creep extends GameObject { const directionY = targetCell[0] - currentCell[0]; let deltaX = this.speed * elapsedMS * directionX; let deltaY = this.speed * elapsedMS * directionY; - console.log(deltaX + ' DELTA X UPDATE\n' + deltaY + 'DELTA Y UPDATE '); let increaseIndex = false; if (deltaX > 0 && this.x + deltaX > targetX) { @@ -84,7 +83,6 @@ export default class Creep extends GameObject { } this.x += deltaX; this.y += deltaY; - console.log(this.x + ' CREEP X UPDATE\n' + this.y + 'CREEP Y UPDATE '); if (increaseIndex) this.pathIndex++; this.draw(); } diff --git a/src/classes/game/MissionStats.ts b/src/classes/game/MissionStats.ts new file mode 100644 index 0000000..561ec0b --- /dev/null +++ b/src/classes/game/MissionStats.ts @@ -0,0 +1,73 @@ +import Assets from '../Assets'; +import { Globals } from '../Bastion'; +import GameObject from '../GameObject'; +import * as PIXI from 'pixi.js'; + +export default class MissionStats extends GameObject { + private hp: number = 100; + private gold: number = 0; + + public getHP() { + return this.hp; + } + + public setHP(hp: number) { + this.hp = hp; + } + + public takeDamage(damage: number) { + this.hp -= damage; + } + + public setGold(gold: number) { + this.gold = gold; + } + + constructor(initialHP: number, initialGold: number) { + super(); + this.hp = initialHP; + this.gold = initialGold; + this.container.x = 0; + this.container.y = 20; + Globals.app.stage.addChild(this.container); + const healthText = new PIXI.Text({ + text: `HP: ${this.hp}`, + style: new PIXI.TextStyle({ + fill: 'white', + fontSize: 24, + fontWeight: 'bold', + dropShadow: true, + }), + }); + healthText.x = 200; + const goldText = new PIXI.Text({ + text: `Gold: ${this.gold}`, + style: new PIXI.TextStyle({ + fill: 'white', + fontSize: 24, + fontWeight: 'bold', + dropShadow: true, + }), + }); + goldText.x = 200; + goldText.y = 30; + + const healthSprite = new PIXI.Sprite(Assets.HealthTexture); + healthSprite.x = 165; + healthSprite.width = 30; + healthSprite.height = 26; + healthSprite.y = 1; + + const goldSprite = new PIXI.Sprite(Assets.GoldTexture); + goldSprite.x = 165; + goldSprite.width = 30; + goldSprite.height = 26; + goldSprite.y = 30; + this.container.addChild(healthText); + this.container.addChild(goldText); + this.container.addChild(healthSprite); + this.container.addChild(goldSprite); + } + + public update() {} +} diff --git a/src/scenes/Game.ts b/src/scenes/Game.ts index b216c42..e5cb320 100644 --- a/src/scenes/Game.ts +++ b/src/scenes/Game.ts @@ -8,6 +8,7 @@ import Sidebar from '../classes/gui/Sidebar'; import Button, { ButtonTexture } from '../classes/gui/Button'; import Scene from './Scene'; import * as PIXI from 'pixi.js'; +import MissionStats from '../classes/game/MissionStats'; enum RoundMode { Purchase = 0, @@ -19,6 +20,7 @@ export class GameScene extends Scene { public missionIndex: number; public roundMode: RoundMode; public ticker: PIXI.Ticker; + public changeRoundButton: Button; private currentRound: number = 0; constructor(name: string) { @@ -36,8 +38,8 @@ export class GameScene extends Scene { this.ticker.minFPS = 30; this.ticker.add(() => this.update(this.ticker.elapsedMS)); // bruh this.ticker.start(); - const SidebarRect = new PIXI.Rectangle(Globals.WindowWidth - 350, 0, 350, Globals.app.canvas.height); - const StartButtonRect = new PIXI.Rectangle(Globals.WindowWidth - 200, Globals.WindowHeight, 200, 100); + 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); new Grid(this.mission.gameMap, this.missionIndex); new WaveManager(this.mission.rounds, this.mission.gameMap.paths); @@ -48,14 +50,15 @@ export class GameScene extends Scene { }); }); new Sidebar(SidebarRect); - // const changeRoundButton = new Button('Start', new PIXI.Color('white'), true); - const changeRoundButton = new Button(StartButtonRect, 'Start', ButtonTexture.Button01, true); - changeRoundButton.onClick = () => { + this.changeRoundButton = new Button(changeRoundButtonRect, 'Start', ButtonTexture.Button01, true); + this.changeRoundButton.onClick = () => { console.log('clicked'); - changeRoundButton.setEnabled(false); - changeRoundButton.setCaption('[X]'); + this.changeRoundButton.setEnabled(false); + this.changeRoundButton.setCaption('[X]'); this.setRoundMode(RoundMode.Combat); }; + + new MissionStats(100, 200); } public update(elapsedMS) { Globals.WaveManager.update(elapsedMS);