From 2636170ebf4f671a4377a045f9fb15c4dfe94555 Mon Sep 17 00:00:00 2001 From: Chris Weed Date: Tue, 9 Jul 2024 14:43:23 -0500 Subject: [PATCH] One step closer --- island.ts | 6 ++++-- pirate.ts | 34 +++++++++++++++++++--------------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/island.ts b/island.ts index e3a16ec..45b71f0 100644 --- a/island.ts +++ b/island.ts @@ -12,7 +12,7 @@ namespace Island { player2.destroy() // Remove all listeners and clear the screen // controller.player1.A.removeEventListener(ControllerButtonEvent.Pressed, p1Attack) - // controller.player1.B.removeEventListener(ControllerButtonEvent.Pressed, leaveIsland) + controller.player1.B.removeEventListener(ControllerButtonEvent.Pressed, leaveIsland) // player1Sprite.destroy() // player2Sprite.destroy() @@ -46,11 +46,13 @@ namespace Island { player1 = new Pirate({ controller: controller.player1 }) player2 = new Pirate({ controller: controller.player2 }) + Pirate.registerEvents(player1) + player1.place(10, 90) // controller.player.left.addEventListener(ControllerButtonEvent.Pressed, goLeft) // controller.player1.A.addEventListener(ControllerButtonEvent.Pressed, p1Attack) - // controller.player1.B.addEventListener(ControllerButtonEvent.Pressed, leaveIsland) + controller.player1.B.addEventListener(ControllerButtonEvent.Pressed, leaveIsland) // player1Sprite = sprites.create(assets.image`Pirate`) // player2Sprite = sprites.create(assets.image`empty`) diff --git a/pirate.ts b/pirate.ts index 3f3006d..b8a4a7b 100644 --- a/pirate.ts +++ b/pirate.ts @@ -11,6 +11,10 @@ class Pirate { static walkRightSprite: Image = assets.image`Pirate` static walkLeftSprite: Image = assets.image`Pirate` + static registerEvents = function(pirate: Pirate) { + + } + currentSprite: Sprite facing: 'left' | 'right' _controller: controller.Controller @@ -27,8 +31,7 @@ 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) + // this._controller.A.addEventListener(ControllerButtonEvent.Pressed, Pirate.player1Attack) } public place(x: number, y: number) { @@ -39,23 +42,24 @@ class Pirate { public destroy() { // Remove all event listeners + // this._controller.A.removeEventListener(ControllerButtonEvent.Pressed, Pirate.punch) } public render() { } - attack() { - console.log("Attack!" + this.health) + public attack(me: Pirate) { + console.log('Attack!') const attackAnimationSpeed = 50 - // const anim = this.facing === 'right' ? - // Pirate.attackRightAnimation : - // Pirate.attackLeftAnimation - - // animation.runImageAnimation( - // this.currentSprite, - // anim, - // attackAnimationSpeed, - // false - // ) - // pause(anim.length * attackAnimationSpeed) + const anim = me.facing === 'right' ? + Pirate.attackRightAnimation : + Pirate.attackLeftAnimation + + animation.runImageAnimation( + me.currentSprite, + anim, + attackAnimationSpeed, + false + ) + pause(anim.length * attackAnimationSpeed) } }