From 50d227dbc7d1a6abc6716ffed9f0383ceda59c44 Mon Sep 17 00:00:00 2001 From: Chris Weed Date: Wed, 10 Jul 2024 15:05:59 -0500 Subject: [PATCH] Refactored, now ready for attacks! --- pirate.ts | 146 +++++++++++++++++++++++------------------------------- 1 file changed, 61 insertions(+), 85 deletions(-) diff --git a/pirate.ts b/pirate.ts index 562d55a..99a3126 100644 --- a/pirate.ts +++ b/pirate.ts @@ -3,7 +3,6 @@ type ActionObject = { parry: () => void faceLeft: () => void faceRight: () => void - goIdle: () => void } class Pirate { @@ -25,8 +24,7 @@ class Pirate { attack: () => undefined, parry: () => undefined, faceLeft: () => undefined, - faceRight: () => undefined, - goIdle: () => undefined + faceRight: () => undefined } public health: number @@ -37,66 +35,7 @@ class Pirate { this.facing = 'right' this.currentSprite = sprites.create(assets.image`Pirate`) - // Setup animations - // These numbers are coming from the source code: https://github.com/microsoft/arcade-character-animations/blob/main/main.ts - characterAnimations.loopFrames( - this.currentSprite, - Pirate.walkRightAnimation, - 150, - // Moving right (and facing right): - 8 + 128 - ) - characterAnimations.loopFrames( - this.currentSprite, - Pirate.walkLeftAnimation, - 150, - // Moving left (and facing left): - 32 + 512 - ) - characterAnimations.loopFrames( - this.currentSprite, - Pirate.idleLeftAnimation, - 150, - // Facing left: - 32 - ) - characterAnimations.loopFrames( - this.currentSprite, - Pirate.idleRightAnimation, - 150, - // Facing right: - 8 - ) - characterAnimations.loopFrames( - this.currentSprite, - Pirate.walkLeftAnimation, - 150, - // Moving up (facing left): - 32 + 64 - ) - characterAnimations.loopFrames( - this.currentSprite, - Pirate.walkRightAnimation, - 150, - // Moving up (facing right): - 8 + 64 - ) - characterAnimations.loopFrames( - this.currentSprite, - Pirate.walkLeftAnimation, - 150, - // Moving down (facing left): - 32 + 256 - ) - characterAnimations.loopFrames( - this.currentSprite, - Pirate.walkRightAnimation, - 150, - // Moving down (facing right): - 8 + 256 - ) - - // this.idle() + this._setupAnimations() // Setup multiplayer mp.setPlayerSprite(mp.getPlayerByNumber(playerNumber), this.currentSprite) @@ -108,14 +47,11 @@ class Pirate { this.action.parry = () => this.parry() this.action.faceLeft = () => this.face('left') this.action.faceRight = () => this.face('right') - this.action.goIdle = () => this.idle() this.controller.A.addEventListener(ControllerButtonEvent.Pressed, this.action.attack) // this.controller.B.addEventListener(ControllerButtonEvent.Pressed, this.action.parry) this.controller.left.addEventListener(ControllerButtonEvent.Pressed, this.action.faceLeft) this.controller.right.addEventListener(ControllerButtonEvent.Pressed, this.action.faceRight) - this.controller.left.addEventListener(ControllerButtonEvent.Released, this.action.goIdle) - this.controller.right.addEventListener(ControllerButtonEvent.Released, this.action.goIdle) } public place(x: number, y: number) { @@ -131,8 +67,6 @@ class Pirate { this.controller.B.removeEventListener(ControllerButtonEvent.Pressed, this.action.parry) this.controller.left.removeEventListener(ControllerButtonEvent.Pressed, this.action.faceLeft) this.controller.right.removeEventListener(ControllerButtonEvent.Pressed, this.action.faceRight) - this.controller.left.removeEventListener(ControllerButtonEvent.Released, this.action.goIdle) - this.controller.right.removeEventListener(ControllerButtonEvent.Released, this.action.goIdle) } public render() { @@ -173,22 +107,64 @@ class Pirate { } } - idle() { - console.log('Going idle ' + this.facing) - // if (this.facing === 'left') { - // animation.runImageAnimation( - // this.currentSprite, - // Pirate.idleLeftAnimation, - // 200, - // true - // ) - // } else { - // animation.runImageAnimation( - // this.currentSprite, - // Pirate.idleRightAnimation, - // 200, - // true - // ) - // } + _setupAnimations() { + // Setup animations + // These numbers are coming from the source code: https://github.com/microsoft/arcade-character-animations/blob/main/main.ts + characterAnimations.loopFrames( + this.currentSprite, + Pirate.walkRightAnimation, + 150, + // Moving right (and facing right): + 8 + 128 + ) + characterAnimations.loopFrames( + this.currentSprite, + Pirate.walkLeftAnimation, + 150, + // Moving left (and facing left): + 32 + 512 + ) + characterAnimations.loopFrames( + this.currentSprite, + Pirate.idleLeftAnimation, + 150, + // Facing left: + 32 + ) + characterAnimations.loopFrames( + this.currentSprite, + Pirate.idleRightAnimation, + 150, + // Facing right: + 8 + ) + characterAnimations.loopFrames( + this.currentSprite, + Pirate.walkLeftAnimation, + 150, + // Moving up (facing left): + 32 + 64 + ) + characterAnimations.loopFrames( + this.currentSprite, + Pirate.walkRightAnimation, + 150, + // Moving up (facing right): + 8 + 64 + ) + characterAnimations.loopFrames( + this.currentSprite, + Pirate.walkLeftAnimation, + 150, + // Moving down (facing left): + 32 + 256 + ) + characterAnimations.loopFrames( + this.currentSprite, + Pirate.walkRightAnimation, + 150, + // Moving down (facing right): + 8 + 256 + ) } }