/**** * Classes ****/ //<Assets used in the game will automatically appear here> //<Write imports for supported plugins here> // Bubble class representing each bubble in the game var Bubble = Container.expand(function () { var self = Container.call(this); var bubbleGraphics = self.attachAsset('bubble', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Update logic for bubbles if needed }; }); // LevelMap class representing the level map var LevelMap = Container.expand(function () { var self = Container.call(this); self.levels = [ // Level 1 [{ x: 0, y: 0, bubble: new Bubble() }, { x: 100, y: 0, bubble: new Bubble() }, { x: 200, y: 0, bubble: new Bubble() } // Add more bubbles as needed ] // Add more levels as needed ]; self.currentLevel = 0; self.loadLevel = function (level) { // Clear old level for (var i = self.children.length - 1; i >= 0; i--) { self.children[i].destroy(); } // Load new level for (var i = 0; i < self.levels[level].length; i++) { var bubble = self.levels[level][i].bubble; bubble.x = self.levels[level][i].x; bubble.y = self.levels[level][i].y; self.addChild(bubble); } }; self.nextLevel = function () { if (self.currentLevel < self.levels.length - 1) { self.currentLevel++; self.loadLevel(self.currentLevel); } else { // Game over, player won LK.showGameOver(); } }; }); // Shooter class representing the bubble shooter var Shooter = Container.expand(function () { var self = Container.call(this); var shooterGraphics = self.attachAsset('shooter', { anchorX: 0.5, anchorY: 0.5 }); self.shoot = function () { // Logic to shoot a bubble var newBubble = new Bubble(); newBubble.x = self.x; newBubble.y = self.y; bubbles.push(newBubble); game.addChild(newBubble); }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize variables var levelMap = game.addChild(new LevelMap()); levelMap.loadLevel(0); var shooter = game.addChild(new Shooter()); shooter.x = 2048 / 2; shooter.y = 2732 - 100; // Position shooter near the bottom var bubbles = []; // Define the bubbles array // Function to handle shooting function handleShoot(x, y, obj) { shooter.shoot(); } // Event listener for shooting game.down = function (x, y, obj) { handleShoot(x, y, obj); }; // Update function called every frame game.update = function () { for (var i = levelMap.children.length - 1; i >= 0; i--) { levelMap.children[i].update(); // Check for collisions or out-of-bounds bubbles if (levelMap.children[i].y < 0) { levelMap.children[i].destroy(); } } // Check if level is complete if (levelMap.children.length == 0) { levelMap.nextLevel(); } }; // Add more game logic as needed
/****
* Classes
****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Bubble class representing each bubble in the game
var Bubble = Container.expand(function () {
var self = Container.call(this);
var bubbleGraphics = self.attachAsset('bubble', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Update logic for bubbles if needed
};
});
// LevelMap class representing the level map
var LevelMap = Container.expand(function () {
var self = Container.call(this);
self.levels = [
// Level 1
[{
x: 0,
y: 0,
bubble: new Bubble()
}, {
x: 100,
y: 0,
bubble: new Bubble()
}, {
x: 200,
y: 0,
bubble: new Bubble()
}
// Add more bubbles as needed
]
// Add more levels as needed
];
self.currentLevel = 0;
self.loadLevel = function (level) {
// Clear old level
for (var i = self.children.length - 1; i >= 0; i--) {
self.children[i].destroy();
}
// Load new level
for (var i = 0; i < self.levels[level].length; i++) {
var bubble = self.levels[level][i].bubble;
bubble.x = self.levels[level][i].x;
bubble.y = self.levels[level][i].y;
self.addChild(bubble);
}
};
self.nextLevel = function () {
if (self.currentLevel < self.levels.length - 1) {
self.currentLevel++;
self.loadLevel(self.currentLevel);
} else {
// Game over, player won
LK.showGameOver();
}
};
});
// Shooter class representing the bubble shooter
var Shooter = Container.expand(function () {
var self = Container.call(this);
var shooterGraphics = self.attachAsset('shooter', {
anchorX: 0.5,
anchorY: 0.5
});
self.shoot = function () {
// Logic to shoot a bubble
var newBubble = new Bubble();
newBubble.x = self.x;
newBubble.y = self.y;
bubbles.push(newBubble);
game.addChild(newBubble);
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize variables
var levelMap = game.addChild(new LevelMap());
levelMap.loadLevel(0);
var shooter = game.addChild(new Shooter());
shooter.x = 2048 / 2;
shooter.y = 2732 - 100; // Position shooter near the bottom
var bubbles = []; // Define the bubbles array
// Function to handle shooting
function handleShoot(x, y, obj) {
shooter.shoot();
}
// Event listener for shooting
game.down = function (x, y, obj) {
handleShoot(x, y, obj);
};
// Update function called every frame
game.update = function () {
for (var i = levelMap.children.length - 1; i >= 0; i--) {
levelMap.children[i].update();
// Check for collisions or out-of-bounds bubbles
if (levelMap.children[i].y < 0) {
levelMap.children[i].destroy();
}
}
// Check if level is complete
if (levelMap.children.length == 0) {
levelMap.nextLevel();
}
};
// Add more game logic as needed