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;
|
bleedStat: Sprite;
|
||||||
|
|
||||||
attackTimer : Timer;
|
attackTimer : Timer;
|
||||||
|
isAttaking: boolean = false;
|
||||||
|
|
||||||
|
|
||||||
initializeAI(owner: AnimatedSprite, options: Record<string, any>): void {
|
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");
|
console.log(damage +" damage taken, "+this.CURRENT_HP+" hp left");
|
||||||
this.CURRENT_HP -= damage;
|
this.CURRENT_HP -= damage;
|
||||||
//TODO -
|
//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");
|
console.log(damage +" damage taken, "+this.CURRENT_HP+" hp left");
|
||||||
|
|
||||||
// If health goes below 0, disable AI and fire enemyDied event
|
// 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
|
//TODO - need to modify for side view
|
||||||
isPlayerVisible(pos: Vec2): Vec2{
|
isPlayerVisible(pos: Vec2): Vec2{
|
||||||
//Check ifplayer is visible, taking into account walls
|
//Check ifplayer is visible, taking into account walls
|
||||||
|
@ -182,9 +190,6 @@ export default class EnemyAI extends StateMachineAI implements BattlerAI {
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gets the position of the player
|
* gets the position of the player
|
||||||
* @returns position of the player if visible, else null
|
* @returns position of the player if visible, else null
|
||||||
|
|
|
@ -9,6 +9,7 @@ export default class Attack extends EnemyState {
|
||||||
onEnter(options: Record<string, any>): void {
|
onEnter(options: Record<string, any>): void {
|
||||||
this.parent.attackTimer.start();
|
this.parent.attackTimer.start();
|
||||||
this.parent.velocity.x = 0;
|
this.parent.velocity.x = 0;
|
||||||
|
this.parent.isAttaking = true;
|
||||||
this.charged = this.owner.id+"charged";
|
this.charged = this.owner.id+"charged";
|
||||||
this.attacked = this.owner.id+"attacked";
|
this.attacked = this.owner.id+"attacked";
|
||||||
|
|
||||||
|
@ -34,6 +35,7 @@ export default class Attack extends EnemyState {
|
||||||
}
|
}
|
||||||
|
|
||||||
onExit(): Record<string, any> {
|
onExit(): Record<string, any> {
|
||||||
|
this.parent.isAttaking = false;
|
||||||
(<AnimatedSprite>this.owner).animation.stop();
|
(<AnimatedSprite>this.owner).animation.stop();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import EnemyAI, { EnemyStates } from "../EnemyAI";
|
import EnemyAI, { EnemyStates } from "../EnemyAI";
|
||||||
import EnemyState from "./EnemyState";
|
|
||||||
import AnimatedSprite from "../../../Wolfie2D/Nodes/Sprites/AnimatedSprite";
|
import AnimatedSprite from "../../../Wolfie2D/Nodes/Sprites/AnimatedSprite";
|
||||||
import AABB from "../../../Wolfie2D/DataTypes/Shapes/AABB";
|
import AABB from "../../../Wolfie2D/DataTypes/Shapes/AABB";
|
||||||
import Sprite from "../../../Wolfie2D/Nodes/Sprites/Sprite";
|
import Sprite from "../../../Wolfie2D/Nodes/Sprites/Sprite";
|
||||||
|
|
|
@ -950,7 +950,7 @@ export default class GameLevel extends Scene {
|
||||||
}
|
}
|
||||||
if(typeof enemy != undefined && typeof player != undefined){
|
if(typeof enemy != undefined && typeof player != undefined){
|
||||||
//damage the player
|
//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