Permalink
Browse files

Merge branch 'master' of github.com:louisremi/Slasher

  • Loading branch information...
2 parents afc0f59 + 126a0aa commit 3ae41662435233b812648c46bbe72f0260e6a7d4 @louisremi committed Nov 25, 2012
Showing with 32 additions and 7 deletions.
  1. +4 −4 components/raytracing.js
  2. +11 −3 components/teenager.js
  3. +15 −0 game.js
  4. +2 −0 panic.js
@@ -13,10 +13,10 @@
var norm = Math.sqrt(Math.pow(normal.x,2) + Math.pow(normal.y,2));
normal = {x:normal.x*(Crafty.tileSize/2)/norm,y:normal.y*(Crafty.tileSize/2)/norm};
- var ray = new Crafty.polygon([origin._x + (Crafty.tileSize/2) + (normal.x/2),origin.y+(Crafty.tileSize/2)-(normal.y/2)],
- [origin._x + (Crafty.tileSize/2) - (normal.x/2),origin.y+(Crafty.tileSize/2)+(normal.y/2)],
- [dest._x + (Crafty.tileSize/2) - (normal.x/2),dest.y+(Crafty.tileSize/2)+(normal.y/2)],
- [dest._x + (Crafty.tileSize/2) + (normal.x/2),dest.y+(Crafty.tileSize/2)-(normal.y/2)]);
+ var ray = new Crafty.polygon([origin._x+16 + (Crafty.tileSize/2) + (normal.x/2),origin._y+32+(Crafty.tileSize/2)-(normal.y/2)],
+ [origin._x+16 + (Crafty.tileSize/2) - (normal.x/2),origin._y+32+(Crafty.tileSize/2)+(normal.y/2)],
+ [dest._x+16 + (Crafty.tileSize/2) - (normal.x/2),dest._y+32+(Crafty.tileSize/2)+(normal.y/2)],
+ [dest._x+16 + (Crafty.tileSize/2) + (normal.x/2),dest._y+32+(Crafty.tileSize/2)-(normal.y/2)]);
return ray;
},
@@ -48,8 +48,9 @@
}
})
.onHit("Slasher",function() {
- this.dieAHorribleDeath();
- Crafty.trigger('NpcDead');
+ if (!this.dead) {
+ this.dieAHorribleDeath();
+ }
});
},
@@ -71,13 +72,15 @@
});
}
+ Crafty.trigger('NpcDead');
+
return this;
},
dieAHorribleDeath: function() {
this.animate('deathBySlasher', 3, this.offsetY, 6).animate('deathBySlasher',300,0);
this.removeComponent(this.name+'Sprite');
- this.dead = true;
+ this.die();
this.stop().addComponent(this.name+'DeadSprite');
return this;
@@ -174,6 +177,11 @@
} else {
this.tilePos();
this.isMoving = false;
+
+ if(Crafty.panic) {
+ this.destroy();
+ Crafty.trigger('NpcEscape');
+ }
}
return this;
View
@@ -136,6 +136,21 @@ window.onload = function () {
//create our player entity with some premade components
});
+ var deaths = 0;
+ var escaped = 0;
+ Crafty.bind('NpcDead', function() {
+ deaths++;
+ if(deaths+escaped >=5) {
+ Crafty.pause();
+ }
+ });
+
+ Crafty.bind('NpcEscape', function() {
+ escaped++;
+ if(deaths+escaped >=5) {
+ Crafty.pause();
+ }
+ })
Crafty.bind('PANIC',enterPanicMode);
View
@@ -12,6 +12,8 @@
Jeu.musique.panic();
+ Crafty.panic = true;
+
Crafty.sprite(104, "assets/sprites/teenagers.png", {
SlasherSprite:[1,5],
});

0 comments on commit 3ae4166

Please sign in to comment.