Skip to content

Commit

Permalink
Merge branch 'master' of github.com:louisremi/Slasher
Browse files Browse the repository at this point in the history
  • Loading branch information
louisremi committed Nov 25, 2012
2 parents afc0f59 + 126a0aa commit 3ae4166
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
8 changes: 4 additions & 4 deletions components/raytracing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
Expand Down
14 changes: 11 additions & 3 deletions components/teenager.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@
}
})
.onHit("Slasher",function() {
this.dieAHorribleDeath();
Crafty.trigger('NpcDead');
if (!this.dead) {
this.dieAHorribleDeath();
}
});
},

Expand All @@ -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;
Expand Down Expand Up @@ -174,6 +177,11 @@
} else {
this.tilePos();
this.isMoving = false;

if(Crafty.panic) {
this.destroy();
Crafty.trigger('NpcEscape');
}
}

return this;
Expand Down
15 changes: 15 additions & 0 deletions game.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 2 additions & 0 deletions panic.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

Jeu.musique.panic();

Crafty.panic = true;

Crafty.sprite(104, "assets/sprites/teenagers.png", {
SlasherSprite:[1,5],
});
Expand Down

0 comments on commit 3ae4166

Please sign in to comment.