From 4b8c7a0bf90a044d0d5acc294fd8ec2c3be07ee3 Mon Sep 17 00:00:00 2001 From: OfficialCHenry Date: Mon, 9 May 2022 14:46:09 -0400 Subject: [PATCH] locked archer direction, changed boss hitbox --- src/shattered_sword/AI/BossAI.ts | 43 ++++++++++++++++++- .../AI/EnemyStates/ArcherAttack.ts | 8 ++-- src/shattered_sword/Scenes/GameFinish.ts | 2 +- src/shattered_sword/Scenes/GameLevel.ts | 4 +- 4 files changed, 50 insertions(+), 7 deletions(-) diff --git a/src/shattered_sword/AI/BossAI.ts b/src/shattered_sword/AI/BossAI.ts index 7afa02e..f679e25 100644 --- a/src/shattered_sword/AI/BossAI.ts +++ b/src/shattered_sword/AI/BossAI.ts @@ -3,7 +3,7 @@ import EnemyAI, { EnemyStates } from "./EnemyAI"; import BossAttack from "./EnemyStates/BossAttack"; import Weapon from "../GameSystems/items/Weapon"; import Vec2 from "../../Wolfie2D/DataTypes/Vec2"; - +import { Player_Events } from "../sword_enums"; export default class BossAI extends EnemyAI { @@ -19,4 +19,45 @@ export default class BossAI extends EnemyAI { canAttack(position: Vec2): boolean { return this.attackTimer.isStopped() && this.owner.position.distanceTo(position)<=128; } + + damage(damage: number): void { + // enemy already dead, do not send new event + if (this.CURRENT_HP <= 0) { + return; + } + //console.log(damage +" damage taken, "+this.CURRENT_HP+" hp left"); + this.CURRENT_HP -= damage; + //TODO - + if (!this.isAttacking && !this.isCharging) { + this.owner.animation.play("HURT",false); + } + + //console.log(damage +" damage taken, "+this.CURRENT_HP+" hp left"); + + // If health goes below 0, disable AI and fire enemyDied event + if (this.CURRENT_HP <= 0) { + this.owner.setAIActive(false, {}); + this.owner.isCollidable = false; + this.owner.visible = false; + if (this.healthBar) { + this.healthBar.destroy(); + this.healthBar = undefined; + } + if (this.poisonStat) { + this.poisonStat.destroy(); + this.poisonStat = undefined; + } + if (this.burnStat) { + this.burnStat.destroy(); + this.burnStat = undefined; + } + if (this.bleedStat) { + this.bleedStat.destroy(); + this.bleedStat = undefined; + } + + this.emitter.fireEvent("nextLevel", {owner: this.owner.id, ai:this}); + } + this.damageTimer.start(); + } } \ No newline at end of file diff --git a/src/shattered_sword/AI/EnemyStates/ArcherAttack.ts b/src/shattered_sword/AI/EnemyStates/ArcherAttack.ts index 3ccc131..6129732 100644 --- a/src/shattered_sword/AI/EnemyStates/ArcherAttack.ts +++ b/src/shattered_sword/AI/EnemyStates/ArcherAttack.ts @@ -4,23 +4,25 @@ import Attack from "./Attack"; import ArcherAI from "../ArcherAI"; import Sprite from "../../../Wolfie2D/Nodes/Sprites/Sprite"; import Timer from "../../../Wolfie2D/Timing/Timer"; +import Vec2 from "../../../Wolfie2D/DataTypes/Vec2"; //TODO - unfinished export default class ArcherAttack extends Attack { pauseTimer : Timer; + dir :Vec2; onEnter(options: Record): void { super.onEnter(options); this.pauseTimer = new Timer(1000); this.pauseTimer.start(); + this.dir = this.parent.getPlayerPosition().clone().sub(this.owner.position).normalize(); + this.parent.direction = this.parent.getPlayerPosition().x - this.owner.position.x >= 0 ? 1 : -1; } update(deltaT: number): void { if(this.pauseTimer.isStopped()){ - this.parent.direction = this.parent.getPlayerPosition().x - this.owner.position.x >= 0 ? 1 : -1; - let dir = this.parent.getPlayerPosition().clone().sub(this.owner.position).normalize(); - (this.parent).weapon.use(this.owner, "enemy", dir.scale(1,0)); + (this.parent).weapon.use(this.owner, "enemy", this.dir.scale(1,0)); (this.owner).invertX = this.parent.direction === 1 ? true : false ; this.finished(EnemyStates.ALERT); } diff --git a/src/shattered_sword/Scenes/GameFinish.ts b/src/shattered_sword/Scenes/GameFinish.ts index eccfb16..a7116e5 100644 --- a/src/shattered_sword/Scenes/GameFinish.ts +++ b/src/shattered_sword/Scenes/GameFinish.ts @@ -17,7 +17,7 @@ export default class GameFinish extends Scene { this.addUILayer("primary"); - const congra =