Added elements

This commit is contained in:
2016-02-22 19:46:34 +08:00
parent 7c925c4332
commit 8e7d83cc11
9 changed files with 208 additions and 152 deletions
+26 -26
View File
@@ -10,7 +10,7 @@
game.load();
var lab = game.lab;
var research = game.research;
var elements = game.elements;
var workers = game.workers;
var upgrades = game.upgrades;
var achievements = game.achievements;
@@ -40,6 +40,11 @@
};
}]);
// Hack to prevent text highlighting
document.getElementById('detector').addEventListener('mousedown', function(e) {
e.preventDefault();
});
// controllers
app.controller('DetectorController', function() {
this.click = function() {
@@ -50,10 +55,26 @@
};
});
// Hack to prevent text highlighting
document.getElementById('detector').addEventListener('mousedown', function(e) {
e.preventDefault();
});
app.controller('ElementController', ['$compile', function($compile) {
this.elements = elements;
this.isVisible = function(item) {
return item.isVisible(lab);
};
this.isAvailable = function(item) {
return item.isAvailable(lab);
};
this.doElement = function(item) {
var cost = item.element(lab);
if (cost > 0) {
UI.showUpdateValue("#update-data", -cost);
UI.showUpdateValue("#update-reputation", item.state.reputation);
}
};
this.showInfo = function(r) {
UI.showModal(r.name, r.getInfo());
UI.showLevels(r.state.level);
};
}]);
app.controller('LabController', ['$interval', function($interval) {
this.lab = lab;
@@ -80,27 +101,6 @@
}, 1000);
}]);
app.controller('ResearchController', ['$compile', function($compile) {
this.research = research;
this.isVisible = function(item) {
return item.isVisible(lab);
};
this.isAvailable = function(item) {
return item.isAvailable(lab);
};
this.doResearch = function(item) {
var cost = item.research(lab);
if (cost > 0) {
UI.showUpdateValue("#update-data", -cost);
UI.showUpdateValue("#update-reputation", item.state.reputation);
}
};
this.showInfo = function(r) {
UI.showModal(r.name, r.getInfo());
UI.showLevels(r.state.level);
};
}]);
app.controller('HRController', function() {
this.workers = workers;
this.isVisible = function(worker) {
-3
View File
@@ -64,9 +64,6 @@
self.animationLoop();
}, this.options.animationSpeed);
$(window).on('resize',this.onResize.bind(this));
};
Bubblr.prototype.onResize= function(){
+6 -4
View File
@@ -6,7 +6,7 @@ var Game = (function(Helpers,GameObjects,ObjectStorage) {
var Game = function() {
this.lab = new GameObjects.Lab();
this.research = null;
this.elements = null;
this.workers = null;
this.upgrades = null;
this.achievements = null;
@@ -23,10 +23,12 @@ var Game = (function(Helpers,GameObjects,ObjectStorage) {
// However, I don't see any other reasonable way to do this in order to
// make it work with Angular. If you know a way, let me know, and I'll
// give you a beer. - Kevin
this.research = Helpers.loadFile('json/research.json');
this.elements = Helpers.loadFile('json/elements.json');
this.workers = Helpers.loadFile('json/workers.json');
this.upgrades = Helpers.loadFile('json/upgrades.json');
this.achievements = Helpers.loadFile('json/achievements.json');
this.runes = Helpers.loadFile('json/runes.json');
this.keywords = Helpers.loadFile('json/keywords.json');
// Turn JSON files into actual game objects and fill map of all objects
var _this = this;
@@ -37,8 +39,8 @@ var Game = (function(Helpers,GameObjects,ObjectStorage) {
_this.allObjects[o.key] = o;
return o;
};
this.research = this.research.map(
function(r) { return makeGameObject(GameObjects.Research, r); });
this.elements = this.elements.map(
function(r) { return makeGameObject(GameObjects.Element, r); });
this.workers = this.workers.map(
function(w) { return makeGameObject(GameObjects.Worker, w); });
this.upgrades = this.upgrades.map(
+15 -14
View File
@@ -82,34 +82,35 @@ var GameObjects = (function() {
return false;
};
/** @class Research
/** @class Element
*/
var Research = function(obj) {
var Element = function(obj) {
GameObject.apply(this, [obj]);
this.state.level = 0;
this.state.interesting = false;
this.state.amount = Math.round(Math.random()*2);
this.state.discovered = Math.random()<0.1;
this.state.interesting = Math.random()<0.1;
this.state.color = Math.round(Math.random()*12);
};
Research.prototype = Object.create(GameObject.prototype);
Element.prototype = Object.create(GameObject.prototype);
Research.prototype.constructor = Research;
Element.prototype.constructor = Element;
Research.prototype.isVisible = function(lab) {
Element.prototype.isVisible = function(lab) {
if (!lab) {
return false;
}
return this.state.level > 0 ||
lab.state.data >= this.state.cost * GLOBAL_VISIBILITY_THRESHOLD;
return this.state.discovered;
};
Research.prototype.isAvailable = function(lab) {
Element.prototype.isAvailable = function(lab) {
if (!lab) {
return false;
}
return lab.state.data >= this.state.cost;
return this.state.amount>0;
};
Research.prototype.research = function(lab) {
Element.prototype.research = function(lab) {
if (lab && lab.research(this.state.cost, this.state.reputation)) {
this.state.level++;
if (this.state.info_levels.length > 0 &&
@@ -124,7 +125,7 @@ var GameObjects = (function() {
return -1;
};
Research.prototype.getInfo = function() {
Element.prototype.getInfo = function() {
if (!this._info) {
this._info = Helpers.loadFile(this.info);
}
@@ -269,7 +270,7 @@ var GameObjects = (function() {
// Expose classes in module.
return {
Lab: Lab,
Research: Research,
Element: Element,
Worker: Worker,
Upgrade: Upgrade,
Achievement: Achievement
+3 -1
View File
@@ -18,7 +18,7 @@ var UI = (function () {
}
$('.scrollable').height(h - offset + 'px');
var types = ['research', 'hr', 'upgrades'];
var types = ['element', 'hr', 'upgrades'];
if ($(window).width() < 992) {
for (var i = 0; i < types.length; i++) {
@@ -65,6 +65,8 @@ var UI = (function () {
detector.init(400);
}
}
detector.bubblr.onResize();
}
$(window).resize(resize);