/**** * Classes ****/ //<Assets used in the game will automatically appear here> // FireBlock class var FireBlock = Container.expand(function () { var self = Container.call(this); var fireBlockGraphics = self.attachAsset('fireBlock', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // FireBlock specific update logic }; }); // WaterDrop class var WaterDrop = Container.expand(function () { var self = Container.call(this); var waterDropGraphics = self.attachAsset('waterDrop', { anchorX: 0.5, anchorY: 0.5 }); self.speed = -5; self.update = function () { self.y += self.speed; }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize arrays and variables var fireBlocks = []; var waterDrops = []; var score = 0; // Create score text var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Function to handle move events function handleMove(x, y, obj) { // Get event position in relation to game object if (dragNode) { dragNode.x = x; dragNode.y = y; } } // Mouse or touch down on the game object game.down = function (x, y, obj) { // Set drag node to the first fire block dragNode = fireBlocks[0]; handleMove(x, y, obj); }; // Mouse or touch up on the game object game.up = function (x, y, obj) { dragNode = null; }; // Game update function game.update = function () { // Update water drops for (var i = waterDrops.length - 1; i >= 0; i--) { if (waterDrops[i].y < -50) { waterDrops[i].destroy(); waterDrops.splice(i, 1); } } // Fire water drop if (LK.ticks % 30 == 0) { var newWaterDrop = new WaterDrop(); newWaterDrop.x = fireBlocks[0].x; newWaterDrop.y = fireBlocks[0].y; waterDrops.push(newWaterDrop); game.addChild(newWaterDrop); } }; // Initialize fire blocks for (var i = 0; i < 5; i++) { var fireBlock = new FireBlock(); fireBlock.x = 2048 / 2; fireBlock.y = 2732 / 2 + i * 150; fireBlocks.push(fireBlock); game.addChild(fireBlock); }
/****
* Classes
****/
//<Assets used in the game will automatically appear here>
// FireBlock class
var FireBlock = Container.expand(function () {
var self = Container.call(this);
var fireBlockGraphics = self.attachAsset('fireBlock', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// FireBlock specific update logic
};
});
// WaterDrop class
var WaterDrop = Container.expand(function () {
var self = Container.call(this);
var waterDropGraphics = self.attachAsset('waterDrop', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -5;
self.update = function () {
self.y += self.speed;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize arrays and variables
var fireBlocks = [];
var waterDrops = [];
var score = 0;
// Create score text
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Function to handle move events
function handleMove(x, y, obj) {
// Get event position in relation to game object
if (dragNode) {
dragNode.x = x;
dragNode.y = y;
}
}
// Mouse or touch down on the game object
game.down = function (x, y, obj) {
// Set drag node to the first fire block
dragNode = fireBlocks[0];
handleMove(x, y, obj);
};
// Mouse or touch up on the game object
game.up = function (x, y, obj) {
dragNode = null;
};
// Game update function
game.update = function () {
// Update water drops
for (var i = waterDrops.length - 1; i >= 0; i--) {
if (waterDrops[i].y < -50) {
waterDrops[i].destroy();
waterDrops.splice(i, 1);
}
}
// Fire water drop
if (LK.ticks % 30 == 0) {
var newWaterDrop = new WaterDrop();
newWaterDrop.x = fireBlocks[0].x;
newWaterDrop.y = fireBlocks[0].y;
waterDrops.push(newWaterDrop);
game.addChild(newWaterDrop);
}
};
// Initialize fire blocks
for (var i = 0; i < 5; i++) {
var fireBlock = new FireBlock();
fireBlock.x = 2048 / 2;
fireBlock.y = 2732 / 2 + i * 150;
fireBlocks.push(fireBlock);
game.addChild(fireBlock);
}