Skip to content

Instantly share code, notes, and snippets.

@knubie
Last active December 23, 2015 03:39
Show Gist options
  • Save knubie/6574961 to your computer and use it in GitHub Desktop.
Save knubie/6574961 to your computer and use it in GitHub Desktop.
Entity = function (name, stats) {
this.ui = {
healthBar: $('<div id="healthBar" class="progress-bar progress-bar-danger"></div>')
manaBar: $('<div id="healthBar" class="progress-bar progress-bar-danger"></div>')
};
// Append UI
$('body').append(this.ui.healthBar);
$('body').append(this.ui.manaBar);
this.name = name;
this.stats = _.extend({
health : 100,
maxhealth : 100,
mana : 100,
maxmana : 100,
timer : 3000,
maxtimer : 3000,
PP : 10,
MP : 10,
defense : 10,
accuracy : 10,
gold : 100,
exp : 0,
maxexp : 10,
level : 1,
statpoints: 5
}, stats)
};
};
Entity.prototype.attack = function (target) {
target.stats.health -= this.stats.PP;
return target;
}
// Update UI
Entity.prototype.updateUI = function() {
this.ui.healthBar.css({'width' : Math.floor((this.stats.timer/this.stats.maxtimer)*100) + '%'});
// etc..
}
var enemy1 = new Entity('goblin', {
maxtimer: 3750,
timer: 3750
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment