diff --git a/dist/shattered_sword_assets/spritesheets/Snake.json b/dist/shattered_sword_assets/spritesheets/Snake.json index a0fc037..718adcb 100644 --- a/dist/shattered_sword_assets/spritesheets/Snake.json +++ b/dist/shattered_sword_assets/spritesheets/Snake.json @@ -81,7 +81,7 @@ }, { "name": "ATTACK", - "repeat": true, + "repeat": false, "frames": [ { "index": 0, diff --git a/src/shattered_sword/AI/EnemyStates/Alert.ts b/src/shattered_sword/AI/EnemyStates/Alert.ts index 6da893e..16d6e44 100644 --- a/src/shattered_sword/AI/EnemyStates/Alert.ts +++ b/src/shattered_sword/AI/EnemyStates/Alert.ts @@ -12,7 +12,7 @@ export default class Alert extends EnemyState { 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()) { + if (this.parent.attackTimer.isStopped() && this.owner.position.distanceTo(position)<=32) { this.finished(EnemyStates.ATTACK); } } diff --git a/src/shattered_sword/AI/EnemyStates/Attack.ts b/src/shattered_sword/AI/EnemyStates/Attack.ts index c734ef2..cfd7203 100644 --- a/src/shattered_sword/AI/EnemyStates/Attack.ts +++ b/src/shattered_sword/AI/EnemyStates/Attack.ts @@ -8,31 +8,27 @@ export default class Attack extends EnemyState { protected attacked: string; onEnter(options: Record): void { - let event = this.owner.id+"charged"; - (this.owner).animation.play("DYING", false, event); - this.receiver.subscribe(event); + this.parent.attackTimer.start(); + this.parent.velocity.x = 0; + this.charged = this.owner.id+"charged"; + this.attacked = this.owner.id+"attacked"; + (this.owner).animation.play("DYING", false, this.charged); + this.receiver.subscribe(this.charged); + this.receiver.subscribe(this.attacked); } update(deltaT: number): void { while (this.receiver.hasNextEvent()) { - this.receiver.getNextEvent(); - + let event = this.receiver.getNextEvent().type; + switch (event) { + case this.charged: + (this.owner).animation.play("ATTACK", false, this.attacked); + break; + case this.attacked: + this.finished(EnemyStates.ALERT); + break; + } } - 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); }