feat&fix: added collideWithPlayer to handle collision and fix attack bug
This commit is contained in:
parent
51be51916b
commit
b2adaaa1db
|
@ -63,6 +63,7 @@ export default class EnemyAI extends StateMachineAI implements BattlerAI {
|
|||
bleedStat: Sprite;
|
||||
|
||||
attackTimer : Timer;
|
||||
isAttaking: boolean = false;
|
||||
|
||||
|
||||
initializeAI(owner: AnimatedSprite, options: Record<string, any>): void {
|
||||
|
@ -105,7 +106,10 @@ export default class EnemyAI extends StateMachineAI implements BattlerAI {
|
|||
console.log(damage +" damage taken, "+this.CURRENT_HP+" hp left");
|
||||
this.CURRENT_HP -= damage;
|
||||
//TODO -
|
||||
this.owner.animation.play("HURT",false);
|
||||
if (!this.isAttaking) {
|
||||
this.owner.animation.play("HURT",false);
|
||||
}
|
||||
|
||||
console.log(damage +" damage taken, "+this.CURRENT_HP+" hp left");
|
||||
|
||||
// If health goes below 0, disable AI and fire enemyDied event
|
||||
|
@ -134,6 +138,10 @@ export default class EnemyAI extends StateMachineAI implements BattlerAI {
|
|||
}
|
||||
}
|
||||
|
||||
collideWithPlayer(player: PlayerController): void {
|
||||
player.damage(10);
|
||||
}
|
||||
|
||||
//TODO - need to modify for side view
|
||||
isPlayerVisible(pos: Vec2): Vec2{
|
||||
//Check ifplayer is visible, taking into account walls
|
||||
|
@ -181,9 +189,6 @@ export default class EnemyAI extends StateMachineAI implements BattlerAI {
|
|||
}
|
||||
return pos;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* gets the position of the player
|
||||
|
|
|
@ -9,6 +9,7 @@ export default class Attack extends EnemyState {
|
|||
onEnter(options: Record<string, any>): void {
|
||||
this.parent.attackTimer.start();
|
||||
this.parent.velocity.x = 0;
|
||||
this.parent.isAttaking = true;
|
||||
this.charged = this.owner.id+"charged";
|
||||
this.attacked = this.owner.id+"attacked";
|
||||
|
||||
|
@ -34,6 +35,7 @@ export default class Attack extends EnemyState {
|
|||
}
|
||||
|
||||
onExit(): Record<string, any> {
|
||||
this.parent.isAttaking = false;
|
||||
(<AnimatedSprite>this.owner).animation.stop();
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import EnemyAI, { EnemyStates } from "../EnemyAI";
|
||||
import EnemyState from "./EnemyState";
|
||||
import AnimatedSprite from "../../../Wolfie2D/Nodes/Sprites/AnimatedSprite";
|
||||
import AABB from "../../../Wolfie2D/DataTypes/Shapes/AABB";
|
||||
import Sprite from "../../../Wolfie2D/Nodes/Sprites/Sprite";
|
||||
|
|
|
@ -950,7 +950,7 @@ export default class GameLevel extends Scene {
|
|||
}
|
||||
if(typeof enemy != undefined && typeof player != undefined){
|
||||
//damage the player
|
||||
(<PlayerController>this.player._ai).damage(10); //10 collision dmg for now
|
||||
(<EnemyAI>enemy._ai).collideWithPlayer(<PlayerController>this.player._ai);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user