Hero Manager
by Sam Fereday
HTML
<div id="output">
...
</div>
<button id="sendOut">
Send Hero Out
</button>
<button id="callBack">
Call Hero Back
</button>
CSS
body {
font: 85%/1.4em 'consolas', arial;
padding: 1em;
margin: 0;
background: #333;
color: #fff;
}
JavaScript
var gameloop = (function() {
'use strict';
var reqAnimFrame = window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame;
return function(callback) {
var lastUpdate = +new Date();
(function loop() {
callback(((+new Date()) - lastUpdate) / 1000);
reqAnimFrame(loop);
lastUpdate = +new Date();
}());
};
}());
// Leveling
var LevelWeights = {
getExpForLevel: function(n) {
return n * 200;
}
}
// Managers
var HeroManager = {
update: function() {
}
}
// Global layer
var Global = function() {
// ...
this.userData = {
name: ""
}
// ...
}
// Guild layer
var Guild = function() {
// ...
this.guildData = {
name: "",
currencyPool: 0,
rooms: {
lobby: 0,
training: 0,
kitchen: 0
}
}
// ...
}
// Hero layer
var Hero = function() {
// ...
this.heroData = {
name: "",
destination: {
name: "",
distance: 0
},
currentQuest: {
id: "",
completion: 0
},
inventory: {
carriedCurrency: 0
},
leveling: {
level: 1,
exp: 0,
expToNext: LevelWeights.getExpForLevel(this.heroData.stats.level)
},
stats: {
currentHealth: 150,
maxHealth: 150,
combatAbility: 0
}
}
// ...
}
Hero.prototype.update = function(){
}
// Make some stuff
gameloop(function() {
HeroManager.update();
});