/****
* Classes
****/
var BoostButton = Container.expand(function () {
var self = Container.call(this);
self.interactive = true;
self.buttonMode = true;
self.text = new Text2('', {
size: 50,
fill: '#ffffff'
});
self.addChild(self.text);
self.on('down', function () {
if (self.callback) {
self.callback();
}
});
self.setLabel = function (label) {
self.text.setText(label);
self.text.x = (self.width - self.text.width) / 2;
self.text.y = (self.height - self.text.height) / 2;
};
self.setCallback = function (callback) {
self.callback = callback;
};
});
var Octopus = Container.expand(function () {
var self = Container.call(this);
var octopusGraphics = self.attachAsset('octopus', {
anchorX: 0.5,
anchorY: 0.5
});
self.x = 2048 / 2;
self.y = 2732 / 2;
self.on('down', function (obj) {
var pos = obj.event.getLocalPosition(game);
self.emitFish(pos.x, pos.y);
});
self.fishBoost = 1;
self.emitFish = function (x, y) {
// Emit fish from the point where the octopus was clicked
for (var i = 0; i < self.fishBoost; i++) {
var angle = Math.random() * Math.PI * 2;
var speed = 5 + Math.random() * 5;
var fish = new Fish();
fish.x = x;
fish.y = y;
fish.speedX = Math.cos(angle) * speed;
fish.speedY = Math.sin(angle) * speed;
game.addChild(fish);
}
// Update the score counter
LK.setScore(LK.getScore() + self.fishBoost);
scoreTxt.setText(LK.getScore());
};
});
var Fish = Container.expand(function () {
var self = Container.call(this);
var fishGraphics = self.attachAsset('fish', {
anchorX: 0.5,
anchorY: 0.5
});
self.speedX = 0;
self.speedY = 0;
self.move = function () {
self.x += self.speedX;
self.y += self.speedY;
// Remove fish if it goes off screen
if (self.x < 0 || self.x > 2048 || self.y < 0 || self.y > 2732) {
self.destroy();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1099bb //Init game with blue background
});
/****
* Game Code
****/
/****var MenuBar = Container.expand(function () {
var self = Container.call(this);
self.y = 2732 - 100;
self.width = 2048;
self.height = 100;
self.interactive = true;
self.buttonMode = true;
var gameSettingsButton = new BoostButton();
gameSettingsButton.setLabel('Game Settings');
gameSettingsButton.setCallback(function () {
// TODO: Implement game settings
});
self.addChild(gameSettingsButton);
var octopusBoostButton = new BoostButton();
octopusBoostButton.setLabel('Octopus Boost');
octopusBoostButton.setCallback(function () {
// Increase the fish boost multiplier
octopus.fishBoost++;
});
octopusBoostButton.x = 2048 / 3;
self.addChild(octopusBoostButton);
var fishGrowthBoostButton = new BoostButton();
fishGrowthBoostButton.setLabel('Fish Growth Boost');
fishGrowthBoostButton.setCallback(function () {
// TODO: Implement fish growth boost
});
fishGrowthBoostButton.x = 2048 / 3 * 2;
self.addChild(fishGrowthBoostButton);
var autoClickBoostButton = new BoostButton();
autoClickBoostButton.setLabel('Auto-Click Boost');
autoClickBoostButton.setCallback(function () {
// TODO: Implement auto-click boost
});
autoClickBoostButton.x = 2048;
self.addChild(autoClickBoostButton);
});
var menuBar = new MenuBar();
LK.gui.bottom.addChild(menuBar);
* Assets
****/
var scoreTxt = new Text2('0', {
size: 150,
fill: '#ffffff'
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var octopus = game.addChild(new Octopus());
LK.on('tick', function () {
// Update all fish
var children = game.children.slice(); // Copy array as it may be modified during iteration
for (var i = 0; i < children.length; i++) {
if (children[i] instanceof Fish) {
children[i].move();
}
}
});