Skip to content

Commit

Permalink
One step closer
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikketer committed Jul 9, 2024
1 parent eba479d commit 2636170
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
6 changes: 4 additions & 2 deletions island.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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`)
Expand Down
34 changes: 19 additions & 15 deletions pirate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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)
}
}

0 comments on commit 2636170

Please sign in to comment.