diff --git a/dist/shattered_sword_assets/spritesheets/Snake.json b/dist/shattered_sword_assets/spritesheets/Snake.json index b5d963e..a0fc037 100644 --- a/dist/shattered_sword_assets/spritesheets/Snake.json +++ b/dist/shattered_sword_assets/spritesheets/Snake.json @@ -54,7 +54,7 @@ ] }, { - "name": "walk", + "name": "WALK", "repeat": true, "frames": [ { diff --git a/src/shattered_sword/AI/EnemyAI.ts b/src/shattered_sword/AI/EnemyAI.ts index f5abf37..1afad16 100644 --- a/src/shattered_sword/AI/EnemyAI.ts +++ b/src/shattered_sword/AI/EnemyAI.ts @@ -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; } diff --git a/src/shattered_sword/AI/EnemyStates/Alert.ts b/src/shattered_sword/AI/EnemyStates/Alert.ts index 1266c4e..6da893e 100644 --- a/src/shattered_sword/AI/EnemyStates/Alert.ts +++ b/src/shattered_sword/AI/EnemyStates/Alert.ts @@ -5,13 +5,16 @@ import AnimatedSprite from "../../../Wolfie2D/Nodes/Sprites/AnimatedSprite"; export default class Alert extends EnemyState { onEnter(options: Record): void { - (this.owner).animation.playIfNotAlready("IDLE", true); + (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; diff --git a/src/shattered_sword/AI/EnemyStates/Attack.ts b/src/shattered_sword/AI/EnemyStates/Attack.ts new file mode 100644 index 0000000..ee667fc --- /dev/null +++ b/src/shattered_sword/AI/EnemyStates/Attack.ts @@ -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): void { + (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; + } + + (this.owner).invertX = this.parent.direction === 1 ? true : false ; + super.update(deltaT); + } + + onExit(): Record { + (this.owner).animation.stop(); + return null; + } +} \ No newline at end of file