added enemy killing
This commit is contained in:
parent
d9b81428f4
commit
1b3946f56c
|
@ -7,7 +7,7 @@
|
|||
"displayName": "Knife",
|
||||
"animationSprite": "slice",
|
||||
"spriteKey": "knife",
|
||||
"damage": 1,
|
||||
"damage": 50,
|
||||
"cooldown": 3,
|
||||
"useVolume": 0
|
||||
}
|
||||
|
|
|
@ -25,9 +25,9 @@
|
|||
},
|
||||
{
|
||||
"name": "HURT",
|
||||
"frames": [ {"index": 0, "duration": 250},
|
||||
{"index": 1, "duration": 500},
|
||||
{"index": 0, "duration": 250} ]
|
||||
"frames": [ {"index": 0, "duration": 1},
|
||||
{"index": 1, "duration": 50},
|
||||
{"index": 0, "duration": 25} ]
|
||||
}
|
||||
]
|
||||
}
|
|
@ -20,6 +20,8 @@ import { Statuses } from "../sword_enums";
|
|||
import Sprite from "../../Wolfie2D/Nodes/Sprites/Sprite";
|
||||
|
||||
import MathUtils from "../../Wolfie2D/Utils/MathUtils";
|
||||
|
||||
import { Player_Events } from "../sword_enums";
|
||||
export default class EnemyAI extends StateMachineGoapAI implements BattlerAI {
|
||||
/** The owner of this AI */
|
||||
owner: AnimatedSprite;
|
||||
|
@ -105,6 +107,9 @@ export default class EnemyAI extends StateMachineGoapAI implements BattlerAI {
|
|||
|
||||
damage(damage: number): void {
|
||||
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 (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.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) {
|
||||
|
|
|
@ -8,6 +8,7 @@ import EnemyState from "./EnemyState";
|
|||
import Sprite from "../../../Wolfie2D/Nodes/Sprites/Sprite";
|
||||
import MathUtils from "../../../Wolfie2D/Utils/MathUtils";
|
||||
import OnGround from "./OnGround";
|
||||
import AnimatedSprite from "../../../Wolfie2D/Nodes/Sprites/AnimatedSprite";
|
||||
|
||||
export default class Patrol extends EnemyState {
|
||||
|
||||
|
@ -23,6 +24,7 @@ export default class Patrol extends EnemyState {
|
|||
|
||||
onEnter(options: Record<string, any>): void {
|
||||
//this.currentPath = this.getNextPath();
|
||||
(<AnimatedSprite>this.owner).animation.play("IDLE", true);
|
||||
}
|
||||
|
||||
handleInput(event: GameEvent): void { }
|
||||
|
@ -36,7 +38,7 @@ export default class Patrol extends EnemyState {
|
|||
//check if next tile on walking path is collidable
|
||||
if(this.parent.tilemap.isTileCollidable(colrow.x+this.parent.direction,colrow.y)){
|
||||
//turn around
|
||||
console.log(this.parent.tilemap.getTileAtRowCol(colrow));
|
||||
//console.log(this.parent.tilemap.getTileAtRowCol(colrow));
|
||||
this.parent.direction *= -1;
|
||||
(<Sprite>this.owner).invertX = MathUtils.sign(1) < 0;
|
||||
//console.log("turn around cus wall in front");
|
||||
|
|
|
@ -18,7 +18,8 @@ export default class BattleManager {
|
|||
for (let enemy of this.enemies) {
|
||||
if (weapon.hits(enemy.owner)) {
|
||||
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){
|
||||
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;
|
||||
|
||||
}
|
||||
}
|
|
@ -161,6 +161,17 @@ export default class GameLevel extends Scene {
|
|||
let event = this.receiver.getNextEvent();
|
||||
|
||||
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
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user