Skip to content

Commit

Permalink
Fixed some crazy bugs with shooting and moving
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikketer committed Jul 16, 2024
1 parent 05038a5 commit 12c751b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
4 changes: 4 additions & 0 deletions enemy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,17 @@ class Enemy {

protected attack() {
// Stop moving
console.log("Should stop!")
this.sprite.follow(this._currentTarget.sprite, 0)
this._isAttacking = true
}

protected die() {}

public render() {
// No Undead walking!
if (this.health <= 0 && !this._isAttacking) return

// Check your distance from the target randomly
if ((control.millis() - this._lastDirectionTick) > Militia.directionChangeInterval) {
this._lastDirectionTick = control.millis()
Expand Down
21 changes: 7 additions & 14 deletions militia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ class Militia extends Enemy {
static attackDelayMin: number = 4000
static attackDelayMax: number = 6000

private facing: 'left' | 'right' = 'right'
// private _isParrying: boolean = false

constructor({ x, y, target }: { x: number, y: number, target?: Pirate }) {
super({ x, y, target, sprite: sprites.create(assets.animation`Militia Walk`[0]) })

Expand All @@ -22,26 +19,22 @@ class Militia extends Enemy {
}

public hit(damage: number) {
// if (this._isParrying) {
// music.play(Militia.parrySound, music.PlaybackMode.InBackground)
// return
// }

super.hit(damage)

if (this.health <= 0) {
animation.runImageAnimation(
this.sprite,
this.facing === 'right' ? Militia.deathRightAnimation : Militia.deathLeftAnimation,
this._facing === 'right' ? Militia.deathRightAnimation : Militia.deathLeftAnimation,
100,
false
)
}
}

public render() {
if (this.health <= 0) return

public render() {
// No Undead walking!
if (this.health <= 0 && !this._isAttacking) return

super.render()

// Attack randomly
Expand All @@ -65,7 +58,7 @@ class Militia extends Enemy {
const oldY = this.sprite.y

this.sprite.destroy()
if (this.facing === 'left') {
if (this._facing === 'left') {
this.sprite = sprites.create(assets.image`Militia Broken and Broke Left`)
} else {
this.sprite = sprites.create(assets.image`Militia Broken and Broke`)
Expand Down Expand Up @@ -100,7 +93,7 @@ class Militia extends Enemy {
super.attack()

// Play the fire animation
if (this.facing === 'right') {
if (this._facing === 'right') {
animation.runImageAnimation(
this.sprite,
Militia.attackRightAnimation,
Expand Down

0 comments on commit 12c751b

Please sign in to comment.