/**** 
* Classes
****/ 
// Face class representing the faces
var Face = Container.expand(function () {
	var self = Container.call(this);
	var faceGraphics = self.attachAsset('face', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	// Set initial speed for the face
	self.speedX = Math.random() * 10 - 5;
	self.speedY = Math.random() * 10 - 5;
	// Update function to move the face
	self.update = function () {
		self.x += self.speedX;
		self.y += self.speedY;
		// Check for collision with screen boundaries and reverse direction
		if (self.x < 0 || self.x > 2048) {
			self.speedX *= -1;
		}
		if (self.y < 0 || self.y > 2732) {
			self.speedY *= -1;
		}
	};
});
// MrBeastCommand class representing Mr. Beast's command phases
var MrBeastCommand = Container.expand(function () {
	var self = Container.call(this);
});
//<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, faces and MrBeastCommand instances
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);
	// Create a new Face instance
	var face = new Face();
	face.x = Math.random() * 2048;
	face.y = Math.random() * 2732;
	game.addChild(face);
	// Create a new MrBeastCommand instance
	var command = new MrBeastCommand();
	// Set the position and other properties of the command
	// This is just a placeholder and should be replaced with actual code
	game.addChild(command);
}
// 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
****/ 
// Face class representing the faces
var Face = Container.expand(function () {
	var self = Container.call(this);
	var faceGraphics = self.attachAsset('face', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	// Set initial speed for the face
	self.speedX = Math.random() * 10 - 5;
	self.speedY = Math.random() * 10 - 5;
	// Update function to move the face
	self.update = function () {
		self.x += self.speedX;
		self.y += self.speedY;
		// Check for collision with screen boundaries and reverse direction
		if (self.x < 0 || self.x > 2048) {
			self.speedX *= -1;
		}
		if (self.y < 0 || self.y > 2732) {
			self.speedY *= -1;
		}
	};
});
// MrBeastCommand class representing Mr. Beast's command phases
var MrBeastCommand = Container.expand(function () {
	var self = Container.call(this);
});
//<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, faces and MrBeastCommand instances
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);
	// Create a new Face instance
	var face = new Face();
	face.x = Math.random() * 2048;
	face.y = Math.random() * 2732;
	game.addChild(face);
	// Create a new MrBeastCommand instance
	var command = new MrBeastCommand();
	// Set the position and other properties of the command
	// This is just a placeholder and should be replaced with actual code
	game.addChild(command);
}
// 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();
	}
};