Skip to content
Browse files

egg death added

  • Loading branch information...
1 parent 7bdf4b6 commit 76d24870209569e0f98c8ce6730cdf6ada01e247 @severest severest committed Nov 24, 2012
Showing with 21 additions and 15 deletions.
  1. +14 −9 components.js
  2. +7 −6 game.js
View
23 components.js
@@ -79,15 +79,20 @@ Crafty.c("EnemyBase", {
this.health = 100;
this.requires("Collision")
.onHit("ForkyBullet", function () {
- var fork = this.hit('ForkyBullet')[0].obj;
- createFireball(fork.x-25,fork.y-25);
- //destroy fork bullet
- fork.destroy()
- this.health -= 50;
- if (this.health < 0) {
- enemiesAlive--;
- this.destroy();
- gameScore += 100;
+ if (this.health > 0) {
+ var fork = this.hit('ForkyBullet')[0].obj;
+ createFireball(fork.x-25,fork.y-25);
+ //destroy fork bullet
+ fork.destroy()
+ this.health -= 50;
+ if (this.health <= 0) {
+ enemiesAlive--;
+ this.animate("death",50,0);
+ this.bind('AnimationEnd', function () {
+ this.destroy();
+ gameScore += 100;
+ });
+ }
}
})
.onHit("Forky", function() {
View
13 game.js
@@ -16,7 +16,7 @@ window.onload = function () {
Crafty.sprite(20, 80, "imgs/bacon2.png", {firebacon:[0,0]});
Crafty.sprite(120, "imgs/burger_sheet.png", {burg:[0,0]});
Crafty.sprite(100,91, "imgs/egg_ss.png", {egg:[0,0]});
- Crafty.sprite(40,50, "imgs/eggbullet.png", {eggbullet:[0,0]});
+ Crafty.sprite(20,25, "imgs/eggbullet.png", {eggbullet:[0,0]});
Crafty.sprite(80,71, "imgs/onion_ss.png", {onion:[0,0]});
Crafty.sprite(100, "imgs/fireball.png", {fireball:[0,0]});
Crafty.sprite(39,36, "imgs/peppermint.png", {peppermint:[0,0]});
@@ -179,15 +179,16 @@ function showInstructions() {
}
function spawnSimpleEnemy() {
- Crafty.e("Enemy, 2D, DOM, onion, SpriteAnimation, EnemyBase, SimpleEnemy")
- .attr({ x: Crafty.math.randomInt(20, STAGE_WIDTH), y: -50, z: 2})
- .animate("idle", 0, 0, 4)
- .animate("idle", 30, -1)
- .setSpeed(1.5);
+ // Crafty.e("Enemy, 2D, DOM, onion, SpriteAnimation, EnemyBase, SimpleEnemy")
+// .attr({ x: Crafty.math.randomInt(20, STAGE_WIDTH), y: -50, z: 2})
+// .animate("idle", 0, 0, 4)
+// .animate("idle", 30, -1)
+// .setSpeed(1.5);
Crafty.e("Enemy, 2D, DOM, egg, SpriteAnimation, EnemyBase, SimpleEnemy")
.attr({ x: Crafty.math.randomInt(20, STAGE_WIDTH), y: -50, z: 2})
.animate("idle", 0, 0, 3)
+ .animate("death", 4, 0, 8)
.animate("idle", 20, -1)
.setSpeed(1.5);

0 comments on commit 76d2487

Please sign in to comment.
Something went wrong with that request. Please try again.