added enemy killing

This commit is contained in:
OfficialCHenry 2022-04-10 21:32:22 -04:00
parent d9b81428f4
commit 1b3946f56c
6 changed files with 41 additions and 8 deletions

View File

@ -7,7 +7,7 @@
"displayName": "Knife", "displayName": "Knife",
"animationSprite": "slice", "animationSprite": "slice",
"spriteKey": "knife", "spriteKey": "knife",
"damage": 1, "damage": 50,
"cooldown": 3, "cooldown": 3,
"useVolume": 0 "useVolume": 0
} }

View File

@ -25,9 +25,9 @@
}, },
{ {
"name": "HURT", "name": "HURT",
"frames": [ {"index": 0, "duration": 250}, "frames": [ {"index": 0, "duration": 1},
{"index": 1, "duration": 500}, {"index": 1, "duration": 50},
{"index": 0, "duration": 250} ] {"index": 0, "duration": 25} ]
} }
] ]
} }

View File

@ -20,6 +20,8 @@ import { Statuses } from "../sword_enums";
import Sprite from "../../Wolfie2D/Nodes/Sprites/Sprite"; import Sprite from "../../Wolfie2D/Nodes/Sprites/Sprite";
import MathUtils from "../../Wolfie2D/Utils/MathUtils"; import MathUtils from "../../Wolfie2D/Utils/MathUtils";
import { Player_Events } from "../sword_enums";
export default class EnemyAI extends StateMachineGoapAI implements BattlerAI { export default class EnemyAI extends StateMachineGoapAI implements BattlerAI {
/** The owner of this AI */ /** The owner of this AI */
owner: AnimatedSprite; owner: AnimatedSprite;
@ -105,6 +107,9 @@ export default class EnemyAI extends StateMachineGoapAI implements BattlerAI {
damage(damage: number): void { damage(damage: number): void {
this.CURRENT_HP -= damage; this.CURRENT_HP -= damage;
//TODO -
this.owner.animation.play("HURT");
console.log(damage +" damage taken, "+this.CURRENT_HP+" hp left");
// If we're low enough, add Low Health status to enemy // If we're low enough, add Low Health status to enemy
if (this.CURRENT_HP <= Math.floor(this.maxHealth/2)) { if (this.CURRENT_HP <= Math.floor(this.maxHealth/2)) {
@ -117,7 +122,7 @@ export default class EnemyAI extends StateMachineGoapAI implements BattlerAI {
this.owner.isCollidable = false; this.owner.isCollidable = false;
this.owner.visible = false; this.owner.visible = false;
this.emitter.fireEvent("enemyDied", {enemy: this.owner}) this.emitter.fireEvent(Player_Events.ENEMY_KILLED, {owner: this.owner.id, ai:this});
if (Math.random() < 0.05) { if (Math.random() < 0.05) {

View File

@ -8,6 +8,7 @@ import EnemyState from "./EnemyState";
import Sprite from "../../../Wolfie2D/Nodes/Sprites/Sprite"; import Sprite from "../../../Wolfie2D/Nodes/Sprites/Sprite";
import MathUtils from "../../../Wolfie2D/Utils/MathUtils"; import MathUtils from "../../../Wolfie2D/Utils/MathUtils";
import OnGround from "./OnGround"; import OnGround from "./OnGround";
import AnimatedSprite from "../../../Wolfie2D/Nodes/Sprites/AnimatedSprite";
export default class Patrol extends EnemyState { export default class Patrol extends EnemyState {
@ -23,6 +24,7 @@ export default class Patrol extends EnemyState {
onEnter(options: Record<string, any>): void { onEnter(options: Record<string, any>): void {
//this.currentPath = this.getNextPath(); //this.currentPath = this.getNextPath();
(<AnimatedSprite>this.owner).animation.play("IDLE", true);
} }
handleInput(event: GameEvent): void { } handleInput(event: GameEvent): void { }
@ -36,7 +38,7 @@ export default class Patrol extends EnemyState {
//check if next tile on walking path is collidable //check if next tile on walking path is collidable
if(this.parent.tilemap.isTileCollidable(colrow.x+this.parent.direction,colrow.y)){ if(this.parent.tilemap.isTileCollidable(colrow.x+this.parent.direction,colrow.y)){
//turn around //turn around
console.log(this.parent.tilemap.getTileAtRowCol(colrow)); //console.log(this.parent.tilemap.getTileAtRowCol(colrow));
this.parent.direction *= -1; this.parent.direction *= -1;
(<Sprite>this.owner).invertX = MathUtils.sign(1) < 0; (<Sprite>this.owner).invertX = MathUtils.sign(1) < 0;
//console.log("turn around cus wall in front"); //console.log("turn around cus wall in front");

View File

@ -18,7 +18,8 @@ export default class BattleManager {
for (let enemy of this.enemies) { for (let enemy of this.enemies) {
if (weapon.hits(enemy.owner)) { if (weapon.hits(enemy.owner)) {
enemy.damage(weapon.type.damage); enemy.damage(weapon.type.damage);
console.log("enemy took dmg");
//console.log("enemy took dmg");
} }
} }
} }
@ -45,4 +46,15 @@ export default class BattleManager {
addEnemy(enemy : BattlerAI){ addEnemy(enemy : BattlerAI){
this.enemies.push(enemy); this.enemies.push(enemy);
} }
removeEnemy(enemy : BattlerAI){
this.enemies = this.enemies.filter(item => item !== enemy)
if(this.enemies.length == 0){
this.enemies = new Array();
}
return this.enemies;
}
} }

View File

@ -161,6 +161,17 @@ export default class GameLevel extends Scene {
let event = this.receiver.getNextEvent(); let event = this.receiver.getNextEvent();
switch(event.type){ switch(event.type){
case Player_Events.ENEMY_KILLED:
let node = this.sceneGraph.getNode(event.data.get("owner"));//get enemy id
//remove enemy from enemies
this.enemies = this.enemies.filter(item => item !== event.data.get("ai"));
this.battleManager.removeEnemy(event.data.get("ai"));
console.log("enemy destroyed");
node.destroy();
break;
} }
} }
@ -191,6 +202,8 @@ export default class GameLevel extends Scene {
}); });
} }
} }
/** /**
@ -398,7 +411,8 @@ export default class GameLevel extends Scene {
//add enemy to the enemy array //add enemy to the enemy array
this.enemies.push(enemy); this.enemies.push(enemy);
this.battleManager.setEnemies(this.enemies.map(enemy => <BattlerAI>enemy._ai)); //this.battleManager.setEnemies(this.enemies.map(enemy => <BattlerAI>enemy._ai));
this.battleManager.addEnemy(<BattlerAI>enemy._ai);
} }