exported creepstats to seperate file
This commit is contained in:
parent
660599c439
commit
e04d4a76c7
14
public/assets/CreepStats.json
Normal file
14
public/assets/CreepStats.json
Normal file
@ -0,0 +1,14 @@
|
||||
[
|
||||
{
|
||||
"health": 2,
|
||||
"speed": 0.0005,
|
||||
"special": null,
|
||||
"resistance": {
|
||||
"physical": 0,
|
||||
"divine": 0,
|
||||
"fire": 0,
|
||||
"ice": 0,
|
||||
"frostfire": 0
|
||||
}
|
||||
}
|
||||
]
|
@ -30,7 +30,6 @@
|
||||
[
|
||||
[8, 0],
|
||||
[8, 1],
|
||||
[8, 2],
|
||||
[9, 2],
|
||||
[10, 2],
|
||||
[11, 2],
|
||||
@ -44,7 +43,6 @@
|
||||
[11, 10],
|
||||
[10, 10],
|
||||
[9, 10],
|
||||
[8, 10],
|
||||
[8, 11],
|
||||
[8, 12],
|
||||
[8, 13],
|
||||
|
@ -1,5 +1,5 @@
|
||||
import * as PIXI from 'pixi.js';
|
||||
import { MissionDefinition } from './Definitions';
|
||||
import { CreepStats, MissionDefinition } from './Definitions';
|
||||
|
||||
export default class Assets {
|
||||
public static async LoadAssets() {
|
||||
@ -12,6 +12,13 @@ export default class Assets {
|
||||
});
|
||||
console.log('Loading Missions');
|
||||
await this.LoadMissions();
|
||||
await this.LoadCreepStats();
|
||||
}
|
||||
|
||||
public static async LoadCreepStats() {
|
||||
const res = await fetch('/assets/CreepStats.json');
|
||||
const stats = await res.json();
|
||||
this.CreepStats = stats;
|
||||
}
|
||||
|
||||
private static async LoadMissions() {
|
||||
@ -38,4 +45,5 @@ export default class Assets {
|
||||
|
||||
public static MissionBackgrounds: PIXI.Texture[] = [];
|
||||
public static Missions: MissionDefinition[];
|
||||
public static CreepStats: CreepStats[];
|
||||
}
|
||||
|
@ -30,6 +30,21 @@ export type WaveDefinition = {
|
||||
creeps: CreepType[];
|
||||
};
|
||||
|
||||
export type CreepStats = {
|
||||
health: number;
|
||||
speed: number;
|
||||
special: Function;
|
||||
resistance: CreepResistances;
|
||||
};
|
||||
|
||||
export type CreepResistances = {
|
||||
physical: number;
|
||||
divine: number;
|
||||
fire: number;
|
||||
ice: number;
|
||||
frostfire: number;
|
||||
};
|
||||
|
||||
export type PathDefinition = [[row: number, column: number]];
|
||||
|
||||
export enum CreepType {
|
||||
@ -40,6 +55,7 @@ export enum CreepType {
|
||||
export enum TerrainType {
|
||||
Restricted = 0,
|
||||
Buildable = 1,
|
||||
Path = 9,
|
||||
}
|
||||
|
||||
export enum GemType {
|
||||
|
@ -1,42 +1,8 @@
|
||||
import Assets from '../base/Assets';
|
||||
import { CreepType, PathDefinition } from '../base/Definitions';
|
||||
import { CreepStats, CreepType, PathDefinition } from '../base/Definitions';
|
||||
import GameObject from '../base/GameObject';
|
||||
import * as PIXI from 'pixi.js';
|
||||
import GameScene from '../scenes/GameScene';
|
||||
import { Grid } from './Grid';
|
||||
|
||||
export function CreepStats(ctype: CreepType): object {
|
||||
switch (ctype) {
|
||||
case CreepType.Basic:
|
||||
return {
|
||||
health: 2,
|
||||
speed: 0.45,
|
||||
special: null,
|
||||
resistance: {
|
||||
physical: 0,
|
||||
divine: 0,
|
||||
fire: 0,
|
||||
ice: 0,
|
||||
frostfire: 0,
|
||||
},
|
||||
};
|
||||
case CreepType.Fast:
|
||||
throw new Error('Fast creep not defined.');
|
||||
default:
|
||||
return {
|
||||
health: null,
|
||||
speed: null,
|
||||
special: null,
|
||||
resistance: {
|
||||
physical: null,
|
||||
divine: null,
|
||||
fire: null,
|
||||
ice: null,
|
||||
frostfire: null,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export enum CreepEvents {
|
||||
Died = 'died',
|
||||
@ -48,23 +14,30 @@ export enum CreepEvents {
|
||||
export default class Creep extends GameObject {
|
||||
public creepType: CreepType;
|
||||
private path: PathDefinition;
|
||||
private stats: CreepStats;
|
||||
private pathIndex: number = 0;
|
||||
private speed: number = 0.002;
|
||||
private speed: number;
|
||||
private gameScene: GameScene;
|
||||
public health: number = 2;
|
||||
public health: number;
|
||||
public escaped: boolean = false;
|
||||
public died: boolean = false;
|
||||
public x: number; // X and Y are local to the grid, not canvas
|
||||
public y: number;
|
||||
constructor(creepType: CreepType, path: PathDefinition, gameScene: GameScene, bounds?: PIXI.Rectangle) {
|
||||
super(bounds);
|
||||
this.creepType = creepType;
|
||||
this.path = path;
|
||||
this.gameScene = gameScene;
|
||||
this.creepType = creepType;
|
||||
this.stats = Assets.CreepStats[this.creepType];
|
||||
this.speed = this.stats.speed;
|
||||
this.health = this.stats.health;
|
||||
this.path = path;
|
||||
this.x = path[0][1] + 0.5; // centered
|
||||
this.y = path[0][0] + 0.5;
|
||||
this.gameScene.grid.container.addChild(this.container);
|
||||
}
|
||||
private gridUnitsToPixels(gridUnits) {
|
||||
return this.gameScene.grid.gridUnitsToPixels(gridUnits);
|
||||
}
|
||||
public update(elapsedMS: number) {
|
||||
if (this.pathIndex + 1 == this.path.length) {
|
||||
if (this.escaped) return;
|
||||
@ -108,10 +81,10 @@ export default class Creep extends GameObject {
|
||||
if (increaseIndex) this.pathIndex++;
|
||||
this.setBounds(
|
||||
new PIXI.Rectangle(
|
||||
this.gameScene.grid.gridUnitsToPixels(this.x),
|
||||
this.gameScene.grid.gridUnitsToPixels(this.y),
|
||||
this.gameScene.grid.gridUnitsToPixels(0.5),
|
||||
this.gameScene.grid.gridUnitsToPixels(0.6)
|
||||
this.gridUnitsToPixels(this.x),
|
||||
this.gridUnitsToPixels(this.y),
|
||||
this.gridUnitsToPixels(0.5),
|
||||
this.gridUnitsToPixels(0.6)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -30,11 +30,17 @@ export class Cell extends GameObject {
|
||||
case TerrainType.Restricted:
|
||||
g.fill(0xff0000);
|
||||
break;
|
||||
case TerrainType.Path:
|
||||
g.fill(0xff00ff);
|
||||
break;
|
||||
case TerrainType.Buildable:
|
||||
g.stroke(0x00ff00);
|
||||
break;
|
||||
}
|
||||
this.container.addChild(g);
|
||||
this.container.x = this.bounds.x;
|
||||
this.container.y = this.bounds.y;
|
||||
return; // comment to enable debugging
|
||||
const text = new PIXI.Text({
|
||||
text: `${this.row}|${this.column}`,
|
||||
style: new PIXI.TextStyle({
|
||||
@ -48,8 +54,6 @@ export class Cell extends GameObject {
|
||||
text.x = this.bounds.width / 2;
|
||||
text.y = this.bounds.height / 2;
|
||||
if (this.isPath) text.text += 'P';
|
||||
this.container.x = this.bounds.x;
|
||||
this.container.y = this.bounds.y;
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,7 +77,7 @@ export class Grid extends GameObject {
|
||||
type = 1;
|
||||
}
|
||||
const isPath = this.gameMap.paths.some((path) => path.some((p) => p[0] === x && p[1] === y));
|
||||
if (isPath) type = TerrainType.Restricted;
|
||||
if (isPath) type = TerrainType.Path;
|
||||
let cell = new Cell(type, x, y, isPath, this);
|
||||
this.cells.push(cell);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user