This repository has been archived by the owner on Dec 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
168 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
var bs = require('bindlestiff') | ||
|
||
module.exports = health | ||
|
||
function health(amount) { | ||
return bs.component('health') | ||
.on('init', function() { | ||
this.health = amount | ||
this.dead = false | ||
}) | ||
.on('damaged', function(dmg) { | ||
this.health -= dmg | ||
if (!this.dead && this.health <= 0) { | ||
this.dead = true | ||
this.trigger('died') | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
var Box2D = require('box2dweb-commonjs').Box2D | ||
var b2e = require('box2d-events') | ||
var bs = require('bindlestiff') | ||
|
||
module.exports = function vulnerable(group) { | ||
group = parseInt(group, 10) | ||
|
||
return bs.component('vulnerable') | ||
.needs('physical') | ||
.needs('body') | ||
.on('init', function() { | ||
var self = this | ||
|
||
this.body.m_userData = this.body.m_userData || {} | ||
this.body.m_userData.vulnerable_group = group | ||
b2e(Box2D, this.world).fixture( | ||
this.fixture | ||
).on('begin', function(a, b) { | ||
var data = a.m_body.m_userData | ||
if (data.harmful_group === group) | ||
self.trigger('damaged', data.harmful_damage) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
Copyright (c) Matthew Mueller, MIT License | ||
http:https://component.io/matthewmueller/color | ||
*/ | ||
|
||
/** | ||
* Lighten the given color | ||
* @param {String} color hex value | ||
* @param {Number} value | ||
* @return {String} | ||
*/ | ||
|
||
exports.lighten = function(color, v) { | ||
v = (v <= 1) ? v*100 : v; | ||
return tint(color, v); | ||
}; | ||
|
||
/** | ||
* Darken the given color | ||
* @param {String} color hex value | ||
* @param {Number} value | ||
* @return {String} | ||
*/ | ||
|
||
exports.darken = function(color, v) { | ||
v = (v <= 1) ? v*100 : v; | ||
return tint(color, -v); | ||
}; | ||
|
||
|
||
/** | ||
* Tint the color by the given value | ||
* | ||
* Credits: richard maloney 2006 | ||
* | ||
* @param {String} color | ||
* @param {Number} v | ||
* @return {String} | ||
*/ | ||
|
||
function tint(color, v) { | ||
color = color.replace(/^#/, ''); | ||
color = (color.length == 3) ? hex3tohex6(color) : color; | ||
var rgb = parseInt(color, 16); | ||
var r = Math.abs(((rgb >> 16) & 0xFF)+v); if (r>255) r=r-(r-255); | ||
var g = Math.abs(((rgb >> 8) & 0xFF)+v); if (g>255) g=g-(g-255); | ||
var b = Math.abs((rgb & 0xFF)+v); if (b>255) b=b-(b-255); | ||
r = Number(r < 0 || isNaN(r)) ? 0 : ((r > 255) ? 255 : r).toString(16); | ||
if (r.length == 1) r = '0' + r; | ||
g = Number(g < 0 || isNaN(g)) ? 0 : ((g > 255) ? 255 : g).toString(16); | ||
if (g.length == 1) g = '0' + g; | ||
b = Number(b < 0 || isNaN(b)) ? 0 : ((b > 255) ? 255 : b).toString(16); | ||
if (b.length == 1) b = '0' + b; | ||
return "#" + r + g + b; | ||
} | ||
|
||
/** | ||
* Hex3 to Hex6 | ||
*/ | ||
|
||
function hex3tohex6(h) { | ||
return h[0] + h[0] | ||
+ h[1] + h[1] | ||
+ h[2] + h[2]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters