From 50b3b4a7d71998547eff301f42af6d0ccfa0e87c Mon Sep 17 00:00:00 2001 From: Renge Date: Sun, 24 Apr 2022 21:45:40 -0400 Subject: [PATCH] feat: add type to addEnemy --- src/shattered_sword/AI/EnemyAI.ts | 5 ++--- src/shattered_sword/AI/EnemyStates/Attack.ts | 3 ++- src/shattered_sword/Scenes/GameLevel.ts | 13 ++++++------- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/shattered_sword/AI/EnemyAI.ts b/src/shattered_sword/AI/EnemyAI.ts index 9758c9e..bd33645 100644 --- a/src/shattered_sword/AI/EnemyAI.ts +++ b/src/shattered_sword/AI/EnemyAI.ts @@ -80,6 +80,8 @@ export default class EnemyAI extends StateMachineAI implements BattlerAI { this.player = options.player; + this.exp_val = options.exp; + //TODO - get correct tilemap this.tilemap = this.owner.getScene().getLayer("Wall").getItems()[0]; // 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 - //exp value - this.exp_val = options.exp; - //TODO - dots every 1 sec? can change this.burnTimer = new Timer(1000); this.bleedTimer = new Timer(1000); diff --git a/src/shattered_sword/AI/EnemyStates/Attack.ts b/src/shattered_sword/AI/EnemyStates/Attack.ts index cfd7203..e1cd3ef 100644 --- a/src/shattered_sword/AI/EnemyStates/Attack.ts +++ b/src/shattered_sword/AI/EnemyStates/Attack.ts @@ -1,6 +1,5 @@ import EnemyAI, { EnemyStates } from "../EnemyAI"; import EnemyState from "./EnemyState"; -import Sprite from "../../../Wolfie2D/Nodes/Sprites/Sprite"; import AnimatedSprite from "../../../Wolfie2D/Nodes/Sprites/AnimatedSprite"; export default class Attack extends EnemyState { @@ -12,6 +11,8 @@ export default class Attack extends EnemyState { this.parent.velocity.x = 0; this.charged = this.owner.id+"charged"; this.attacked = this.owner.id+"attacked"; + + // TODO replace DYING with CHARGING (this.owner).animation.play("DYING", false, this.charged); this.receiver.subscribe(this.charged); this.receiver.subscribe(this.attacked); diff --git a/src/shattered_sword/Scenes/GameLevel.ts b/src/shattered_sword/Scenes/GameLevel.ts index 7f24f6e..fa0a9a1 100644 --- a/src/shattered_sword/Scenes/GameLevel.ts +++ b/src/shattered_sword/Scenes/GameLevel.ts @@ -822,7 +822,7 @@ export default class GameLevel extends Scene { * @param aiOptions The options for the Enemy AI */ - protected addEnemy(spriteKey: string, tilePos: Vec2, aiOptions: Record): void { + protected addEnemy(spriteKey: string, tilePos: Vec2, ai: new() => T, aiOptions: Record): void { let enemy = this.add.animatedSprite(spriteKey, "primary"); //enemy.position.set(tilePos.x*32, tilePos.y*32); enemy.position.copy(tilePos); @@ -849,7 +849,7 @@ export default class GameLevel extends Scene { enemy.colliderOffset.set(0, 6); } - enemy.addAI(EnemyAI, aiOptions); //TODO - add individual enemy AI + enemy.addAI(ai, aiOptions); //TODO - add individual enemy AI (enemy._ai).healthBar = this.add.graphic(GraphicType.RECT, "primary", {position: enemy.collisionShape.center.clone().add(new Vec2(0, -((enemy.collisionShape).hh+5))), size: new Vec2((enemy.collisionShape).hw*3, 5)}); (enemy._ai).healthBar.borderColor = Color.BLACK; (enemy._ai).healthBar.borderWidth = 1; @@ -878,11 +878,10 @@ export default class GameLevel extends Scene { for (let enemy of enemies) { switch (enemy.type) { 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, health: 50, tilemap: "Main", - goal: Statuses.REACHED_GOAL, size: new Vec2(14,10), offset : new Vec2(0, 22), exp: 50, @@ -890,7 +889,7 @@ export default class GameLevel extends Scene { }) break; 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, health: 200, tilemap: "Main", @@ -900,7 +899,7 @@ export default class GameLevel extends Scene { break; case "remus_werewolf": - this.addEnemy("remus_werewolf", enemy.position.scale(32), { + this.addEnemy("remus_werewolf", enemy.position.scale(32), EnemyAI, { player: this.player, health: 200, tilemap: "Main", @@ -910,7 +909,7 @@ export default class GameLevel extends Scene { }) break; case "black_pudding": - this.addEnemy("black_pudding", enemy.position.scale(32), { + this.addEnemy("black_pudding", enemy.position.scale(32), EnemyAI, { player: this.player, health: 200, tilemap: "Main",