954 lines
87 KiB
JavaScript
954 lines
87 KiB
JavaScript
|
var Base,
|
||
|
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
|
||
|
|
||
|
Base = (function() {
|
||
|
function Base() {
|
||
|
this.changeAnimation = __bind(this.changeAnimation, this);
|
||
|
this.frame = 0;
|
||
|
window.setInterval(this.changeAnimation, 500);
|
||
|
}
|
||
|
|
||
|
Base.prototype.tick = function(tile) {};
|
||
|
|
||
|
Base.prototype.sprite = function() {
|
||
|
return [this.frame * 8, 0, 8, 8];
|
||
|
};
|
||
|
|
||
|
Base.prototype.spritedetail = function() {
|
||
|
return [0, 0, 16, 16];
|
||
|
};
|
||
|
|
||
|
Base.prototype.isMoveable = function() {
|
||
|
return false;
|
||
|
};
|
||
|
|
||
|
Base.prototype.changeAnimation = function() {
|
||
|
if (this.frame === 3) {
|
||
|
return this.frame = 0;
|
||
|
} else {
|
||
|
return this.frame += 1;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
Base.prototype.spaceProvided = 30;
|
||
|
|
||
|
Base.prototype.energyProvided = 7;
|
||
|
|
||
|
Base.prototype.isDockable = true;
|
||
|
|
||
|
return Base;
|
||
|
|
||
|
})();
|
||
|
|
||
|
var Miner,
|
||
|
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
|
||
|
|
||
|
Miner = (function() {
|
||
|
function Miner() {
|
||
|
this.changeAnimation = __bind(this.changeAnimation, this);
|
||
|
this.frame = 0;
|
||
|
window.setInterval(this.changeAnimation, 500);
|
||
|
}
|
||
|
|
||
|
Miner.prototype.tick = function(tile) {
|
||
|
tile.click("left");
|
||
|
tile.click("left");
|
||
|
tile.click("left");
|
||
|
return tile.click("left");
|
||
|
};
|
||
|
|
||
|
Miner.prototype.sprite = function() {
|
||
|
return [this.frame * 8, 16, 8, 8];
|
||
|
};
|
||
|
|
||
|
Miner.prototype.spritedetail = function() {
|
||
|
return [0, 16 * 2, 16, 16];
|
||
|
};
|
||
|
|
||
|
Miner.prototype.isMoveable = function() {
|
||
|
return true;
|
||
|
};
|
||
|
|
||
|
Miner.prototype.changeAnimation = function() {
|
||
|
if (this.frame === 1) {
|
||
|
return this.frame = 0;
|
||
|
} else {
|
||
|
return this.frame += 1;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
Miner.prototype.spaceProvided = 5;
|
||
|
|
||
|
Miner.prototype.energyProvided = 0;
|
||
|
|
||
|
Miner.prototype.isDockable = false;
|
||
|
|
||
|
return Miner;
|
||
|
|
||
|
})();
|
||
|
|
||
|
var Silo,
|
||
|
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
|
||
|
|
||
|
Silo = (function() {
|
||
|
function Silo() {
|
||
|
this.changeAnimation = __bind(this.changeAnimation, this);
|
||
|
this.frame = 0;
|
||
|
window.setInterval(this.changeAnimation, 500);
|
||
|
}
|
||
|
|
||
|
Silo.prototype.tick = function(tile) {};
|
||
|
|
||
|
Silo.prototype.sprite = function() {
|
||
|
return [this.frame * 8, 8, 8, 8];
|
||
|
};
|
||
|
|
||
|
Silo.prototype.spritedetail = function() {
|
||
|
return [0, 16, 16, 16];
|
||
|
};
|
||
|
|
||
|
Silo.prototype.isMoveable = function() {
|
||
|
return false;
|
||
|
};
|
||
|
|
||
|
Silo.prototype.changeAnimation = function() {
|
||
|
if (this.frame === 1) {
|
||
|
return this.frame = 0;
|
||
|
} else {
|
||
|
return this.frame += 1;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
Silo.prototype.spaceProvided = 15;
|
||
|
|
||
|
Silo.prototype.energyProvided = 0;
|
||
|
|
||
|
Silo.prototype.isDockable = true;
|
||
|
|
||
|
return Silo;
|
||
|
|
||
|
})();
|
||
|
|
||
|
var Solarpanel;
|
||
|
|
||
|
Solarpanel = (function() {
|
||
|
function Solarpanel() {}
|
||
|
|
||
|
Solarpanel.prototype.tick = function(tile) {};
|
||
|
|
||
|
Solarpanel.prototype.sprite = function() {
|
||
|
return [0, 8 * 3, 8, 8];
|
||
|
};
|
||
|
|
||
|
Solarpanel.prototype.spritedetail = function() {
|
||
|
return [0, 16 * 3, 16, 16];
|
||
|
};
|
||
|
|
||
|
Solarpanel.prototype.isMoveable = function() {
|
||
|
return false;
|
||
|
};
|
||
|
|
||
|
Solarpanel.prototype.spaceProvided = 0;
|
||
|
|
||
|
Solarpanel.prototype.energyProvided = 15;
|
||
|
|
||
|
Solarpanel.prototype.isDockable = true;
|
||
|
|
||
|
return Solarpanel;
|
||
|
|
||
|
})();
|
||
|
|
||
|
var AnimatedItem,
|
||
|
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
|
||
|
|
||
|
AnimatedItem = (function() {
|
||
|
function AnimatedItem(options) {
|
||
|
this.changeAnimation = __bind(this.changeAnimation, this);
|
||
|
this.maxFrames = options.maxFrames, this.image = options.image, this.speed = options.speed;
|
||
|
this.frame = 0;
|
||
|
window.setInterval(this.changeAnimation, this.speed);
|
||
|
}
|
||
|
|
||
|
AnimatedItem.prototype.sprite = function() {
|
||
|
return [this.frame * 8, 0, 8, 8];
|
||
|
};
|
||
|
|
||
|
AnimatedItem.prototype.changeAnimation = function() {
|
||
|
if (this.frame === this.maxFrames) {
|
||
|
return this.frame = 0;
|
||
|
} else {
|
||
|
return this.frame += 1;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
return AnimatedItem;
|
||
|
|
||
|
})();
|
||
|
|
||
|
var Tile;
|
||
|
|
||
|
Tile = (function() {
|
||
|
function Tile(position) {
|
||
|
var i, restype, _i, _len, _ref;
|
||
|
this.position = position;
|
||
|
this.layers = [];
|
||
|
_ref = allResourceTypes();
|
||
|
for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
|
||
|
restype = _ref[i];
|
||
|
this.layers.push(new Tilelayer({
|
||
|
type: restype,
|
||
|
depth: i,
|
||
|
amount: Math.round(Math.random() * app.game.maxTileAmount) + 1
|
||
|
}));
|
||
|
}
|
||
|
this.currentLayer = 0;
|
||
|
this.empty = false;
|
||
|
this.entity = null;
|
||
|
this.isActive = false;
|
||
|
this.isBuildable = !(Math.round(Math.random() * 10) === 5);
|
||
|
if (this.position === 20 * 5 + 10) {
|
||
|
this.isBuildable = true;
|
||
|
}
|
||
|
this.randomSeed = Math.round(Math.random() * 10);
|
||
|
}
|
||
|
|
||
|
Tile.prototype.click = function(button) {
|
||
|
var name;
|
||
|
if (!this.isBuildable) {
|
||
|
return;
|
||
|
}
|
||
|
if (button === "left" && !this.empty) {
|
||
|
if ((app.game.availableSiloStorage() - app.game.usedSiloStorage()) > 0) {
|
||
|
if (this.layers[this.currentLayer].collect()) {
|
||
|
name = app.layerIndexToName(this.currentLayer);
|
||
|
return app.game.resources[name] += 1;
|
||
|
} else {
|
||
|
this.currentLayer += 1;
|
||
|
if (this.currentLayer === allResourceTypes().length - 1) {
|
||
|
this.entity = null;
|
||
|
return this.empty = true;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
Tile.prototype.tick = function() {
|
||
|
if (this.entity) {
|
||
|
return this.entity.tick(this);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
Tile.prototype.moveIn = function() {
|
||
|
return this.isActive = true;
|
||
|
};
|
||
|
|
||
|
Tile.prototype.moveOut = function() {
|
||
|
return this.isActive = false;
|
||
|
};
|
||
|
|
||
|
Tile.prototype.select = function() {
|
||
|
return this.isSelected = true;
|
||
|
};
|
||
|
|
||
|
Tile.prototype.deselect = function() {
|
||
|
return this.isSelected = false;
|
||
|
};
|
||
|
|
||
|
Tile.prototype.getCurrentLayer = function() {
|
||
|
return this.layers[this.currentLayer];
|
||
|
};
|
||
|
|
||
|
Tile.prototype.render = function(x, y) {
|
||
|
var color, i, numPercent, tileLayer, _i;
|
||
|
tileLayer = this.getCurrentLayer();
|
||
|
app.layer.drawRegion(app.images.layers, tileLayer.sprite, x * 8, y * 8);
|
||
|
if (!this.isBuildable) {
|
||
|
app.layer.drawRegion(app.images.deadtiles, [8 * this.randomSeed, 0, 8, 8], x * 8, y * 8);
|
||
|
return;
|
||
|
}
|
||
|
if (this.entity) {
|
||
|
app.layer.drawRegion(app.images.entities, this.entity.sprite(), x * 8, y * 8);
|
||
|
}
|
||
|
if ((this.entity && this.entity.isMoveable()) || this.isActive) {
|
||
|
app.layer.drawImage(app.images.progress, x * 8, y * 8);
|
||
|
numPercent = Math.floor((tileLayer.amount * 6) / app.game.maxTileAmount);
|
||
|
for (i = _i = 0; 0 <= numPercent ? _i <= numPercent : _i >= numPercent; i = 0 <= numPercent ? ++_i : --_i) {
|
||
|
color = ["#f00", "#a00", "#f60", "#aa0", "#0a0", "#0a0"][numPercent];
|
||
|
if (i === numPercent) {
|
||
|
color = ["#f00", "#f00", "#f80", "#ff0", "#0f0", "#0f0"][numPercent];
|
||
|
}
|
||
|
app.layer.setPixel(color, x * 8 + 1 + i, y * 8 + 6);
|
||
|
}
|
||
|
}
|
||
|
if (this.isActive) {
|
||
|
app.layer.drawImage(app.images.active, x * 8, y * 8);
|
||
|
}
|
||
|
if (this.isSelected) {
|
||
|
return app.layer.drawImage(app.images.selected, x * 8, y * 8);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
return Tile;
|
||
|
|
||
|
})();
|
||
|
|
||
|
var Tilelayer;
|
||
|
|
||
|
Tilelayer = (function() {
|
||
|
function Tilelayer(options) {
|
||
|
this.type = options.type, this.depth = options.depth, this.amount = options.amount;
|
||
|
this.randomFactor = getRandomInt(0, 4);
|
||
|
this.sprite = [this.randomFactor * 8, this.depth * 8, 8, 8];
|
||
|
this.spritedetail = [0, this.depth * 16, 16, 16];
|
||
|
this.hudSprite = [this.randomFactor * 8, this.depth * 8, 4, 4];
|
||
|
}
|
||
|
|
||
|
Tilelayer.prototype.collect = function() {
|
||
|
if (this.amount === 0) {
|
||
|
return false;
|
||
|
}
|
||
|
return this.amount -= 1;
|
||
|
};
|
||
|
|
||
|
return Tilelayer;
|
||
|
|
||
|
})();
|
||
|
|
||
|
var allResourceTypes, getRandomInt, posToTile, posToXY, xyToPos,
|
||
|
__hasProp = {}.hasOwnProperty;
|
||
|
|
||
|
getRandomInt = function(min, max) {
|
||
|
return Math.floor(Math.random() * (max - min + 1)) + min;
|
||
|
};
|
||
|
|
||
|
allResourceTypes = function() {
|
||
|
var k, _ref, _results;
|
||
|
_ref = app.game.resources;
|
||
|
_results = [];
|
||
|
for (k in _ref) {
|
||
|
if (!__hasProp.call(_ref, k)) continue;
|
||
|
_results.push(k);
|
||
|
}
|
||
|
return _results;
|
||
|
};
|
||
|
|
||
|
posToTile = function(x, y) {
|
||
|
return app.game.map[xyToPos(x, y)];
|
||
|
};
|
||
|
|
||
|
posToXY = function(pos) {
|
||
|
var x, y;
|
||
|
y = Math.floor(pos / 20);
|
||
|
x = pos - (y * 20);
|
||
|
return [x, y];
|
||
|
};
|
||
|
|
||
|
xyToPos = function(x, y) {
|
||
|
return y * 20 + x;
|
||
|
};
|
||
|
|
||
|
var app,
|
||
|
__hasProp = {}.hasOwnProperty;
|
||
|
|
||
|
app = playground({
|
||
|
width: 8 * 20,
|
||
|
height: 8 * 15,
|
||
|
scaleToFit: true,
|
||
|
smoothing: false,
|
||
|
create: function() {
|
||
|
this.loadImages("layers", "active", "progress", "selected", "entities", "hud", "actions", "speechbubbles", "deadtiles", "layerdetails", "entitydetails", "buildinfo", "cursor", "info", "end", "intro1", "intro2", "intro3", "intro4", "titlescreen");
|
||
|
return this.currentHoveredTile = new Tile;
|
||
|
},
|
||
|
ready: function() {
|
||
|
this.game.start();
|
||
|
return this.setState(this.game);
|
||
|
},
|
||
|
render: function() {
|
||
|
this.layer.clear("#00f");
|
||
|
return this.game.render();
|
||
|
},
|
||
|
layerIndexToName: function(index) {
|
||
|
var k, resTypes;
|
||
|
resTypes = (function() {
|
||
|
var _ref, _results;
|
||
|
_ref = this.game.resources;
|
||
|
_results = [];
|
||
|
for (k in _ref) {
|
||
|
if (!__hasProp.call(_ref, k)) continue;
|
||
|
_results.push(k);
|
||
|
}
|
||
|
return _results;
|
||
|
}).call(this);
|
||
|
return resTypes[index];
|
||
|
}
|
||
|
});
|
||
|
|
||
|
app.game = {
|
||
|
start: function() {
|
||
|
var i, _i, _ref;
|
||
|
for (i = _i = 0, _ref = 20 * 15 - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; i = 0 <= _ref ? ++_i : --_i) {
|
||
|
this.map[i] = new Tile(i);
|
||
|
}
|
||
|
this.map[20 * 5 + 10].entity = new Base;
|
||
|
this.mouseX = 0;
|
||
|
this.mouseY = 0;
|
||
|
this.currentHoveredTile = new Tile(-1);
|
||
|
this.currentSelectedTile = null;
|
||
|
window.setInterval(this.tick, 1000);
|
||
|
this.hud.start();
|
||
|
this.speechbubble.start();
|
||
|
this.cutScene = false;
|
||
|
this.intro = false;
|
||
|
return this.titleScreen = true;
|
||
|
},
|
||
|
startCutScene: function() {
|
||
|
if (this.titleScreen) {
|
||
|
this.titleScreen = false;
|
||
|
this.cutScene = true;
|
||
|
app.game.cutSceneImage = app.images.intro1;
|
||
|
return window.setTimeout(app.game.cutScene2, 1500);
|
||
|
}
|
||
|
},
|
||
|
cutScene2: (function(_this) {
|
||
|
return function() {
|
||
|
app.game.cutSceneImage = app.images.intro2;
|
||
|
return window.setTimeout(app.game.cutScene3, 2000);
|
||
|
};
|
||
|
})(this),
|
||
|
cutScene3: (function(_this) {
|
||
|
return function() {
|
||
|
app.game.cutSceneImage = app.images.intro3;
|
||
|
return window.setTimeout(app.game.cutScene4, 1500);
|
||
|
};
|
||
|
})(this),
|
||
|
cutScene4: (function(_this) {
|
||
|
return function() {
|
||
|
app.game.cutSceneImage = app.images.intro4;
|
||
|
return window.setTimeout(app.game.cutSceneEnd, 1500);
|
||
|
};
|
||
|
})(this),
|
||
|
cutSceneEnd: (function(_this) {
|
||
|
return function() {
|
||
|
app.game.cutScene = false;
|
||
|
app.game.intro = true;
|
||
|
return app.game.startIntro();
|
||
|
};
|
||
|
})(this),
|
||
|
startIntro: function() {
|
||
|
this.speechbubble.setFix(90, 27);
|
||
|
this.speechbubble.say('help', 2000);
|
||
|
return this.timeout = window.setTimeout(this.intro2, 3000);
|
||
|
},
|
||
|
intro2: (function(_this) {
|
||
|
return function() {
|
||
|
app.game.speechbubble.say('damn', 2000);
|
||
|
return app.game.timeout = window.setTimeout(app.game.intro3, 3000);
|
||
|
};
|
||
|
})(this),
|
||
|
intro3: (function(_this) {
|
||
|
return function() {
|
||
|
app.game.speechbubble.say('need', 3500);
|
||
|
return app.game.timeout = window.setTimeout(app.game.intro4, 4500);
|
||
|
};
|
||
|
})(this),
|
||
|
intro4: (function(_this) {
|
||
|
return function() {
|
||
|
app.game.speechbubble.say('collect', 3500);
|
||
|
return app.game.timeout = window.setTimeout(app.game.introEnd, 3500);
|
||
|
};
|
||
|
})(this),
|
||
|
introEnd: (function(_this) {
|
||
|
return function() {
|
||
|
_this.intro = false;
|
||
|
return app.game.speechbubble.setMouse();
|
||
|
};
|
||
|
})(this),
|
||
|
render: function() {
|
||
|
var i, tile, x, y, _i, _len, _ref;
|
||
|
if (this.titleScreen) {
|
||
|
app.layer.drawImage(app.images.titlescreen, 0, 0, 20 * 8, 15 * 8);
|
||
|
return;
|
||
|
}
|
||
|
if (this.cutScene) {
|
||
|
app.layer.drawImage(this.cutSceneImage, 0, 0, 20 * 8, 15 * 8);
|
||
|
return;
|
||
|
}
|
||
|
if (this.gameEndCheck()) {
|
||
|
app.layer.drawImage(app.images.end, 0, 0, 20 * 8, 15 * 8);
|
||
|
return;
|
||
|
}
|
||
|
_ref = this.map;
|
||
|
for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
|
||
|
tile = _ref[i];
|
||
|
y = Math.floor(i / 20);
|
||
|
x = i - (y * 20);
|
||
|
tile.render(x, y);
|
||
|
}
|
||
|
this.hud.render();
|
||
|
return this.speechbubble.render();
|
||
|
},
|
||
|
mousedown: function(event) {
|
||
|
var tile;
|
||
|
tile = posToTile(Math.floor(event.x / 8), Math.floor(event.y / 8));
|
||
|
if (!(tile && tile.isBuildable)) {
|
||
|
return;
|
||
|
}
|
||
|
if (this.isMouseInView(event.x / 8, event.y / 8)) {
|
||
|
switch (event.button) {
|
||
|
case 'left':
|
||
|
if (event.x > 143 && event.x < 151 && event.y > 95 && event.y < 106) {
|
||
|
return app.game.hud.showBuildInfo();
|
||
|
} else {
|
||
|
tile.click(event.button);
|
||
|
if (this.currentSelectedTile) {
|
||
|
this.currentSelectedTile.deselect();
|
||
|
}
|
||
|
tile.select();
|
||
|
return this.currentSelectedTile = tile;
|
||
|
}
|
||
|
break;
|
||
|
case 'right':
|
||
|
if (this.currentSelectedTile) {
|
||
|
this.currentSelectedTile.deselect();
|
||
|
}
|
||
|
return this.currentSelectedTile = null;
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
mousemove: function(event) {
|
||
|
var tile;
|
||
|
this.mouseX = event.x;
|
||
|
this.mouseY = event.y;
|
||
|
if (this.isMouseInView(event.x, event.y)) {
|
||
|
tile = posToTile(Math.floor(event.x / 8), Math.floor(event.y / 8));
|
||
|
if (tile) {
|
||
|
if (tile !== this.currentHoveredTile) {
|
||
|
tile.moveIn();
|
||
|
if (this.currentHoveredTile) {
|
||
|
this.currentHoveredTile.moveOut();
|
||
|
}
|
||
|
return this.currentHoveredTile = tile;
|
||
|
}
|
||
|
}
|
||
|
} else {
|
||
|
if (this.currentHoveredTile) {
|
||
|
this.currentHoveredTile.moveOut();
|
||
|
}
|
||
|
return this.currentHoveredTile = null;
|
||
|
}
|
||
|
},
|
||
|
isMouseInView: function(mouseX, mouseY) {
|
||
|
if (mouseX < app.width && mouseX >= 0 && mouseY < app.height && mouseY >= 0) {
|
||
|
return true;
|
||
|
}
|
||
|
return false;
|
||
|
},
|
||
|
keyup: function(event) {
|
||
|
switch (event.key) {
|
||
|
case "enter":
|
||
|
return this.startCutScene();
|
||
|
case "m":
|
||
|
return this.createMiner();
|
||
|
case "e":
|
||
|
return this.createSolarpanel();
|
||
|
case "i":
|
||
|
return app.game.hud.showBuildInfo();
|
||
|
case "s":
|
||
|
return this.createSilo();
|
||
|
case "c":
|
||
|
return this.cheatah();
|
||
|
case "1":
|
||
|
return this.releaseRes('stardust');
|
||
|
case "2":
|
||
|
return this.releaseRes('dirt');
|
||
|
case "3":
|
||
|
return this.releaseRes('bedrock');
|
||
|
case "4":
|
||
|
return this.releaseRes('oxodum');
|
||
|
case "5":
|
||
|
return this.releaseRes('lubinit');
|
||
|
case "6":
|
||
|
return this.releaseRes('darkana');
|
||
|
case "7":
|
||
|
return this.releaseRes('bio');
|
||
|
case "8":
|
||
|
return this.releaseRes('notch');
|
||
|
case "9":
|
||
|
return this.releaseRes('lava');
|
||
|
case "space":
|
||
|
if (this.currentSelectedTile) {
|
||
|
this.currentSelectedTile.deselect();
|
||
|
}
|
||
|
return this.currentSelectedTile = null;
|
||
|
}
|
||
|
},
|
||
|
releaseRes: function(string) {
|
||
|
return this.resources[string] = 0;
|
||
|
},
|
||
|
tick: (function(_this) {
|
||
|
return function() {
|
||
|
var tile, _i, _len, _ref, _results;
|
||
|
_ref = app.game.map;
|
||
|
_results = [];
|
||
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||
|
tile = _ref[_i];
|
||
|
_results.push(tile.tick());
|
||
|
}
|
||
|
return _results;
|
||
|
};
|
||
|
})(this),
|
||
|
createMiner: function() {
|
||
|
if (this.currentSelectedTile && !this.currentSelectedTile.entity) {
|
||
|
if (this.checkResource('lubinit', 5, true)) {
|
||
|
return this.currentSelectedTile.entity = new Miner;
|
||
|
} else {
|
||
|
return this.speechbubble.say('nores');
|
||
|
}
|
||
|
} else {
|
||
|
return this.speechbubble.say('nosel');
|
||
|
}
|
||
|
},
|
||
|
createSilo: function() {
|
||
|
if (this.currentSelectedTile) {
|
||
|
if (this.checkPosition(this.currentSelectedTile)) {
|
||
|
if (this.checkResource('dirt', 5, true)) {
|
||
|
return this.currentSelectedTile.entity = new Silo;
|
||
|
} else {
|
||
|
return this.speechbubble.say('nores');
|
||
|
}
|
||
|
} else {
|
||
|
return this.speechbubble.say('toofar');
|
||
|
}
|
||
|
} else {
|
||
|
return this.speechbubble.say('nosel');
|
||
|
}
|
||
|
},
|
||
|
createSolarpanel: function() {
|
||
|
if (this.currentSelectedTile) {
|
||
|
if (this.checkPosition(this.currentSelectedTile)) {
|
||
|
if (this.checkResource('notch', 30, true)) {
|
||
|
return this.currentSelectedTile.entity = new Solarpanel;
|
||
|
} else {
|
||
|
return this.speechbubble.say('nores');
|
||
|
}
|
||
|
} else {
|
||
|
return this.speechbubble.say('toofar');
|
||
|
}
|
||
|
} else {
|
||
|
return this.speechbubble.say('nosel');
|
||
|
}
|
||
|
},
|
||
|
checkResource: function(type, amount, drain) {
|
||
|
if (drain == null) {
|
||
|
drain = false;
|
||
|
}
|
||
|
if (this.resources[type] >= amount) {
|
||
|
if (drain) {
|
||
|
this.resources[type] -= amount;
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
return false;
|
||
|
},
|
||
|
checkPosition: function(tile) {
|
||
|
var x, y, _ref;
|
||
|
if (tile.entity) {
|
||
|
return false;
|
||
|
}
|
||
|
_ref = posToXY(tile.position), x = _ref[0], y = _ref[1];
|
||
|
if (app.game.map[xyToPos(x - 1, y)].entity && app.game.map[xyToPos(x - 1, y)].entity.isDockable && x > 0) {
|
||
|
return true;
|
||
|
}
|
||
|
if (app.game.map[xyToPos(x + 1, y)].entity && app.game.map[xyToPos(x + 1, y)].entity.isDockable && x < 19) {
|
||
|
return true;
|
||
|
}
|
||
|
if (app.game.map[xyToPos(x, y - 1)].entity && app.game.map[xyToPos(x, y - 1)].entity.isDockable && y > 0) {
|
||
|
return true;
|
||
|
}
|
||
|
if (app.game.map[xyToPos(x, y + 1)].entity && app.game.map[xyToPos(x, y + 1)].entity.isDockable && y < 14) {
|
||
|
return true;
|
||
|
}
|
||
|
return false;
|
||
|
},
|
||
|
cheatah: function() {
|
||
|
var amount, type, _ref, _results;
|
||
|
_ref = this.resources;
|
||
|
_results = [];
|
||
|
for (type in _ref) {
|
||
|
amount = _ref[type];
|
||
|
_results.push(this.resources[type] = 100);
|
||
|
}
|
||
|
return _results;
|
||
|
},
|
||
|
map: [],
|
||
|
miners: [],
|
||
|
maxTileAmount: 75,
|
||
|
availableSiloStorage: function() {
|
||
|
var space, tile, _i, _len, _ref;
|
||
|
space = 0;
|
||
|
_ref = app.game.map;
|
||
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||
|
tile = _ref[_i];
|
||
|
if (tile.entity) {
|
||
|
space += tile.entity.spaceProvided;
|
||
|
}
|
||
|
}
|
||
|
return space;
|
||
|
},
|
||
|
usedSiloStorage: function() {
|
||
|
var amount, resource, space, _ref;
|
||
|
space = 0;
|
||
|
_ref = this.resources;
|
||
|
for (resource in _ref) {
|
||
|
amount = _ref[resource];
|
||
|
space += amount;
|
||
|
}
|
||
|
return space;
|
||
|
},
|
||
|
solarpanelCount: function() {
|
||
|
var energy, tile, _i, _len, _ref;
|
||
|
energy = 0;
|
||
|
_ref = app.game.map;
|
||
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||
|
tile = _ref[_i];
|
||
|
if (tile.entity && tile.entity.energyProvided > 10) {
|
||
|
energy += 1;
|
||
|
}
|
||
|
}
|
||
|
return energy;
|
||
|
},
|
||
|
gameEndCheck: function() {
|
||
|
if (this.solarpanelCount() >= 4) {
|
||
|
return true;
|
||
|
}
|
||
|
return false;
|
||
|
},
|
||
|
resources: {
|
||
|
stardust: 0,
|
||
|
dirt: 0,
|
||
|
bedrock: 0,
|
||
|
oxodum: 0,
|
||
|
lubinit: 0,
|
||
|
darkana: 0,
|
||
|
bio: 0,
|
||
|
notch: 0,
|
||
|
lava: 0
|
||
|
}
|
||
|
};
|
||
|
|
||
|
var __hasProp = {}.hasOwnProperty;
|
||
|
|
||
|
app.game.hud = {
|
||
|
start: function() {
|
||
|
var i, k, resTypes, restype, _i, _len, _results;
|
||
|
resTypes = (function() {
|
||
|
var _ref, _results;
|
||
|
_ref = app.game.resources;
|
||
|
_results = [];
|
||
|
for (k in _ref) {
|
||
|
if (!__hasProp.call(_ref, k)) continue;
|
||
|
_results.push(k);
|
||
|
}
|
||
|
return _results;
|
||
|
})();
|
||
|
this.position = {
|
||
|
x: 45,
|
||
|
y: 103
|
||
|
};
|
||
|
this.buildinfo = false;
|
||
|
this.itemArrow = new AnimatedItem({
|
||
|
maxFrames: 10,
|
||
|
image: app.images.actions,
|
||
|
speed: 50
|
||
|
});
|
||
|
this.resources = [];
|
||
|
_results = [];
|
||
|
for (i = _i = 0, _len = resTypes.length; _i < _len; i = ++_i) {
|
||
|
restype = resTypes[i];
|
||
|
_results.push(this.resources[restype] = new Tilelayer({
|
||
|
type: restype,
|
||
|
depth: i
|
||
|
}));
|
||
|
}
|
||
|
return _results;
|
||
|
},
|
||
|
render: function() {
|
||
|
var colorStep, currentSelectedTile, f, i, length, panelusage, resourcePanelColor, usedSiloStoragePercent, x, y, _i, _j;
|
||
|
panelusage = 'resources';
|
||
|
app.layer.drawImage(app.images.hud, 0, 11 * 8);
|
||
|
app.layer.drawImage(app.images.info, 143, 95);
|
||
|
if (this.buildinfo) {
|
||
|
app.layer.drawRegion(app.images.buildinfo, [0, 0, 106, 10], 1, 1);
|
||
|
app.layer.drawRegion(app.images.buildinfo, [0, 10, 106, 10], 1, 12);
|
||
|
app.layer.drawRegion(app.images.buildinfo, [0, 20, 106, 10], 1, 23);
|
||
|
app.layer.drawRegion(app.images.buildinfo, [0, 30, 106, 10], 1, 34);
|
||
|
}
|
||
|
currentSelectedTile = app.game.currentSelectedTile;
|
||
|
if (currentSelectedTile !== null) {
|
||
|
panelusage = 'tile';
|
||
|
if (currentSelectedTile.entity) {
|
||
|
panelusage = 'entity';
|
||
|
app.layer.drawRegion(app.images.entitydetails, currentSelectedTile.entity.spritedetail(), 12, 95);
|
||
|
} else {
|
||
|
app.layer.drawRegion(app.images.layerdetails, currentSelectedTile.getCurrentLayer().spritedetail, 12, 95);
|
||
|
}
|
||
|
}
|
||
|
usedSiloStoragePercent = Math.round((100 / app.game.availableSiloStorage()) * app.game.usedSiloStorage());
|
||
|
for (f = _i = 0; _i <= 100; f = ++_i) {
|
||
|
resourcePanelColor = "#333";
|
||
|
if (f <= usedSiloStoragePercent) {
|
||
|
colorStep = Math.round((usedSiloStoragePercent / 100) * 5);
|
||
|
resourcePanelColor = ["#0a0", "#0a0", "#aa0", "#f60", "#a00", "#f00"][colorStep];
|
||
|
}
|
||
|
x = 44 + f;
|
||
|
y = 112;
|
||
|
app.layer.setPixel(resourcePanelColor, x, y);
|
||
|
}
|
||
|
length = Math.round(((25 * app.game.solarpanelCount()) * 45) / 100);
|
||
|
for (i = _j = 0; 0 <= length ? _j <= length : _j >= length; i = 0 <= length ? ++_j : --_j) {
|
||
|
app.layer.setPixel("#228ca5", 49 + i, 91);
|
||
|
app.layer.setPixel("#8ddaed", 50 + i, 92);
|
||
|
app.layer.setPixel("#228ca5", 49 + i, 93);
|
||
|
}
|
||
|
switch (panelusage) {
|
||
|
case 'tile':
|
||
|
return this.showResources();
|
||
|
case 'entity':
|
||
|
if (currentSelectedTile.entity.isMoveable()) {
|
||
|
return app.layer.drawRegion(this.itemArrow.image, this.itemArrow.sprite(), 44, 102);
|
||
|
}
|
||
|
break;
|
||
|
case 'resources':
|
||
|
return this.showResources();
|
||
|
}
|
||
|
},
|
||
|
showBuildInfo: function() {
|
||
|
if (this.timeout) {
|
||
|
clearTimeout(this.timeout);
|
||
|
}
|
||
|
this.buildinfo = true;
|
||
|
return this.timeout = window.setTimeout(this.hideBuildInfo, 6000);
|
||
|
},
|
||
|
hideBuildInfo: function() {
|
||
|
return app.game.hud.buildinfo = false;
|
||
|
},
|
||
|
showResources: function() {
|
||
|
var amount, amountByTwenty, amountLeft, color, e, f, i, spritePosition, tileLayer, type, x, y, _i, _j, _ref, _results;
|
||
|
i = 0;
|
||
|
_ref = app.game.resources;
|
||
|
_results = [];
|
||
|
for (type in _ref) {
|
||
|
amount = _ref[type];
|
||
|
if (amount > 0) {
|
||
|
tileLayer = this.resources[type];
|
||
|
spritePosition = {
|
||
|
x: i * 9 + this.position.x,
|
||
|
y: this.position.y
|
||
|
};
|
||
|
app.layer.drawRegion(app.images.layers, tileLayer.hudSprite, spritePosition.x, spritePosition.y);
|
||
|
amountByTwenty = Math.floor(amount / 20);
|
||
|
amountLeft = amount - amountByTwenty * 20;
|
||
|
for (e = _i = 0; 0 <= amountLeft ? _i <= amountLeft : _i >= amountLeft; e = 0 <= amountLeft ? ++_i : --_i) {
|
||
|
color = "#0a0";
|
||
|
if (e === amountLeft) {
|
||
|
color = "#0f0";
|
||
|
}
|
||
|
if (e < 6) {
|
||
|
x = spritePosition.x - 1 + e;
|
||
|
y = spritePosition.y - 1;
|
||
|
} else if (e < 10) {
|
||
|
x = spritePosition.x + 4;
|
||
|
y = spritePosition.y - 1 + e - 5;
|
||
|
} else if (e < 15) {
|
||
|
x = spritePosition.x + 14 - e;
|
||
|
y = spritePosition.y + 4;
|
||
|
} else {
|
||
|
x = spritePosition.x - 1;
|
||
|
y = spritePosition.y + 19 - e;
|
||
|
}
|
||
|
app.layer.setPixel(color, x, y);
|
||
|
}
|
||
|
for (f = _j = 0; 0 <= amountByTwenty ? _j <= amountByTwenty : _j >= amountByTwenty; f = 0 <= amountByTwenty ? ++_j : --_j) {
|
||
|
if (f > 0) {
|
||
|
color = "#0000ff";
|
||
|
x = spritePosition.x - 2 + f;
|
||
|
y = spritePosition.y + 7;
|
||
|
app.layer.setPixel(color, x, y);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
_results.push(i++);
|
||
|
}
|
||
|
return _results;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
app.game.speechbubble = {
|
||
|
start: function() {
|
||
|
this.sprite = [0, 0, 27, 13];
|
||
|
return this.positioning = 'mouse';
|
||
|
},
|
||
|
setFix: function(x, y) {
|
||
|
this.x = x;
|
||
|
this.y = y;
|
||
|
return this.positioning = 'fixed';
|
||
|
},
|
||
|
setMouse: function() {
|
||
|
return this.positioning = 'mouse';
|
||
|
},
|
||
|
say: function(text, timeout) {
|
||
|
if (timeout == null) {
|
||
|
timeout = 1000;
|
||
|
}
|
||
|
if (this.timeout) {
|
||
|
clearTimeout(this.timeout);
|
||
|
}
|
||
|
switch (text) {
|
||
|
case 'help':
|
||
|
this.sprite = [0, 0, 27, 13];
|
||
|
break;
|
||
|
case 'toofar':
|
||
|
this.sprite = [0, 13, 90, 13];
|
||
|
break;
|
||
|
case 'nores':
|
||
|
this.sprite = [0, 26, 90, 13];
|
||
|
break;
|
||
|
case 'nosel':
|
||
|
this.sprite = [0, 39, 90, 13];
|
||
|
break;
|
||
|
case 'damn':
|
||
|
this.sprite = [0, 52, 90, 13];
|
||
|
break;
|
||
|
case 'need':
|
||
|
this.sprite = [0, 65, 90, 13];
|
||
|
break;
|
||
|
case 'collect':
|
||
|
this.sprite = [0, 78, 90, 13];
|
||
|
}
|
||
|
this.visible = true;
|
||
|
return this.timeout = window.setTimeout(this.hide, timeout);
|
||
|
},
|
||
|
hide: (function(_this) {
|
||
|
return function() {
|
||
|
return app.game.speechbubble.visible = false;
|
||
|
};
|
||
|
})(this),
|
||
|
render: function() {
|
||
|
var x, y;
|
||
|
switch (this.positioning) {
|
||
|
case 'mouse':
|
||
|
x = app.game.mouseX + 5;
|
||
|
y = app.game.mouseY - 15;
|
||
|
break;
|
||
|
case 'fixed':
|
||
|
x = this.x;
|
||
|
y = this.y;
|
||
|
}
|
||
|
if (this.visible) {
|
||
|
return app.layer.drawRegion(app.images.speechbubbles, this.sprite, x, y);
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImJhc2UuY29mZmVlIiwibWluZXIuY29mZmVlIiwic2lsby5jb2ZmZWUiLCJzb2xhcnBhbmVsLmNvZmZlZSIsImFuaW1hdGVkaXRlbS5jb2ZmZWUiLCJ0aWxlLmNvZmZlZSIsInRpbGVsYXllci5jb2ZmZWUiLCJ0b29scy5jb2ZmZWUiLCJhcHAu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