/**** * Classes ****/ //<Assets used in the game will automatically appear here> //<Write imports for supported plugins here> // TNT class representing the explosive object var TNT = Container.expand(function () { var self = Container.call(this); var tntGraphics = self.attachAsset('tnt', { anchorX: 0.5, anchorY: 0.5 }); self.exploded = false; // Method to trigger explosion self.explode = function () { if (!self.exploded) { self.exploded = true; LK.effects.flashObject(self, 0xff0000, 500); // Flash red to indicate explosion self.destroy(); // Remove TNT after explosion } }; }); // Target class representing objects to be destroyed var Target = Container.expand(function () { var self = Container.call(this); var targetGraphics = self.attachAsset('target', { anchorX: 0.5, anchorY: 0.5 }); // Method to destroy target self.destroyTarget = function () { LK.effects.flashObject(self, 0x00ff00, 500); // Flash green to indicate destruction self.destroy(); }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize arrays to keep track of TNTs and targets var tnts = []; var targets = []; // Function to handle TNT placement function placeTNT(x, y) { var newTNT = new TNT(); newTNT.x = x; newTNT.y = y; tnts.push(newTNT); game.addChild(newTNT); } // Function to handle chain reactions function triggerChainReaction() { tnts.forEach(function (tnt) { if (tnt.exploded) return; tnt.explode(); targets.forEach(function (target) { if (tnt.intersects(target)) { target.destroyTarget(); } }); }); } // Initialize some targets for (var i = 0; i < 5; i++) { var target = new Target(); target.x = Math.random() * 2048; target.y = Math.random() * 2732; targets.push(target); game.addChild(target); } // Handle game touch events for placing TNT game.down = function (x, y, obj) { placeTNT(x, y); }; // Update function to check for chain reactions game.update = function () { if (LK.ticks % 60 == 0) { // Check every second triggerChainReaction(); } };
/****
* Classes
****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// TNT class representing the explosive object
var TNT = Container.expand(function () {
var self = Container.call(this);
var tntGraphics = self.attachAsset('tnt', {
anchorX: 0.5,
anchorY: 0.5
});
self.exploded = false;
// Method to trigger explosion
self.explode = function () {
if (!self.exploded) {
self.exploded = true;
LK.effects.flashObject(self, 0xff0000, 500); // Flash red to indicate explosion
self.destroy(); // Remove TNT after explosion
}
};
});
// Target class representing objects to be destroyed
var Target = Container.expand(function () {
var self = Container.call(this);
var targetGraphics = self.attachAsset('target', {
anchorX: 0.5,
anchorY: 0.5
});
// Method to destroy target
self.destroyTarget = function () {
LK.effects.flashObject(self, 0x00ff00, 500); // Flash green to indicate destruction
self.destroy();
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize arrays to keep track of TNTs and targets
var tnts = [];
var targets = [];
// Function to handle TNT placement
function placeTNT(x, y) {
var newTNT = new TNT();
newTNT.x = x;
newTNT.y = y;
tnts.push(newTNT);
game.addChild(newTNT);
}
// Function to handle chain reactions
function triggerChainReaction() {
tnts.forEach(function (tnt) {
if (tnt.exploded) return;
tnt.explode();
targets.forEach(function (target) {
if (tnt.intersects(target)) {
target.destroyTarget();
}
});
});
}
// Initialize some targets
for (var i = 0; i < 5; i++) {
var target = new Target();
target.x = Math.random() * 2048;
target.y = Math.random() * 2732;
targets.push(target);
game.addChild(target);
}
// Handle game touch events for placing TNT
game.down = function (x, y, obj) {
placeTNT(x, y);
};
// Update function to check for chain reactions
game.update = function () {
if (LK.ticks % 60 == 0) {
// Check every second
triggerChainReaction();
}
};