Skip to content

Commit

Permalink
Hurt animation
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikketer committed Jul 14, 2024
1 parent 1b64122 commit d428b46
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions pirate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ class Pirate {
parryRightSprite: Image = assets.image`Pirate`
walkRightAnimation: Image[] = assets.animation`Pirate Walk`
walkLeftAnimation: Image[] = Utils.flipAnimation(assets.animation`Pirate Walk`)
hurtRightAnimation: Image[] = assets.animation`Pirate Hurt`
hurtLeftAnimation: Image[] = Utils.flipAnimation(assets.animation`Pirate Hurt`)

sprite: Sprite
facing: 'left' | 'right'
controller: controller.Controller
isAttacking?: 'left' | 'right'
isGettingHurt?: boolean = false
isParrying?: 'left' | 'right'
_topBoundary: number = 0
_lastAttackTick: number = 0
Expand Down Expand Up @@ -100,7 +103,7 @@ class Pirate {
}

public render() {
if (!this.isAttacking) {
if (!this.isAttacking && !this.isGettingHurt) {
this.sprite.x += this.controller.dx(50)
this.sprite.y += this.controller.dy(50)
}
Expand All @@ -118,10 +121,25 @@ class Pirate {
return
}

scene.cameraShake(2, 500)
this.health -= damage
this.isGettingHurt = true

if (this.health > 0) {
animation.runImageAnimation(
this.sprite,
this.facing === 'right' ? this.hurtRightAnimation : this.hurtLeftAnimation,
200,
false
)
setTimeout(() => {
this.isGettingHurt = false
}, this.hurtLeftAnimation.length * 200)
} else {
// You dead!
}

scene.cameraShake(2, 500)
this._updateStats()
// Add death!
}

parry() {
Expand Down Expand Up @@ -200,6 +218,8 @@ class Pirate {
Utils.swapAnimationColors(this.attackRightAnimation, 14, toColor)
Utils.swapAnimationColors(this.walkRightAnimation, 14, toColor)
Utils.swapAnimationColors(this.walkLeftAnimation, 14, toColor)
Utils.swapAnimationColors(this.hurtRightAnimation, 14, toColor)
Utils.swapAnimationColors(this.hurtLeftAnimation, 14, toColor)
}

_setupAnimations() {
Expand Down

0 comments on commit d428b46

Please sign in to comment.