From 64a5bf35abf9be9ef5c04984e374c7cd8d500909 Mon Sep 17 00:00:00 2001 From: koneko <67551503+koneko@users.noreply.github.com> Date: Mon, 13 Jan 2025 15:21:42 +0100 Subject: [PATCH] work --- src/classes/GameUIConstants.ts | 15 +++++++++++++++ src/classes/game/Grid.ts | 5 ----- src/classes/game/Tower.ts | 2 +- src/main.ts | 3 ++- src/scenes/Game.ts | 14 ++++++++------ 5 files changed, 26 insertions(+), 13 deletions(-) create mode 100644 src/classes/GameUIConstants.ts diff --git a/src/classes/GameUIConstants.ts b/src/classes/GameUIConstants.ts new file mode 100644 index 0000000..a875166 --- /dev/null +++ b/src/classes/GameUIConstants.ts @@ -0,0 +1,15 @@ +import * as PIXI from 'pixi.js'; +import { Engine } from './Bastion'; +export default class GameUIConstants { + public static SidebarRect; + public static ChangeRoundButtonRect; + public static init() { + GameUIConstants.SidebarRect = new PIXI.Rectangle( + Engine.app.canvas.width - 360, + 0, + 360, + Engine.app.canvas.height + ); + GameUIConstants.ChangeRoundButtonRect = new PIXI.Rectangle(50, Engine.app.canvas.height - 100, 310, 100); + } +} diff --git a/src/classes/game/Grid.ts b/src/classes/game/Grid.ts index e33e55d..39b6691 100644 --- a/src/classes/game/Grid.ts +++ b/src/classes/game/Grid.ts @@ -97,11 +97,6 @@ export class Grid extends GameObject { Engine.GameMaster.currentScene.stage.addChild(this.container); let background = new PIXI.Sprite(GameAssets.MissionBackgrounds[missionIndex]); - background.x = 0; - background.y = 0; - background.width = this.bb.width; - background.height = this.bb.height; - this.container.addChild(background); for (let y = 0; y < this.gameMap.columns; y++) { diff --git a/src/classes/game/Tower.ts b/src/classes/game/Tower.ts index 1622116..c14dc31 100644 --- a/src/classes/game/Tower.ts +++ b/src/classes/game/Tower.ts @@ -78,7 +78,7 @@ export class Tower extends GameObject { const towerY = this.row * Engine.GridCellSize + Engine.GridCellSize / 2; const radius = this.definition.stats.range * Engine.GridCellSize; const d = distance(towerX, towerY, x, y); - return d < radius; + return d < radius + Engine.GridCellSize; }); } public Shoot(creep: Creep) { diff --git a/src/main.ts b/src/main.ts index ddd3276..3b70666 100644 --- a/src/main.ts +++ b/src/main.ts @@ -3,9 +3,9 @@ import GameMaster, { Engine } from './classes/Bastion'; import Assets from './classes/Assets'; import { MainScene } from './scenes/Main'; import { GameScene } from './scenes/Game'; -import { log } from './utils'; import { AnimationManager } from './classes/game/AnimationManager'; import NotificationManager from './classes/game/NotificationManager'; +import GameUIConstants from './classes/GameUIConstants'; (async () => { const app = new PIXI.Application(); @@ -46,6 +46,7 @@ import NotificationManager from './classes/game/NotificationManager'; window.addEventListener('resize', resize); resize(); await Assets.LoadAssets(); + GameUIConstants.init(); new GameMaster(); Engine.AnimationManager = new AnimationManager(); Engine.NotificationManager = new NotificationManager(); diff --git a/src/scenes/Game.ts b/src/scenes/Game.ts index 19fbc2b..930d890 100644 --- a/src/scenes/Game.ts +++ b/src/scenes/Game.ts @@ -11,6 +11,7 @@ import * as PIXI from 'pixi.js'; import MissionStats from '../classes/game/MissionStats'; import TowerManager from '../classes/game/TowerManager'; import { MissionPickerScene } from './MissionPicker'; +import GameUIConstants from '../classes/GameUIConstants'; enum RoundMode { Purchase = 0, @@ -49,10 +50,6 @@ export class GameScene extends Scene { if (this.update) this.update(this.ticker.elapsedMS); }); this.ticker.start(); - console.log(Engine.GridCellSize * (Engine.GridColumns + 5) - 360); - console.log(Engine.app.canvas.width - 360); - const SidebarRect = new PIXI.Rectangle(Engine.app.canvas.width - 360, 0, 360, Engine.app.canvas.height); - const changeRoundButtonRect = new PIXI.Rectangle(50, Engine.app.canvas.height - 100, 310, 100); new Grid(this.mission.gameMap, this.missionIndex); new TowerManager(); new WaveManager(this.mission.rounds, this.mission.gameMap.paths); @@ -73,8 +70,13 @@ export class GameScene extends Scene { this.events.on(CreepEvents.Died, (playerAward, creepThatDied) => { this.MissionStats.earnGold(playerAward); }); - this.sidebar = new Sidebar(SidebarRect); - this.changeRoundButton = new Button(changeRoundButtonRect, 'Start', ButtonTexture.Button01, true); + this.sidebar = new Sidebar(GameUIConstants.SidebarRect); + this.changeRoundButton = new Button( + GameUIConstants.ChangeRoundButtonRect, + 'Start', + ButtonTexture.Button01, + true + ); this.changeRoundButton.container.removeFromParent(); this.sidebar.container.addChild(this.changeRoundButton.container); this.changeRoundButton.onClick = () => {