feat: add type to addEnemy
This commit is contained in:
parent
6f4bbeb885
commit
50b3b4a7d7
|
@ -80,6 +80,8 @@ export default class EnemyAI extends StateMachineAI implements BattlerAI {
|
||||||
|
|
||||||
this.player = options.player;
|
this.player = options.player;
|
||||||
|
|
||||||
|
this.exp_val = options.exp;
|
||||||
|
|
||||||
//TODO - get correct tilemap
|
//TODO - get correct tilemap
|
||||||
this.tilemap = <OrthogonalTilemap>this.owner.getScene().getLayer("Wall").getItems()[0];
|
this.tilemap = <OrthogonalTilemap>this.owner.getScene().getLayer("Wall").getItems()[0];
|
||||||
// Initialize to the default state
|
// Initialize to the default state
|
||||||
|
@ -87,9 +89,6 @@ export default class EnemyAI extends StateMachineAI implements BattlerAI {
|
||||||
|
|
||||||
this.direction = 1; //default moving to the right
|
this.direction = 1; //default moving to the right
|
||||||
|
|
||||||
//exp value
|
|
||||||
this.exp_val = options.exp;
|
|
||||||
|
|
||||||
//TODO - dots every 1 sec? can change
|
//TODO - dots every 1 sec? can change
|
||||||
this.burnTimer = new Timer(1000);
|
this.burnTimer = new Timer(1000);
|
||||||
this.bleedTimer = new Timer(1000);
|
this.bleedTimer = new Timer(1000);
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import EnemyAI, { EnemyStates } from "../EnemyAI";
|
import EnemyAI, { EnemyStates } from "../EnemyAI";
|
||||||
import EnemyState from "./EnemyState";
|
import EnemyState from "./EnemyState";
|
||||||
import Sprite from "../../../Wolfie2D/Nodes/Sprites/Sprite";
|
|
||||||
import AnimatedSprite from "../../../Wolfie2D/Nodes/Sprites/AnimatedSprite";
|
import AnimatedSprite from "../../../Wolfie2D/Nodes/Sprites/AnimatedSprite";
|
||||||
|
|
||||||
export default class Attack extends EnemyState {
|
export default class Attack extends EnemyState {
|
||||||
|
@ -12,6 +11,8 @@ export default class Attack extends EnemyState {
|
||||||
this.parent.velocity.x = 0;
|
this.parent.velocity.x = 0;
|
||||||
this.charged = this.owner.id+"charged";
|
this.charged = this.owner.id+"charged";
|
||||||
this.attacked = this.owner.id+"attacked";
|
this.attacked = this.owner.id+"attacked";
|
||||||
|
|
||||||
|
// TODO replace DYING with CHARGING
|
||||||
(<AnimatedSprite>this.owner).animation.play("DYING", false, this.charged);
|
(<AnimatedSprite>this.owner).animation.play("DYING", false, this.charged);
|
||||||
this.receiver.subscribe(this.charged);
|
this.receiver.subscribe(this.charged);
|
||||||
this.receiver.subscribe(this.attacked);
|
this.receiver.subscribe(this.attacked);
|
||||||
|
|
|
@ -822,7 +822,7 @@ export default class GameLevel extends Scene {
|
||||||
* @param aiOptions The options for the Enemy AI
|
* @param aiOptions The options for the Enemy AI
|
||||||
*/
|
*/
|
||||||
|
|
||||||
protected addEnemy(spriteKey: string, tilePos: Vec2, aiOptions: Record<string, any>): void {
|
protected addEnemy<T extends EnemyAI>(spriteKey: string, tilePos: Vec2, ai: new() => T, aiOptions: Record<string, any>): void {
|
||||||
let enemy = this.add.animatedSprite(spriteKey, "primary");
|
let enemy = this.add.animatedSprite(spriteKey, "primary");
|
||||||
//enemy.position.set(tilePos.x*32, tilePos.y*32);
|
//enemy.position.set(tilePos.x*32, tilePos.y*32);
|
||||||
enemy.position.copy(tilePos);
|
enemy.position.copy(tilePos);
|
||||||
|
@ -849,7 +849,7 @@ export default class GameLevel extends Scene {
|
||||||
enemy.colliderOffset.set(0, 6);
|
enemy.colliderOffset.set(0, 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
enemy.addAI(EnemyAI, aiOptions); //TODO - add individual enemy AI
|
enemy.addAI(ai, aiOptions); //TODO - add individual enemy AI
|
||||||
(<EnemyAI>enemy._ai).healthBar = <Rect>this.add.graphic(GraphicType.RECT, "primary", {position: enemy.collisionShape.center.clone().add(new Vec2(0, -((<AABB>enemy.collisionShape).hh+5))), size: new Vec2((<AABB>enemy.collisionShape).hw*3, 5)});
|
(<EnemyAI>enemy._ai).healthBar = <Rect>this.add.graphic(GraphicType.RECT, "primary", {position: enemy.collisionShape.center.clone().add(new Vec2(0, -((<AABB>enemy.collisionShape).hh+5))), size: new Vec2((<AABB>enemy.collisionShape).hw*3, 5)});
|
||||||
(<EnemyAI>enemy._ai).healthBar.borderColor = Color.BLACK;
|
(<EnemyAI>enemy._ai).healthBar.borderColor = Color.BLACK;
|
||||||
(<EnemyAI>enemy._ai).healthBar.borderWidth = 1;
|
(<EnemyAI>enemy._ai).healthBar.borderWidth = 1;
|
||||||
|
@ -878,11 +878,10 @@ export default class GameLevel extends Scene {
|
||||||
for (let enemy of enemies) {
|
for (let enemy of enemies) {
|
||||||
switch (enemy.type) {
|
switch (enemy.type) {
|
||||||
case "Snake": //Snake enemies drop from sky("trees")? or could just be very abundant
|
case "Snake": //Snake enemies drop from sky("trees")? or could just be very abundant
|
||||||
this.addEnemy("Snake", enemy.position.scale(32), {
|
this.addEnemy("Snake", enemy.position.scale(32), EnemyAI, {
|
||||||
player: this.player,
|
player: this.player,
|
||||||
health: 50,
|
health: 50,
|
||||||
tilemap: "Main",
|
tilemap: "Main",
|
||||||
goal: Statuses.REACHED_GOAL,
|
|
||||||
size: new Vec2(14,10),
|
size: new Vec2(14,10),
|
||||||
offset : new Vec2(0, 22),
|
offset : new Vec2(0, 22),
|
||||||
exp: 50,
|
exp: 50,
|
||||||
|
@ -890,7 +889,7 @@ export default class GameLevel extends Scene {
|
||||||
})
|
})
|
||||||
break;
|
break;
|
||||||
case "Tiger": //Tiger can be miniboss for now?
|
case "Tiger": //Tiger can be miniboss for now?
|
||||||
this.addEnemy("Tiger", enemy.position.scale(32), {
|
this.addEnemy("Tiger", enemy.position.scale(32), EnemyAI, {
|
||||||
player: this.player,
|
player: this.player,
|
||||||
health: 200,
|
health: 200,
|
||||||
tilemap: "Main",
|
tilemap: "Main",
|
||||||
|
@ -900,7 +899,7 @@ export default class GameLevel extends Scene {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "remus_werewolf":
|
case "remus_werewolf":
|
||||||
this.addEnemy("remus_werewolf", enemy.position.scale(32), {
|
this.addEnemy("remus_werewolf", enemy.position.scale(32), EnemyAI, {
|
||||||
player: this.player,
|
player: this.player,
|
||||||
health: 200,
|
health: 200,
|
||||||
tilemap: "Main",
|
tilemap: "Main",
|
||||||
|
@ -910,7 +909,7 @@ export default class GameLevel extends Scene {
|
||||||
})
|
})
|
||||||
break;
|
break;
|
||||||
case "black_pudding":
|
case "black_pudding":
|
||||||
this.addEnemy("black_pudding", enemy.position.scale(32), {
|
this.addEnemy("black_pudding", enemy.position.scale(32), EnemyAI, {
|
||||||
player: this.player,
|
player: this.player,
|
||||||
health: 200,
|
health: 200,
|
||||||
tilemap: "Main",
|
tilemap: "Main",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user