Skip to content

Commit

Permalink
Animations somewhat there, adding an extension
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikketer committed Jul 10, 2024
1 parent 2636170 commit c77df71
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 208 deletions.
14 changes: 0 additions & 14 deletions images.g.jres
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,6 @@
"data": "YzgwMDEwMDAxMDAwMDQwMDAwMDBlZTAwZWUwMDAwMDAwMGUwY2VlZWVlMDAwMDAwMDAwMGVjZWUwZTAwMDAwMDAwZWVlZWRkZmQwMDAwMDAwMGYwZGZkZmRmMDAwMDAwMDBiZGRkYmRkZDAwMDAwMDAwZGRkYmRkMGQwMDAwMDAwMDAwZDBkZDAwMDAwMDAwMDBlMGVlZWUwZWQwMDAwMDAwZWVlY2NlZWVkZTBkMDBlMGNlZWVlZWVjZGUwZDAwZGQwZGVlZWUwMDAwMDAwMGRkMDBhYWNhMDAwMDAwMDAwMGYwYTBjYTAwMDAwMDAwMDBhZmFhMGMwMDAwMDAwMGYwMDBmMGZmMDAwMDAwMDAwMDAwZWUwMGVlMDAwMDAwMDBlMGNlZWVlZTAwMDAwMDAwMDBlY2VlMGUwMDAwMDAwMGVlZWVkZGZkMDAwMDAwMDBmMGRmZGZkZjAwMDAwMDAwYmRkZGJkZGQwMDAwMDAwMGRkZGJkZDBkMDAwMDAwMDAwMGQwZGQwMDAwMDAwMDAwZTBlZWVlMGMwMDAwMDAwMGVlZWNjZTBjMDAwMDAwMDBjZWVlZWUwMDAwMDAwMDAwZWVlY2VlMGQwMDAwMDAwMGUwZGRhYTBkMDAwMDAwZjBkYzBkYWEwYTBmMDAwMDAwY2YwMGEwZmEwMDAwMDAwMGYwMDAwMDBmMDAwMDAwMDAwMGVlMDBlZTAwMDAwMDAwZTBjZWVlZWUwMDAwMDAwMDAwZWNlZTBlMDAwMDAwMDBlZWVlZGQwZDAwMDAwMDAwZjBkZmZkZmQwMDAwMDAwMGQwZGJkZGRiMDAwMDAwM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NhY2FhZGRiMDFiZDFkZGNjMDBhYTBhMDBiYjFiZmVmZmYwZmYwZjAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDBlZTAwMDAwMDAwMDBlZWVlZWMwZTAwMDAwMDAwZWVlZWNlMDAwMDAwMDAwMGRmZGRlZWVlMDAwMDAwMDBmZGZkZmQwZjAwMDAwMDAwZGRkYmRkZGIwMDAwMDAwMGQwZGRiZGRkMDAwMDAwMDAwMGRkMGQwMDAwMDAwMDAwZWVlZWVlMGUwMDBiMDBlMGNlZWVjZWVlMDAwYjAwZTBlY2VlZWVlYzAwYjAwMGRkZWRlZWRlZGQwMDAwYmJkZWNkYWNhYWRkMDAwMGIwYmJjYzAwYWEwYTAwMDAwMGYwZmZmMGZmMGYwMDAwMDAwMDAwMDBlZTAwMDAwMDAwMDBlZWVlZWMwZTAwMDAwMDAwZWVlZWNlMDAwMDAwMDAwMGRmZGRlZWVlMDAwMDAwMDBmZGZkZmQwZjAwMDAwMDAwZGRkYmRkZGIwMDAwMDAwMGQwZGRiZGRkMDAwMDAwMDAwMGRkMGQwMDAwMDAwMDAwZWVlZWVlMGUwMDAwMDBlMGNlZWVjZWVlMDAwMDAwZTBlY2VlZWVlYzAwMDAwMGRkZWRlZWRlZGQwMDAwMDBkMGNkYWNhYWRkMDAwMDAwMDBjYzAwYWEwYTAwMDAwMDAwY2MwMGFhMGEwMDAwMDBmMGZmZjBmZjBm",
"displayName": "Pirate Swing w Sword0"
},
"anim9": {
"namespace": "myAnimations",
"id": "anim9",
Expand Down
157 changes: 0 additions & 157 deletions images.g.ts
Original file line number Diff line number Diff line change
Expand Up @@ -704,163 +704,6 @@ d d . . a a a c . . . . . . . .
. f a d d . c c c . f . . . . .
. . f a . . . c c f . . . . . .
. . . f . . . . f . . . . . . .
`];
case "Pirate Walk0":
case "anim11":return [img`
. . . . . . e e . . e e . . . .
. . . . . . e e e e c e e . . .
. . . . . . . e e e e c . . . .
. . . . . . f d d d e e e e . .
. . . . . . d f d f d f f . . .
. . . . . . d d b d d d b d . .
. . . . . . . d d d d b d d . .
. . . . . . . . d d d . . . . .
. . . . d . . e e e e e e . . .
. . . d d e e e c e e c e e . .
. . . d d e e c e e e e c e e .
. . . . . . . . e e e e . d d d
. . . . . . . . c a a a . . d d
. . . . . . . . c a a . f . . .
. . . . . . . . . c a a a f . .
. . . . . . . . f f f . . . f .
`, img`
. . . . . . e e . . e e . . . .
. . . . . . e e e e c e e . . .
. . . . . . . e e e e c . . . .
. . . . . . f d d d e e e e . .
. . . . . . d f d f d f f . . .
. . . . . . d d b d d d b d . .
. . . . . . . d d d d b d d . .
. . . . . . . . d d d . . . . .
. . . . . . . c e e e e e . . .
. . . . . . . c c e e c e e . .
. . . . . . . . e e e e c e . .
. . . . . . . d e e e c e e . .
. . . . . . . d a a d d e . . .
. . . . . f . a a a . d d c f .
. . . . . . f a a . . . c f . .
. . . . . . . f . . . . f . . .
`, img`
. . . . . . e e . . e e . . . .
. . . . . . e e e e c e e . . .
. . . . . . . e e e e c . . . .
. . . . . . . d d d e e e e . .
. . . . . . f d f d d f f . . .
. . . . . . d b d d d b d . . .
. . . . . . . d d d b d d . . .
. . . . . . . . d d d . . . . .
. . . . . . . . e e e e . . . .
. . . . . . . d c e e c e . . .
. . . . . . d d c c c e e d . .
. . . . . . d d e e e e e d . .
. . . . . . . . e e e c . . . .
. . . . . . . . a a c . f . . .
. . . . . . . . . a a c c f . .
. . . . . . . . f f f . . . f .
`, img`
. . . . . . e e . . e e . . . .
. . . . . . e e e e c e e . . .
. . . . . . . e e e e c . . . .
. . . . . . . d d d e e e e . .
. . . . . . f d f d d f f . . .
. . . . . . d b d d d b d . . .
. . . . . . . d d d b d d . . .
. . . . . . . . d d d . . . . .
. . . . . . . c e e e e e . . .
. . . . . . . c c e e c e e . .
. . . . . . . . e e e e c e . .
. . . . . . . d e e e c e e . .
. . . . . . . d d c d d e . . .
. . . . . f . c c c . d d a f .
. . . . . . f c c . . . a f . .
. . . . . . . f . . . . f . . .
`];
case "Pirate Swing w Sword0":
case "anim12":return [img`
. . . . b 1 1 . e e . . e e . .
. . . b b b b 1 e e e e c e e .
. . b b b b b b 1 e e e e c . .
. . b 1 . . . b b d d d e e e e
. . b e . b . . d f d f d f f .
. . b . e d d e d d b d d d b d
. . . . d d e . e d d d d b d d
. . . . . e e e . e d d d . . .
. . . . . . e e e e e e e e e .
. . . . . . . e c c e e e c e e
. . . . . . . . . e e e e e c e
. . . . . . . . . e e e e d d d
. . . . . . . . . c c a a a d d
. . . . . . . . c c . . a a a .
. . . . . . . . c c . . a a a .
. . . . . . . f f f . f f f f .
`, img`
. . . . . . . . e e . . e e . .
. . b 1 1 1 . . e e e e c e e .
. b b b b b 1 . . e e e e c . .
b b 1 . . . . . f d d d e e e e
b b . . b . . . d f d f d f f .
b b . b . . e . d d b d d d b d
b b . . d e . . e d d d d b d d
b b . d . e . e . . d d d . . .
b b e d d e e e e e e e e e e .
. b . . d e e e e c e e e c e e
. . . . . . . . . e e e e e c e
. . . . . . . . . e e e e d d d
. . . . . . . . . c c a a a d d
. . . . . . . . c c . . a a a .
. . . . . . . . c c . . a a a .
. . . . . . . f f f . f f f f .
`, img`
. . . . . . . . . . . . . . . .
. . . b . . . . e e . . e e . .
. . b . . . . . e e e e c e e .
. b . . b . . . . e e e e c . .
. b . b . . . . f d d d e e e e
1 b . b . b . . d f d f d f f .
b b . b . b . . d d b d d d b d
b b . b . b e . . d d d d b d d
b b . b . b . . e . d d d . . .
b b . b . . e . e e e e e e e .
b b . b e . . e e c e e e c e e
b b . b . e e e c e e e e e c e
b b . . b . e e . e e e e d b b
b b 1 . d . d d c c c a a a d d
. b b 1 1 d d d c c . . a a a .
. . b b b 1 e f f f . f f f f .
`, img`
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . e e . .
. . . . . . . . e e e e c e e .
. . . . . . . . e e e e e c . .
. . . . . . . . f d d d e e e e
. . . . . . . . d f d f d f f .
. . . . . . . . d d b d d d b d
. . . . . . . . . d d d d b d d
. . . . . . . . . . d d d . . .
. . . . . . . . e e e e e e e .
. . b . . . . e e c e e e c e e
. . b . . . . e c e e e e e c e
. . . b . . d d d e e e e d d d
. . . . b b e d d c c a a a d d
. . . . . b b b c c . . a a a .
. . . . . . . f f f . f f f f .
`, img`
. . . . . . . . . . . . e e . .
. . . . . . . . e e e e c e e .
. . . . . . . . e e e e e c . .
. . . . . . . . f d d d e e e e
. . . . . . . . d f d f d f f .
. . . . . . . . d d b d d d b d
. . . . . . . . . d d d d b d d
. . . . . . . . . . d d d . . .
. . . . . . . . e e e e e e e .
. . . . . . . e e c e e e c e e
. . . . . . . e c e e e e e c e
. . . . . . d d d e e e e d d d
. . . . . . . d d c c a a a d d
. . . . . . . . c c . . a a a .
. . . . . . . . c c . . a a a .
. . . . . . . f f f . f f f f .
`];
case "Pirate Swing w Sword":
case "anim9":return [img`
Expand Down
6 changes: 2 additions & 4 deletions island.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@ namespace Island {
// }

export function init(island: Map.Island) {
player1 = new Pirate({ controller: controller.player1 })
player2 = new Pirate({ controller: controller.player2 })

Pirate.registerEvents(player1)
player1 = new Pirate({ control: controller.player1, playerNumber: 0 })
player2 = new Pirate({ control: controller.player2, playerNumber: 1 })

player1.place(10, 90)

Expand Down
154 changes: 121 additions & 33 deletions pirate.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,62 @@
type ActionObject = {
attack: () => void
parry: () => void
faceLeft: () => void
faceRight: () => void
goIdle: () => void
}

class Pirate {
static idleRightSprite: Image = assets.image`Pirate`
static idleLeftSprite: Image = assets.image`Pirate`
static attackLeftAnimation: Image[] = assets.animation`Pirate Swing w Sword`.map((frame: Image) => {
frame.flipX()
return frame
})
static idleRightAnimation: Image[] = assets.animation`Pirate Stand`
static idleLeftAnimation: Image[] = Utils.flipAnimation(assets.animation`Pirate Stand`)
static attackLeftAnimation: Image[] = Utils.flipAnimation(assets.animation`Pirate Swing w Sword`)
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`

static registerEvents = function(pirate: Pirate) {

}
static walkRightAnimation: Image[] = assets.animation`Pirate Walk`
static walkLeftAnimation: Image[] = Utils.flipAnimation(assets.animation`Pirate Walk`)

currentSprite: Sprite
facing: 'left' | 'right'
_controller: controller.Controller
public controller: controller.Controller
// This action object is for registering event listeners
// It keeps all functions stable per this class so we can removeEventListners
action: ActionObject = {
attack: () => undefined,
parry: () => undefined,
faceLeft: () => undefined,
faceRight: () => undefined,
goIdle: () => undefined
}

public health: number

constructor({ controller }: { controller: controller.Controller }) {
constructor({ control, playerNumber }: { control: controller.Controller, playerNumber: 0 | 1 }) {
// Setup event listeners
this.health = 100
this.facing = 'right'
this._controller = controller

this.currentSprite = sprites.create(Pirate.idleRightSprite)
animation.runImageAnimation(this.currentSprite, assets.animation`Pirate Stand`, 300, true)
this.currentSprite = sprites.create(assets.image`Pirate`)
this.idle()
// Setup multiplayer
mp.setPlayerSprite(mp.getPlayerByNumber(playerNumber), this.currentSprite)

// Setup the controller handlers
// this._controller.A.addEventListener(ControllerButtonEvent.Pressed, Pirate.player1Attack)
this.controller = control
// We can't simply do `this.attack` as the event listeners can't handle a "lambda"
// And we need to keep a reference to the callback function so we can removeEventListner
this.action.attack = () => this.attack()
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 @@ -41,25 +66,88 @@ class Pirate {
}

public destroy() {
this.currentSprite.destroy()
// Remove all event listeners
// this._controller.A.removeEventListener(ControllerButtonEvent.Pressed, Pirate.punch)
this.controller.A.removeEventListener(ControllerButtonEvent.Pressed, this.action.attack)
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() { }
public render() {
this.currentSprite.x += this.controller.dx(50)
this.currentSprite.y += this.controller.dy(50)
this.currentSprite.z = this.currentSprite.y

if (this.controller.dx(50) > 0) {
animation.runImageAnimation(
this.currentSprite,
Pirate.walkRightAnimation,
200,
true
)
} else if (this.controller.dx(50) < 0) {
animation.runImageAnimation(
this.currentSprite,
Pirate.walkLeftAnimation,
200,
true
)
}
}

public attack(me: Pirate) {
console.log('Attack!')
parry() {
console.log('parry ' + this.controller.playerIndex)
}

attack() {
const attackAnimationSpeed = 50
const anim = me.facing === 'right' ?
Pirate.attackRightAnimation :
Pirate.attackLeftAnimation

animation.runImageAnimation(
me.currentSprite,
anim,
attackAnimationSpeed,
false
)
pause(anim.length * attackAnimationSpeed)
if (this.facing === 'right') {
animation.runImageAnimation(
this.currentSprite,
Pirate.attackRightAnimation,
attackAnimationSpeed,
false
)
} else {
animation.runImageAnimation(
this.currentSprite,
Pirate.attackLeftAnimation,
attackAnimationSpeed,
false
)
}

pause(Pirate.attackLeftAnimation.length * attackAnimationSpeed)
}

face(direction: 'left' | 'right') {
console.log('Face ' + direction)
if (direction === 'left' && this.facing === 'right') {
this.facing = 'left'
} else if (direction === 'right' && this.facing === 'left') {
this.facing = 'right'
}
}

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
)
}
}
}
8 changes: 8 additions & 0 deletions utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,12 @@ namespace Utils {
}
return result
}

// Used to re-use an animation but flip it horizontally (x)
export function flipAnimation(frames: Image[]) {
return frames.map((frame: Image) => {
frame.flipX()
return frame
})
}
}

0 comments on commit c77df71

Please sign in to comment.