fix: enemy play walk animation
This commit is contained in:
parent
1726ba3653
commit
94da5fef26
|
@ -54,7 +54,7 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"name": "walk",
|
||||
"name": "WALK",
|
||||
"repeat": true,
|
||||
"frames": [
|
||||
{
|
||||
|
|
|
@ -4,12 +4,11 @@ import Vec2 from "../../Wolfie2D/DataTypes/Vec2";
|
|||
import GameNode from "../../Wolfie2D/Nodes/GameNode";
|
||||
import AnimatedSprite from "../../Wolfie2D/Nodes/Sprites/AnimatedSprite";
|
||||
import OrthogonalTilemap from "../../Wolfie2D/Nodes/Tilemaps/OrthogonalTilemap";
|
||||
import NavigationPath from "../../Wolfie2D/Pathfinding/NavigationPath";
|
||||
import Weapon from "../GameSystems/items/Weapon";
|
||||
import BattlerAI from "./BattlerAI";
|
||||
|
||||
import Patrol from "./EnemyStates/Patrol";
|
||||
import Alert from "./EnemyStates/Alert";
|
||||
import Attack from "./EnemyStates/Attack";
|
||||
import { GameState, Statuses } from "../sword_enums";
|
||||
|
||||
import Sprite from "../../Wolfie2D/Nodes/Sprites/Sprite";
|
||||
|
@ -35,24 +34,12 @@ export default class EnemyAI extends StateMachineAI implements BattlerAI {
|
|||
|
||||
maxSpeed: number = 40;
|
||||
|
||||
/** The weapon this AI has */
|
||||
weapon: Weapon;
|
||||
|
||||
/** A reference to the player object */
|
||||
player: GameNode;
|
||||
|
||||
// The current known position of the player
|
||||
playerPos: Vec2;
|
||||
|
||||
// The last known position of the player
|
||||
lastPlayerPos: Vec2;
|
||||
|
||||
// Path to player
|
||||
//path: NavigationPath;
|
||||
|
||||
// Path away from player
|
||||
retreatPath: NavigationPath;
|
||||
|
||||
tilemap: OrthogonalTilemap;
|
||||
|
||||
velocity: Vec2 = Vec2.ZERO;
|
||||
|
@ -85,13 +72,12 @@ export default class EnemyAI extends StateMachineAI implements BattlerAI {
|
|||
// Patrol mode
|
||||
this.addState(EnemyStates.PATROL, new Patrol(this, owner));
|
||||
this.addState(EnemyStates.ALERT, new Alert(this, owner));
|
||||
this.addState(EnemyStates.ATTACK, new Attack(this, owner));
|
||||
|
||||
this.maxHealth = options.health;
|
||||
|
||||
this.CURRENT_HP = options.health;
|
||||
|
||||
this.weapon = options.weapon;
|
||||
|
||||
this.player = options.player;
|
||||
|
||||
//TODO - get correct tilemap
|
||||
|
@ -190,7 +176,6 @@ export default class EnemyAI extends StateMachineAI implements BattlerAI {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,13 +5,16 @@ 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);
|
||||
(<AnimatedSprite>this.owner).animation.playIfNotAlready("WALK", true);
|
||||
}
|
||||
|
||||
update(deltaT: number): void {
|
||||
let position = this.parent.getPlayerPosition();
|
||||
if (position) {
|
||||
this.parent.velocity.x = this.parent.maxSpeed * Math.sign(position.x - this.owner.position.x);
|
||||
if (this.parent.attackTimer.isStopped()) {
|
||||
this.finished(EnemyStates.ATTACK);
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.parent.velocity.x = 0;
|
||||
|
|
34
src/shattered_sword/AI/EnemyStates/Attack.ts
Normal file
34
src/shattered_sword/AI/EnemyStates/Attack.ts
Normal file
|
@ -0,0 +1,34 @@
|
|||
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("WALK", true);
|
||||
}
|
||||
|
||||
update(deltaT: number): void {
|
||||
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);
|
||||
}
|
||||
|
||||
this.parent.direction = this.parent.velocity.x >= 0 ? 1 : -1;
|
||||
if (!this.canWalk()) {
|
||||
this.parent.velocity.x = 0;
|
||||
}
|
||||
|
||||
(<Sprite>this.owner).invertX = this.parent.direction === 1 ? true : false ;
|
||||
super.update(deltaT);
|
||||
}
|
||||
|
||||
onExit(): Record<string, any> {
|
||||
(<AnimatedSprite>this.owner).animation.stop();
|
||||
return null;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user