Skip to content

Commit ec30ada

Browse files
committed
feat: zombie knockback
1 parent 90b2edf commit ec30ada

File tree

4 files changed

+8
-0
lines changed

4 files changed

+8
-0
lines changed

assets/blood.png

89 KB
Loading

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
<title>Zombies</title>
1616

17+
<script src="https://code.createjs.com/1.0.0/tweenjs.min.js"></script>
1718
<script src="lib/keyboard.js"></script>
1819
<script src="lib/pixi.min.js"></script>
1920
<script src="lib/matter.min.js"></script>

js/game/app/zombie.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ class Zombie {
115115
{ x: force * damage * horzDelta * 1000, y: force * damage * vertDelta * 1000 }
116116
)
117117

118+
this.damage(force)
119+
118120
setTimeout(() => (this.stunned = false), ZOMBIE_STUNNED_DELAY)
119121
}
120122

@@ -128,10 +130,14 @@ class Zombie {
128130
}
129131

130132
kill = () => {
133+
createjs.Tween.get(this.sprite)
134+
.to({ alpha: 0 }, ZOMBIE_DEATH_ANIMATION_DELAY)
135+
.call(() => this.game.getStage().removeChild(this.sprite))
131136
Matter.Composite.remove(this.game.physicsEngine.world, this.rigidBody)
132137
}
133138

134139
revive = () => {
140+
this.game.getStage().addChild(this.sprite)
135141
Matter.World.add(this.game.physicsEngine.world, this.rigidBody)
136142
}
137143
}

js/setup/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const ZOMBIE_MAX_HEALTH = 50
2222

2323
const ZOMBIE_BASE_COUNT = 10
2424
const ZOMBIE_INCR_COUNT = 4
25+
const ZOMBIE_DEATH_ANIMATION_DELAY = 250 // ms
2526

2627
const PLAYER_TAG = 'MY MAN'
2728

0 commit comments

Comments
 (0)