Skip to content

Commit

Permalink
Death animations galore!!!!
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikketer committed Jul 14, 2024
1 parent 3ee196f commit cd140e9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 18 deletions.
40 changes: 26 additions & 14 deletions island.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,6 @@ namespace Island {
enemy.hit(1)
}
})
// clean any enemies off the array if they are dead
currentEnemies = currentEnemies.reduce((acc, enemy) => {
if (enemy.health > 0) {
acc.push(enemy)
}
return acc
}, [])

checkIfSegmentIsComplete()
}
Expand All @@ -83,12 +76,16 @@ namespace Island {
}

function checkIfSegmentIsComplete() {
if (currentEnemies.length) {
const aliveEnemies = currentEnemies.filter((enemy) => {
return enemy.health > 0
})

if (aliveEnemies.length) {
isSegmentComplete = false
}

// If there are no enemies left, signal to go to the next segment
if (currentEnemies.length <= 0 && !isSegmentComplete) {
if (aliveEnemies.length <= 0 && !isSegmentComplete) {
isSegmentComplete = true

// Show the "go" arrow if we have a place to go
Expand All @@ -111,11 +108,26 @@ namespace Island {
}

function panCameraToNextSegment() {
console.log("Go to next segment! " + screen.width + ':' + screen.height)
// This is a little rough but for now it works
// Place the pirates on the far left side
player1.sprite.x = 10
player2.sprite.x = 10
// TODO someday animate this transition...
// Clean up any corpses
if (player1.health <= 0) {
player1.destroy()
} else {
player1.sprite.x = 10
}

if (player2.health <= 0) {
player2.destroy()
} else {
player2.sprite.x = 10
}

currentEnemies.forEach(enemy => {
if (enemy.health <= 0) {
enemy.destory()
}
})

isSegmentComplete = false

if (arrow) {
Expand Down
20 changes: 16 additions & 4 deletions militia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ class Militia {
static walkLeftAnimation: Image[] = Utils.flipAnimation(assets.animation`Militia Walk`)
static attackRightAnimation: Image[] = assets.animation`Militia Shoot`
static attackLeftAnimation: Image[] = Utils.flipAnimation(assets.animation`Militia Shoot`)
static deathRightAnimation: Image[] = assets.animation`Militia Die`
static deathLeftAnimation: Image[] = Utils.flipAnimation(assets.animation`Militia Die`)
static parrySound: music.SoundEffect = music.createSoundEffect(WaveShape.Noise, 5000, 5000, 255, 0, 100, SoundExpressionEffect.Vibrato, InterpolationCurve.Curve)

static speed: number = 10
Expand Down Expand Up @@ -47,7 +49,13 @@ class Militia {
this.health -= damage

if (this.health <= 0) {
this.destory()
animation.runImageAnimation(
this.sprite,
this.facing === 'right' ? Militia.deathRightAnimation : Militia.deathLeftAnimation,
100,
false
)
this.sprite.follow(this.currentTarget.sprite, 0)
}
}

Expand All @@ -56,6 +64,9 @@ class Militia {
}

public render() {
// Short circut if I die
if (this.health <= 0 ) return

// Attack randomly
if ((control.millis() - this._lastAttackTick) > this._nextAttackTime) {
this._lastAttackTick = control.millis()
Expand All @@ -77,9 +88,10 @@ class Militia {
}

public setCurrentTarget(pirate: Pirate) {
console.log('Setting target')
this.currentTarget = pirate
this.sprite.follow(this.currentTarget.sprite, Militia.speed)
if (pirate.health > 0 && this.health > 0) {
this.currentTarget = pirate
this.sprite.follow(this.currentTarget.sprite, Militia.speed)
}
}

private walk(direction?: 'left' | 'right') {
Expand Down

0 comments on commit cd140e9

Please sign in to comment.