feat: implemented alert
This commit is contained in:
parent
7c63a7957b
commit
7478f4bb1f
|
@ -9,6 +9,7 @@ import Weapon from "../GameSystems/items/Weapon";
|
|||
import BattlerAI from "./BattlerAI";
|
||||
|
||||
import Patrol from "./EnemyStates/Patrol";
|
||||
import Alert from "./EnemyStates/Alert";
|
||||
import { GameState, Statuses } from "../sword_enums";
|
||||
|
||||
import Sprite from "../../Wolfie2D/Nodes/Sprites/Sprite";
|
||||
|
@ -32,6 +33,8 @@ export default class EnemyAI extends StateMachineAI implements BattlerAI {
|
|||
/** The default movement speed of this AI */
|
||||
speed: number = 20;
|
||||
|
||||
maxSpeed: number = 40;
|
||||
|
||||
/** The weapon this AI has */
|
||||
weapon: Weapon;
|
||||
|
||||
|
@ -81,7 +84,7 @@ export default class EnemyAI extends StateMachineAI implements BattlerAI {
|
|||
//add states
|
||||
// Patrol mode
|
||||
this.addState(EnemyStates.PATROL, new Patrol(this, owner));
|
||||
// this.addState(EnemyStates.ALERT,)
|
||||
this.addState(EnemyStates.ALERT, new Alert(this, owner));
|
||||
|
||||
this.maxHealth = options.health;
|
||||
|
||||
|
|
33
src/shattered_sword/AI/EnemyStates/Alert.ts
Normal file
33
src/shattered_sword/AI/EnemyStates/Alert.ts
Normal file
|
@ -0,0 +1,33 @@
|
|||
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 Alert extends EnemyState {
|
||||
onEnter(options: Record<string, any>): void {
|
||||
(<AnimatedSprite>this.owner).animation.playIfNotAlready("IDLE", true);
|
||||
}
|
||||
|
||||
update(deltaT: number): void {
|
||||
if(!this.canWalk()){
|
||||
this.parent.direction *= -1;
|
||||
}
|
||||
|
||||
let position = this.parent.getPlayerPosition();
|
||||
if (position) {
|
||||
this.parent.velocity.x = this.parent.maxSpeed * Math.sign(position.x - this.owner.position.x);
|
||||
}
|
||||
else {
|
||||
this.parent.velocity.x = 0;
|
||||
this.finished(EnemyStates.PATROL);
|
||||
}
|
||||
|
||||
(<Sprite>this.owner).invertX = this.parent.velocity.x > 0 ? true : false ;
|
||||
super.update(deltaT);
|
||||
}
|
||||
|
||||
onExit(): Record<string, any> {
|
||||
(<AnimatedSprite>this.owner).animation.stop();
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -24,6 +24,9 @@ export default class Patrol extends EnemyState {
|
|||
this.parent.velocity.x = this.parent.direction * this.parent.speed;
|
||||
(<Sprite>this.owner).invertX = this.parent.direction === 1 ? true : false ;
|
||||
|
||||
if (this.parent.getPlayerPosition()) {
|
||||
this.finished(EnemyStates.ALERT);
|
||||
}
|
||||
super.update(deltaT);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user