pick tower while choosing another
This commit is contained in:
parent
36a9cacb1c
commit
a9f083a81e
@ -39,7 +39,7 @@ export default class GameAssets {
|
||||
|
||||
public static async LoadAssets() {
|
||||
if (this.text) {
|
||||
throw 'Do not call GameAssets.LoadAssets() more than once.';
|
||||
console.warn('Do not call GameAssets.LoadAssets() more than once.');
|
||||
return;
|
||||
}
|
||||
console.log('Loading Texture Assets');
|
||||
@ -124,9 +124,10 @@ export default class GameAssets {
|
||||
for (let idx = 0; idx < this.Towers.length; idx++) {
|
||||
const tower = this.Towers[idx];
|
||||
for (let i = 0; i < tower.projectileTexturesArrayLength; i++) {
|
||||
const texture = await this.Load(`/assets/projectiles/${tower.sprite}/${i}.png`);
|
||||
tower.projectileTextures[i] = texture;
|
||||
const projTexture = await this.Load(`/assets/projectiles/${tower.sprite}/${i}.png`);
|
||||
tower.projectileTextures[i] = projTexture;
|
||||
}
|
||||
tower.texture = await this.Load(`/assets/towers/${tower.sprite}.png`);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -38,12 +38,17 @@ export class Cell extends GameObject {
|
||||
zIndex: 99,
|
||||
interactive: true,
|
||||
});
|
||||
// ? TODO: make range preview 1 global graphics obj, child. fix
|
||||
this.rangePreview = new PIXI.Graphics({
|
||||
zIndex: 6,
|
||||
zIndex: 10,
|
||||
});
|
||||
this.g = new PIXI.Graphics({
|
||||
zIndex: 5,
|
||||
});
|
||||
this.clickDetector.rect(0, 0, this.bb.width, this.bb.height);
|
||||
this.clickDetector.fill({ color: 0xff0000, alpha: 0 });
|
||||
this.container.addChild(this.clickDetector);
|
||||
this.container.addChild(this.g);
|
||||
this.container.addChild(this.rangePreview);
|
||||
this.clickDetector.on('pointerup', (e) => {
|
||||
Engine.Grid.onGridCellClicked(row, column);
|
||||
@ -79,9 +84,6 @@ export class Cell extends GameObject {
|
||||
);
|
||||
}
|
||||
public gDraw() {
|
||||
this.g = new PIXI.Graphics({
|
||||
zIndex: 5,
|
||||
});
|
||||
this.g.rect(0, 0, this.bb.width, this.bb.height);
|
||||
if (this.type == TerrainType.Restricted) {
|
||||
this.g.fill({ color: 0x222222, alpha: 0.5 });
|
||||
@ -92,7 +94,6 @@ export class Cell extends GameObject {
|
||||
} else if (this.type == TerrainType.Buildable) {
|
||||
this.g.stroke({ color: 0x00ff00, alpha: 0.9 });
|
||||
}
|
||||
this.container.addChild(this.g);
|
||||
}
|
||||
public gClear() {
|
||||
this.g.clear();
|
||||
@ -130,15 +131,25 @@ export class Grid extends GameObject {
|
||||
}
|
||||
}
|
||||
}
|
||||
public toggleGrid() {
|
||||
public toggleGrid(force?: 'hide' | 'show') {
|
||||
this.cells.forEach((cell) => {
|
||||
if (force) {
|
||||
if (force == 'hide') {
|
||||
cell.gClear();
|
||||
} else {
|
||||
cell.gDraw();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (this.gridShown) {
|
||||
cell.gClear();
|
||||
} else {
|
||||
cell.gDraw();
|
||||
}
|
||||
});
|
||||
this.gridShown = !this.gridShown;
|
||||
if (force == 'hide') this.gridShown = false;
|
||||
else if (force == 'show') this.gridShown = true;
|
||||
else this.gridShown = !this.gridShown;
|
||||
}
|
||||
public addCreep(creep: Creep) {
|
||||
this.creeps.push(creep);
|
||||
|
@ -12,7 +12,7 @@ export enum TowerBehaviours {
|
||||
export default class TowerManager {
|
||||
public isPlacingTower: boolean = false;
|
||||
public canPlaceTowers: boolean = true;
|
||||
private selectedTower: TowerDefinition | null = null;
|
||||
public selectedTower: TowerDefinition | null = null;
|
||||
private previewSprite: PIXI.Sprite = new PIXI.Sprite({
|
||||
parent: Engine.GameMaster.currentScene.stage,
|
||||
zIndex: 10,
|
||||
@ -40,6 +40,11 @@ export default class TowerManager {
|
||||
}
|
||||
});
|
||||
}
|
||||
public ResetChooseTower() {
|
||||
this.selectedTower = null;
|
||||
this.isPlacingTower = false;
|
||||
Engine.Grid.toggleGrid('hide');
|
||||
}
|
||||
public ToggleChoosingTowerLocation(towerName: string) {
|
||||
if (!this.canPlaceTowers) return;
|
||||
Engine.Grid.toggleGrid();
|
||||
@ -47,6 +52,7 @@ export default class TowerManager {
|
||||
GameAssets.Towers.forEach((item) => {
|
||||
if (item.name == towerName) {
|
||||
this.selectedTower = item;
|
||||
console.log(this.selectedTower);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
@ -5,9 +5,9 @@ import TowerTab from './TowerTab';
|
||||
import GemTab from './GemTab';
|
||||
|
||||
export default class Sidebar extends GuiObject {
|
||||
public towerTab: TowerTab;
|
||||
private bounds: PIXI.Rectangle;
|
||||
private sidebarSprite: PIXI.NineSliceSprite;
|
||||
private towerTab: TowerTab;
|
||||
private gemTab: GemTab;
|
||||
|
||||
constructor(bounds: PIXI.Rectangle) {
|
||||
|
@ -44,7 +44,7 @@ class TowerButton extends GuiObject {
|
||||
this.container.addChild(this.frameSprite);
|
||||
parent.addChild(this.container);
|
||||
Engine.GameScene.events.on(TowerEvents.TowerPlacedEvent, (name) => {
|
||||
this.frameSprite.tint = 0xffffff; // reset the tint after a tower has been placed
|
||||
this.resetTint();
|
||||
});
|
||||
this.container.onpointerenter = (e) => {
|
||||
// add on mouse over info (banner next to sidebar)
|
||||
@ -53,24 +53,28 @@ class TowerButton extends GuiObject {
|
||||
this.container.onpointerleave = (e) => {};
|
||||
}
|
||||
public onClick(e: PIXI.FederatedPointerEvent): void {
|
||||
if (Engine.TowerManager.isPlacingTower && Engine.TowerManager.selectedTower.name != this.towerName) {
|
||||
Engine.GameScene.sidebar.towerTab.resetTint();
|
||||
Engine.TowerManager.ResetChooseTower();
|
||||
}
|
||||
if (this.frameSprite.tint == 0x00ff00) this.frameSprite.tint = 0xffffff;
|
||||
else this.frameSprite.tint = 0x00ff00;
|
||||
Engine.TowerManager.ToggleChoosingTowerLocation(this.towerName);
|
||||
}
|
||||
public resetTint() {
|
||||
this.frameSprite.tint = 0xffffff;
|
||||
}
|
||||
}
|
||||
|
||||
export default class TowerTab extends GuiObject {
|
||||
private bounds: PIXI.Rectangle;
|
||||
private towerTabSprite: PIXI.NineSliceSprite;
|
||||
private towerList: Array<any> = [];
|
||||
private towerButtons: TowerButton[] = [];
|
||||
|
||||
constructor(bounds: PIXI.Rectangle) {
|
||||
super(false);
|
||||
this.bounds = bounds;
|
||||
GameAssets.Towers.forEach((twr) => {
|
||||
let obj = { name: twr.name, description: twr.description, cost: twr.stats.cost };
|
||||
this.towerList.push(obj);
|
||||
});
|
||||
|
||||
this.container.x = this.bounds.x;
|
||||
this.container.y = this.bounds.y;
|
||||
this.towerTabSprite = new PIXI.NineSliceSprite({
|
||||
@ -84,26 +88,32 @@ export default class TowerTab extends GuiObject {
|
||||
this.towerTabSprite.width = this.bounds.width;
|
||||
this.towerTabSprite.height = this.bounds.height;
|
||||
this.container.addChild(this.towerTabSprite);
|
||||
|
||||
new TowerButton(
|
||||
0,
|
||||
0,
|
||||
70,
|
||||
70,
|
||||
this.container,
|
||||
GameAssets.RedBackground,
|
||||
'Basic Tower',
|
||||
GameAssets.HammerIconTexture
|
||||
this.towerButtons.push(
|
||||
new TowerButton(
|
||||
0,
|
||||
0,
|
||||
70,
|
||||
70,
|
||||
this.container,
|
||||
GameAssets.RedBackground,
|
||||
'Basic Tower',
|
||||
GameAssets.HammerIconTexture
|
||||
)
|
||||
);
|
||||
new TowerButton(
|
||||
0,
|
||||
1,
|
||||
70,
|
||||
70,
|
||||
this.container,
|
||||
GameAssets.GreenBackground,
|
||||
'Circle Tower',
|
||||
GameAssets.HomeIconTexture
|
||||
this.towerButtons.push(
|
||||
new TowerButton(
|
||||
0,
|
||||
1,
|
||||
70,
|
||||
70,
|
||||
this.container,
|
||||
GameAssets.GreenBackground,
|
||||
'Circle Tower',
|
||||
GameAssets.HomeIconTexture
|
||||
)
|
||||
);
|
||||
}
|
||||
public resetTint() {
|
||||
this.towerButtons.forEach((item) => item.resetTint());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user