From eba479d9b5402e2fdc88c007de7c1e9aeabd8561 Mon Sep 17 00:00:00 2001 From: Chris Weed Date: Tue, 9 Jul 2024 14:36:20 -0500 Subject: [PATCH] Attempted to add listeners to the pirate class --- pirate.ts | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/pirate.ts b/pirate.ts index 1f6489c..3f3006d 100644 --- a/pirate.ts +++ b/pirate.ts @@ -1,10 +1,13 @@ class Pirate { static idleRightSprite: Image = assets.image`Pirate` static idleLeftSprite: Image = assets.image`Pirate` - static attackRightSprite: Image = assets.image`Pirate` - static attackLeftSprite: Image = assets.image`Pirate` - static parryRightSprite: Image = assets.image`Pirate` + static attackLeftAnimation: Image[] = assets.animation`Pirate Swing w Sword`.map((frame: Image) => { + frame.flipX() + return frame + }) + static attackRightAnimation: Image[] = assets.animation`Pirate Swing w Sword` static parryLeftSprite: Image = assets.image`Pirate` + static parryRightSprite: Image = assets.image`Pirate` static walkRightSprite: Image = assets.image`Pirate` static walkLeftSprite: Image = assets.image`Pirate` @@ -24,6 +27,8 @@ class Pirate { animation.runImageAnimation(this.currentSprite, assets.animation`Pirate Stand`, 300, true) // Setup the controller handlers + // console.log('This ' + this.attack) + this._controller.A.addEventListener(ControllerButtonEvent.Pressed, this.attack) } public place(x: number, y: number) { @@ -36,7 +41,21 @@ class Pirate { // Remove all event listeners } - public attack() { } - public render() { } + + attack() { + console.log("Attack!" + this.health) + const attackAnimationSpeed = 50 + // const anim = this.facing === 'right' ? + // Pirate.attackRightAnimation : + // Pirate.attackLeftAnimation + + // animation.runImageAnimation( + // this.currentSprite, + // anim, + // attackAnimationSpeed, + // false + // ) + // pause(anim.length * attackAnimationSpeed) + } }