Skip to content

Commit

Permalink
Refactored, now ready for attacks!
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikketer committed Jul 10, 2024
1 parent 731113f commit 50d227d
Showing 1 changed file with 61 additions and 85 deletions.
146 changes: 61 additions & 85 deletions pirate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ type ActionObject = {
parry: () => void
faceLeft: () => void
faceRight: () => void
goIdle: () => void
}

class Pirate {
Expand All @@ -25,8 +24,7 @@ class Pirate {
attack: () => undefined,
parry: () => undefined,
faceLeft: () => undefined,
faceRight: () => undefined,
goIdle: () => undefined
faceRight: () => undefined
}

public health: number
Expand All @@ -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)

Expand All @@ -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) {
Expand All @@ -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() {
Expand Down Expand Up @@ -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
)
}
}

0 comments on commit 50d227d

Please sign in to comment.