User prompt
make all the text white
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'target')' in or related to this line: 'if (obj.event.target && obj.event.target.down) {' Line Number: 412
User prompt
make a menu that has the name of the game 'Lava Bounce 2' on the top of the screen and then a start game button that starts the game and then a settings menu for when clicked on a menu pops up that adjusts the colors of the paddle, ball, and lava ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
remove the hits text and keep the number there
User prompt
why is it still not there
User prompt
still not there
User prompt
still not there
User prompt
add a score counter that is in the center of the screen and counts how many times the ball has hit the paddle
User prompt
move the score counter to the center
User prompt
remove the start menu
User prompt
fix that
User prompt
well fix that
User prompt
when i click play the game does not start
User prompt
make the buttons clickable
User prompt
Please fix the bug: 'storage.getValue is not a function' in or related to this line: 'var soundSetting = storage.getValue('soundEnabled');' Line Number: 288 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
make a start menu where there is settings and a play button
User prompt
move the score counter to the top center of the screen\
User prompt
move the score counter to the center
User prompt
when the ball falls into the lava make it respawn in the top center
User prompt
when you die the screen flashes red ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
when you die start again right away, no delay
User prompt
make the ball go faster
User prompt
when the ball hits the paddle make the ball go in a random direction
User prompt
when the ball hits the paddle your score only goes up by one
User prompt
make the ball spawn in the center
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ var Ball = Container.expand(function () { var self = Container.call(this); var ballGraphic = self.attachAsset('ball', { anchorX: 0.5, anchorY: 0.5 }); self.speedX = 0; self.speedY = 0; self.active = true; self.reset = function (speedMultiplier) { // Set position to center of screen self.x = 2048 / 2; self.y = 2732 / 2; // Random horizontal speed with increased values self.speedX = (Math.random() * 12 - 6) * speedMultiplier; self.speedY = (Math.random() * 3 + 5) * speedMultiplier; self.active = true; }; self.update = function () { if (!self.active) { return; } // Apply velocity self.x += self.speedX; self.y += self.speedY; // Bounce off sides if (self.x < 20 || self.x > 2028) { self.speedX = -self.speedX; // Keep the ball within the game boundaries self.x = Math.max(20, Math.min(2028, self.x)); } // Check if ball hits the top of the screen if (self.y < 20) { self.speedY = -self.speedY; self.y = 20; } }; return self; }); var Menu = Container.expand(function () { var self = Container.call(this); // Menu background var menuBg = self.attachAsset('background', { anchorX: 0, anchorY: 0, alpha: 0.9 }); // Title text self.titleText = new Text2('PADDLE GAME', { size: 150, fill: 0xFFFFFF }); self.titleText.anchor.set(0.5, 0.5); self.titleText.x = 1024; self.titleText.y = 800; self.addChild(self.titleText); // Play button self.playButton = new Text2('PLAY', { size: 120, fill: 0x3498db }); self.playButton.anchor.set(0.5, 0.5); self.playButton.x = 1024; self.playButton.y = 1200; self.addChild(self.playButton); // Settings button self.settingsButton = new Text2('SETTINGS', { size: 120, fill: 0x3498db }); self.settingsButton.anchor.set(0.5, 0.5); self.settingsButton.x = 1024; self.settingsButton.y = 1400; self.addChild(self.settingsButton); // Button interactions self.playButton.interactive = true; self.settingsButton.interactive = true; // Handle button presses self.down = function (x, y, obj) { var local = self.toLocal({ x: x, y: y }); // Check if play button was pressed if (local.x > self.playButton.x - 200 && local.x < self.playButton.x + 200 && local.y > self.playButton.y - 60 && local.y < self.playButton.y + 60) { self.onPlay(); } // Check if settings button was pressed if (local.x > self.settingsButton.x - 200 && local.x < self.settingsButton.x + 200 && local.y > self.settingsButton.y - 60 && local.y < self.settingsButton.y + 60) { self.onSettings(); } }; // Method to be overridden self.onPlay = function () {}; self.onSettings = function () {}; // Hover effects self.update = function () { // Pulsing animation for buttons var pulse = Math.sin(LK.ticks / 20) * 0.1 + 1; self.playButton.scale.set(pulse); self.settingsButton.scale.set(pulse); }; return self; }); var Paddle = Container.expand(function () { var self = Container.call(this); var paddleGraphic = self.attachAsset('paddle', { anchorX: 0.5, anchorY: 0.5 }); self.width = paddleGraphic.width; self.height = paddleGraphic.height; self.update = function () { // Keep paddle within screen bounds self.x = Math.max(self.width / 2, Math.min(2048 - self.width / 2, self.x)); }; return self; }); var Settings = Container.expand(function () { var self = Container.call(this); // Settings background var settingsBg = self.attachAsset('background', { anchorX: 0, anchorY: 0, alpha: 0.9 }); // Title text self.titleText = new Text2('SETTINGS', { size: 120, fill: 0xFFFFFF }); self.titleText.anchor.set(0.5, 0.5); self.titleText.x = 1024; self.titleText.y = 600; self.addChild(self.titleText); // Music toggle self.musicText = new Text2('Music: ON', { size: 80, fill: 0x3498db }); self.musicText.anchor.set(0.5, 0.5); self.musicText.x = 1024; self.musicText.y = 900; self.addChild(self.musicText); // Sound toggle self.soundText = new Text2('Sound: ON', { size: 80, fill: 0x3498db }); self.soundText.anchor.set(0.5, 0.5); self.soundText.x = 1024; self.soundText.y = 1100; self.addChild(self.soundText); // Back button self.backButton = new Text2('BACK', { size: 100, fill: 0xe74c3c }); self.backButton.anchor.set(0.5, 0.5); self.backButton.x = 1024; self.backButton.y = 1400; self.addChild(self.backButton); // Settings state self.musicEnabled = true; self.soundEnabled = true; // Handle button presses self.down = function (x, y, obj) { var local = self.toLocal({ x: x, y: y }); // Check if music button was pressed if (local.x > self.musicText.x - 200 && local.x < self.musicText.x + 200 && local.y > self.musicText.y - 60 && local.y < self.musicText.y + 60) { self.musicEnabled = !self.musicEnabled; self.musicText.setText('Music: ' + (self.musicEnabled ? 'ON' : 'OFF')); if (self.musicEnabled) { LK.playMusic('gameMusic', { fade: { start: 0, end: 0.6, duration: 1000 } }); } else { LK.stopMusic(); } } // Check if sound button was pressed if (local.x > self.soundText.x - 200 && local.x < self.soundText.x + 200 && local.y > self.soundText.y - 60 && local.y < self.soundText.y + 60) { self.soundEnabled = !self.soundEnabled; self.soundText.setText('Sound: ' + (self.soundEnabled ? 'ON' : 'OFF')); // Store sound setting (used in game) storage.setValue('soundEnabled', self.soundEnabled); } // Check if back button was pressed if (local.x > self.backButton.x - 200 && local.x < self.backButton.x + 200 && local.y > self.backButton.y - 60 && local.y < self.backButton.y + 60) { self.onBack(); } }; // Method to be overridden self.onBack = function () {}; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x34495e }); /**** * Game Code ****/ // Game state management var GAME_STATE = { MENU: 0, PLAYING: 1, SETTINGS: 2 }; var currentState = GAME_STATE.MENU; // Menu objects var mainMenu; var settingsMenu; // Game variables var paddle; var lava; var balls = []; var score = 0; var level = 1; var combo = 0; var lastBallHit = 0; var gameActive = false; var speedMultiplier = 1.0; var maxBalls = 1; var ballsInPlay = 0; var spawnInterval; // UI elements var scoreTxt; var levelTxt; var comboTxt; // Initialize menu system function initializeMenuSystem() { // Create main menu mainMenu = new Menu(); mainMenu.onPlay = function () { currentState = GAME_STATE.PLAYING; mainMenu.visible = false; initializeGameElements(); startGame(); }; mainMenu.onSettings = function () { currentState = GAME_STATE.SETTINGS; mainMenu.visible = false; settingsMenu.visible = true; }; game.addChild(mainMenu); // Create settings menu (initially hidden) settingsMenu = new Settings(); settingsMenu.visible = false; settingsMenu.onBack = function () { currentState = GAME_STATE.MENU; settingsMenu.visible = false; mainMenu.visible = true; }; game.addChild(settingsMenu); // Load stored settings var soundSetting = storage.getValue('soundEnabled'); if (soundSetting !== null) { settingsMenu.soundEnabled = soundSetting; settingsMenu.soundText.setText('Sound: ' + (settingsMenu.soundEnabled ? 'ON' : 'OFF')); } } // Initialize game elements (called when starting game) function initializeGameElements() { if (!background) { // Create background background = LK.getAsset('background', { anchorX: 0, anchorY: 0, x: 0, y: 0 }); game.addChild(background); // Initialize lava lava = LK.getAsset('lava', { anchorX: 0.5, anchorY: 0, x: 2048 / 2, y: 2732 - 200 }); game.addChild(lava); // Initialize paddle paddle = new Paddle(); paddle.x = 2048 / 2; paddle.y = 2732 - 250; game.addChild(paddle); // Create score text scoreTxt = new Text2('Score: 0', { size: 80, fill: 0xFFFFFF }); scoreTxt.anchor.set(0, 0); scoreTxt.x = 50; scoreTxt.y = 50; LK.gui.addChild(scoreTxt); // Create level text levelTxt = new Text2('Level: 1', { size: 80, fill: 0xFFFFFF }); levelTxt.anchor.set(1, 0); levelTxt.x = 2000; levelTxt.y = 50; LK.gui.addChild(levelTxt); // Create combo text comboTxt = new Text2('', { size: 60, fill: 0xF39C12 }); comboTxt.anchor.set(0.5, 0); comboTxt.x = 1024; comboTxt.y = 50; comboTxt.alpha = 0; LK.gui.addChild(comboTxt); } // Show game elements background.visible = true; lava.visible = true; paddle.visible = true; scoreTxt.visible = true; levelTxt.visible = true; comboTxt.visible = true; } // Call menu initialization initializeMenuSystem(); // Initialize balls array function createBall() { if (ballsInPlay >= maxBalls || !gameActive) { return; } var ball = new Ball(); ball.reset(speedMultiplier); balls.push(ball); game.addChild(ball); ballsInPlay++; } // Handle input events based on current state game.down = function (x, y, obj) { if (currentState === GAME_STATE.PLAYING) { paddle.x = x; } else if (currentState === GAME_STATE.MENU) { mainMenu.down(x, y, obj); } else if (currentState === GAME_STATE.SETTINGS) { settingsMenu.down(x, y, obj); } }; game.move = function (x, y, obj) { if (currentState === GAME_STATE.PLAYING) { paddle.x = x; } }; // Update function game.update = function () { // Handle different game states if (currentState === GAME_STATE.MENU) { mainMenu.update(); return; } else if (currentState === GAME_STATE.SETTINGS) { return; } // Game play state if (!gameActive) { return; } // Only create a ball if none exists if (ballsInPlay === 0) { createBall(); } // Update paddle paddle.update(); // Update all balls for (var i = balls.length - 1; i >= 0; i--) { var ball = balls[i]; if (!ball.active) { continue; } ball.update(); // Check if ball hits paddle if (ball.speedY > 0 && ball.y + 20 >= paddle.y - paddle.height / 2 && ball.y - 20 <= paddle.y + paddle.height / 2 && ball.x + 20 >= paddle.x - paddle.width / 2 && ball.x - 20 <= paddle.x + paddle.width / 2) { // Make the ball go in a random direction var angle = Math.random() * Math.PI * 0.7 + Math.PI * 0.15; // Random angle between ~25 and ~155 degrees var speed = Math.sqrt(ball.speedX * ball.speedX + ball.speedY * ball.speedY); // Maintain speed magnitude speed = Math.max(speed, 5 * speedMultiplier); // Ensure minimum speed ball.speedX = Math.cos(angle) * speed * (Math.random() > 0.5 ? 1 : -1); // Random left or right direction ball.speedY = -Math.sin(angle) * speed; // Always go up // Move ball above paddle to prevent multiple collisions ball.y = paddle.y - paddle.height / 2 - 20; // Simple scoring - always add 1 point score += 1; // Hide combo text comboTxt.alpha = 0; // Update score scoreTxt.setText('Score: ' + score); LK.setScore(score); // Play bounce sound if enabled if (!settingsMenu || settingsMenu.soundEnabled) { LK.getSound('bounce').play(); } // Level up based on score if (score >= level * 100) { levelUp(); } } // Check if ball falls into lava if (ball.y > lava.y) { // Play lava sound if enabled if (!settingsMenu || settingsMenu.soundEnabled) { LK.getSound('lava').play(); } // Flash the lava tween(lava, { tint: 0xffffff }, { duration: 200, onFinish: function onFinish() { tween(lava, { tint: 0xe74c3c }, { duration: 200 }); } }); // Remove ball ball.active = false; ball.destroy(); balls.splice(i, 1); ballsInPlay--; // Check game over if (balls.length === 0 && ballsInPlay === 0) { gameOver(); } } } }; function levelUp() { level++; levelTxt.setText('Level: ' + level); // Show level up message var levelUpTxt = new Text2('LEVEL UP!', { size: 120, fill: 0x2ECC71 }); levelUpTxt.anchor.set(0.5, 0.5); levelUpTxt.x = 1024; levelUpTxt.y = 1366; LK.gui.addChild(levelUpTxt); // Animate level up message tween(levelUpTxt, { alpha: 0, scaleX: 2, scaleY: 2 }, { duration: 1000, onFinish: function onFinish() { levelUpTxt.destroy(); } }); // Increase difficulty with higher speed boost speedMultiplier += 0.25; // Increased from 0.1 for faster progression maxBalls = 1; // Keep maxBalls at 1 } function gameOver() { gameActive = false; // Flash the screen red to indicate death LK.effects.flashScreen(0xff0000, 1000); // Return to menu after a short delay LK.setTimeout(function () { // Hide game elements if (background) { background.visible = false; } if (lava) { lava.visible = false; } if (paddle) { paddle.visible = false; } if (scoreTxt) { scoreTxt.visible = false; } if (levelTxt) { levelTxt.visible = false; } if (comboTxt) { comboTxt.visible = false; } // Clear any remaining balls for (var i = 0; i < balls.length; i++) { balls[i].destroy(); } balls = []; ballsInPlay = 0; // Show menu currentState = GAME_STATE.MENU; mainMenu.visible = true; }, 1000); } // Start the game function startGame() { // Reset variables score = 0; level = 1; combo = 0; lastBallHit = 0; gameActive = true; speedMultiplier = 2.0; // Increased from 1.0 to make the ball faster maxBalls = 5; ballsInPlay = 0; // Update UI scoreTxt.setText('Score: 0'); levelTxt.setText('Level: 1'); comboTxt.setText(''); comboTxt.alpha = 0; // Clear any existing balls for (var i = 0; i < balls.length; i++) { balls[i].destroy(); } balls = []; // Start with one ball createBall(); // Play music if enabled if (!settingsMenu || settingsMenu.musicEnabled) { LK.playMusic('gameMusic', { fade: { start: 0, end: 0.6, duration: 1000 } }); } } // Game will start when player presses the Play button in the menu
===================================================================
--- original.js
+++ change.js
@@ -45,8 +45,73 @@
}
};
return self;
});
+var Menu = Container.expand(function () {
+ var self = Container.call(this);
+ // Menu background
+ var menuBg = self.attachAsset('background', {
+ anchorX: 0,
+ anchorY: 0,
+ alpha: 0.9
+ });
+ // Title text
+ self.titleText = new Text2('PADDLE GAME', {
+ size: 150,
+ fill: 0xFFFFFF
+ });
+ self.titleText.anchor.set(0.5, 0.5);
+ self.titleText.x = 1024;
+ self.titleText.y = 800;
+ self.addChild(self.titleText);
+ // Play button
+ self.playButton = new Text2('PLAY', {
+ size: 120,
+ fill: 0x3498db
+ });
+ self.playButton.anchor.set(0.5, 0.5);
+ self.playButton.x = 1024;
+ self.playButton.y = 1200;
+ self.addChild(self.playButton);
+ // Settings button
+ self.settingsButton = new Text2('SETTINGS', {
+ size: 120,
+ fill: 0x3498db
+ });
+ self.settingsButton.anchor.set(0.5, 0.5);
+ self.settingsButton.x = 1024;
+ self.settingsButton.y = 1400;
+ self.addChild(self.settingsButton);
+ // Button interactions
+ self.playButton.interactive = true;
+ self.settingsButton.interactive = true;
+ // Handle button presses
+ self.down = function (x, y, obj) {
+ var local = self.toLocal({
+ x: x,
+ y: y
+ });
+ // Check if play button was pressed
+ if (local.x > self.playButton.x - 200 && local.x < self.playButton.x + 200 && local.y > self.playButton.y - 60 && local.y < self.playButton.y + 60) {
+ self.onPlay();
+ }
+ // Check if settings button was pressed
+ if (local.x > self.settingsButton.x - 200 && local.x < self.settingsButton.x + 200 && local.y > self.settingsButton.y - 60 && local.y < self.settingsButton.y + 60) {
+ self.onSettings();
+ }
+ };
+ // Method to be overridden
+ self.onPlay = function () {};
+ self.onSettings = function () {};
+ // Hover effects
+ self.update = function () {
+ // Pulsing animation for buttons
+ var pulse = Math.sin(LK.ticks / 20) * 0.1 + 1;
+ self.playButton.scale.set(pulse);
+ self.settingsButton.scale.set(pulse);
+ };
+ return self;
+});
var Paddle = Container.expand(function () {
var self = Container.call(this);
var paddleGraphic = self.attachAsset('paddle', {
anchorX: 0.5,
@@ -59,8 +124,93 @@
self.x = Math.max(self.width / 2, Math.min(2048 - self.width / 2, self.x));
};
return self;
});
+var Settings = Container.expand(function () {
+ var self = Container.call(this);
+ // Settings background
+ var settingsBg = self.attachAsset('background', {
+ anchorX: 0,
+ anchorY: 0,
+ alpha: 0.9
+ });
+ // Title text
+ self.titleText = new Text2('SETTINGS', {
+ size: 120,
+ fill: 0xFFFFFF
+ });
+ self.titleText.anchor.set(0.5, 0.5);
+ self.titleText.x = 1024;
+ self.titleText.y = 600;
+ self.addChild(self.titleText);
+ // Music toggle
+ self.musicText = new Text2('Music: ON', {
+ size: 80,
+ fill: 0x3498db
+ });
+ self.musicText.anchor.set(0.5, 0.5);
+ self.musicText.x = 1024;
+ self.musicText.y = 900;
+ self.addChild(self.musicText);
+ // Sound toggle
+ self.soundText = new Text2('Sound: ON', {
+ size: 80,
+ fill: 0x3498db
+ });
+ self.soundText.anchor.set(0.5, 0.5);
+ self.soundText.x = 1024;
+ self.soundText.y = 1100;
+ self.addChild(self.soundText);
+ // Back button
+ self.backButton = new Text2('BACK', {
+ size: 100,
+ fill: 0xe74c3c
+ });
+ self.backButton.anchor.set(0.5, 0.5);
+ self.backButton.x = 1024;
+ self.backButton.y = 1400;
+ self.addChild(self.backButton);
+ // Settings state
+ self.musicEnabled = true;
+ self.soundEnabled = true;
+ // Handle button presses
+ self.down = function (x, y, obj) {
+ var local = self.toLocal({
+ x: x,
+ y: y
+ });
+ // Check if music button was pressed
+ if (local.x > self.musicText.x - 200 && local.x < self.musicText.x + 200 && local.y > self.musicText.y - 60 && local.y < self.musicText.y + 60) {
+ self.musicEnabled = !self.musicEnabled;
+ self.musicText.setText('Music: ' + (self.musicEnabled ? 'ON' : 'OFF'));
+ if (self.musicEnabled) {
+ LK.playMusic('gameMusic', {
+ fade: {
+ start: 0,
+ end: 0.6,
+ duration: 1000
+ }
+ });
+ } else {
+ LK.stopMusic();
+ }
+ }
+ // Check if sound button was pressed
+ if (local.x > self.soundText.x - 200 && local.x < self.soundText.x + 200 && local.y > self.soundText.y - 60 && local.y < self.soundText.y + 60) {
+ self.soundEnabled = !self.soundEnabled;
+ self.soundText.setText('Sound: ' + (self.soundEnabled ? 'ON' : 'OFF'));
+ // Store sound setting (used in game)
+ storage.setValue('soundEnabled', self.soundEnabled);
+ }
+ // Check if back button was pressed
+ if (local.x > self.backButton.x - 200 && local.x < self.backButton.x + 200 && local.y > self.backButton.y - 60 && local.y < self.backButton.y + 60) {
+ self.onBack();
+ }
+ };
+ // Method to be overridden
+ self.onBack = function () {};
+ return self;
+});
/****
* Initialize Game
****/
@@ -70,74 +220,130 @@
/****
* Game Code
****/
+// Game state management
+var GAME_STATE = {
+ MENU: 0,
+ PLAYING: 1,
+ SETTINGS: 2
+};
+var currentState = GAME_STATE.MENU;
+// Menu objects
+var mainMenu;
+var settingsMenu;
// Game variables
var paddle;
var lava;
var balls = [];
var score = 0;
var level = 1;
var combo = 0;
var lastBallHit = 0;
-var gameActive = true;
+var gameActive = false;
var speedMultiplier = 1.0;
var maxBalls = 1;
var ballsInPlay = 0;
var spawnInterval;
// UI elements
var scoreTxt;
var levelTxt;
var comboTxt;
-// Create background
-var background = LK.getAsset('background', {
- anchorX: 0,
- anchorY: 0,
- x: 0,
- y: 0
-});
-game.addChild(background);
-// Initialize lava
-lava = LK.getAsset('lava', {
- anchorX: 0.5,
- anchorY: 0,
- x: 2048 / 2,
- y: 2732 - 200
-});
-game.addChild(lava);
-// Initialize paddle
-paddle = new Paddle();
-paddle.x = 2048 / 2;
-paddle.y = 2732 - 250;
-game.addChild(paddle);
-// Create score text
-scoreTxt = new Text2('Score: 0', {
- size: 80,
- fill: 0xFFFFFF
-});
-scoreTxt.anchor.set(0.5, 0);
-scoreTxt.x = 1024;
-scoreTxt.y = 50;
-LK.gui.top.addChild(scoreTxt);
-// Create level text
-levelTxt = new Text2('Level: 1', {
- size: 80,
- fill: 0xFFFFFF
-});
-levelTxt.anchor.set(1, 0);
-levelTxt.x = 2000;
-levelTxt.y = 50;
-LK.gui.addChild(levelTxt);
-// Create combo text
-comboTxt = new Text2('', {
- size: 60,
- fill: 0xF39C12
-});
-comboTxt.anchor.set(0.5, 0);
-comboTxt.x = 1024;
-comboTxt.y = 50;
-comboTxt.alpha = 0;
-LK.gui.addChild(comboTxt);
+// Initialize menu system
+function initializeMenuSystem() {
+ // Create main menu
+ mainMenu = new Menu();
+ mainMenu.onPlay = function () {
+ currentState = GAME_STATE.PLAYING;
+ mainMenu.visible = false;
+ initializeGameElements();
+ startGame();
+ };
+ mainMenu.onSettings = function () {
+ currentState = GAME_STATE.SETTINGS;
+ mainMenu.visible = false;
+ settingsMenu.visible = true;
+ };
+ game.addChild(mainMenu);
+ // Create settings menu (initially hidden)
+ settingsMenu = new Settings();
+ settingsMenu.visible = false;
+ settingsMenu.onBack = function () {
+ currentState = GAME_STATE.MENU;
+ settingsMenu.visible = false;
+ mainMenu.visible = true;
+ };
+ game.addChild(settingsMenu);
+ // Load stored settings
+ var soundSetting = storage.getValue('soundEnabled');
+ if (soundSetting !== null) {
+ settingsMenu.soundEnabled = soundSetting;
+ settingsMenu.soundText.setText('Sound: ' + (settingsMenu.soundEnabled ? 'ON' : 'OFF'));
+ }
+}
+// Initialize game elements (called when starting game)
+function initializeGameElements() {
+ if (!background) {
+ // Create background
+ background = LK.getAsset('background', {
+ anchorX: 0,
+ anchorY: 0,
+ x: 0,
+ y: 0
+ });
+ game.addChild(background);
+ // Initialize lava
+ lava = LK.getAsset('lava', {
+ anchorX: 0.5,
+ anchorY: 0,
+ x: 2048 / 2,
+ y: 2732 - 200
+ });
+ game.addChild(lava);
+ // Initialize paddle
+ paddle = new Paddle();
+ paddle.x = 2048 / 2;
+ paddle.y = 2732 - 250;
+ game.addChild(paddle);
+ // Create score text
+ scoreTxt = new Text2('Score: 0', {
+ size: 80,
+ fill: 0xFFFFFF
+ });
+ scoreTxt.anchor.set(0, 0);
+ scoreTxt.x = 50;
+ scoreTxt.y = 50;
+ LK.gui.addChild(scoreTxt);
+ // Create level text
+ levelTxt = new Text2('Level: 1', {
+ size: 80,
+ fill: 0xFFFFFF
+ });
+ levelTxt.anchor.set(1, 0);
+ levelTxt.x = 2000;
+ levelTxt.y = 50;
+ LK.gui.addChild(levelTxt);
+ // Create combo text
+ comboTxt = new Text2('', {
+ size: 60,
+ fill: 0xF39C12
+ });
+ comboTxt.anchor.set(0.5, 0);
+ comboTxt.x = 1024;
+ comboTxt.y = 50;
+ comboTxt.alpha = 0;
+ LK.gui.addChild(comboTxt);
+ }
+ // Show game elements
+ background.visible = true;
+ lava.visible = true;
+ paddle.visible = true;
+ scoreTxt.visible = true;
+ levelTxt.visible = true;
+ comboTxt.visible = true;
+}
+// Call menu initialization
+initializeMenuSystem();
// Initialize balls array
function createBall() {
if (ballsInPlay >= maxBalls || !gameActive) {
return;
@@ -147,17 +353,33 @@
balls.push(ball);
game.addChild(ball);
ballsInPlay++;
}
-// Handle paddle movement
+// Handle input events based on current state
game.down = function (x, y, obj) {
- paddle.x = x;
+ if (currentState === GAME_STATE.PLAYING) {
+ paddle.x = x;
+ } else if (currentState === GAME_STATE.MENU) {
+ mainMenu.down(x, y, obj);
+ } else if (currentState === GAME_STATE.SETTINGS) {
+ settingsMenu.down(x, y, obj);
+ }
};
game.move = function (x, y, obj) {
- paddle.x = x;
+ if (currentState === GAME_STATE.PLAYING) {
+ paddle.x = x;
+ }
};
// Update function
game.update = function () {
+ // Handle different game states
+ if (currentState === GAME_STATE.MENU) {
+ mainMenu.update();
+ return;
+ } else if (currentState === GAME_STATE.SETTINGS) {
+ return;
+ }
+ // Game play state
if (!gameActive) {
return;
}
// Only create a ball if none exists
@@ -189,19 +411,23 @@
comboTxt.alpha = 0;
// Update score
scoreTxt.setText('Score: ' + score);
LK.setScore(score);
- // Play bounce sound
- LK.getSound('bounce').play();
+ // Play bounce sound if enabled
+ if (!settingsMenu || settingsMenu.soundEnabled) {
+ LK.getSound('bounce').play();
+ }
// Level up based on score
if (score >= level * 100) {
levelUp();
}
}
// Check if ball falls into lava
if (ball.y > lava.y) {
- // Play lava sound
- LK.getSound('lava').play();
+ // Play lava sound if enabled
+ if (!settingsMenu || settingsMenu.soundEnabled) {
+ LK.getSound('lava').play();
+ }
// Flash the lava
tween(lava, {
tint: 0xffffff
}, {
@@ -213,15 +439,17 @@
duration: 200
});
}
});
- // Flash the screen red to indicate death
- LK.effects.flashScreen(0xff0000, 500);
- // Respawn ball at top center
- ball.x = 2048 / 2;
- ball.y = 100;
- ball.speedY = 5 * speedMultiplier; // Move downwards
- ball.speedX = (Math.random() * 12 - 6) * speedMultiplier; // Random horizontal direction
+ // Remove ball
+ ball.active = false;
+ ball.destroy();
+ balls.splice(i, 1);
+ ballsInPlay--;
+ // Check game over
+ if (balls.length === 0 && ballsInPlay === 0) {
+ gameOver();
+ }
}
}
};
function levelUp() {
@@ -254,10 +482,39 @@
function gameOver() {
gameActive = false;
// Flash the screen red to indicate death
LK.effects.flashScreen(0xff0000, 1000);
- // Restart the game immediately instead of showing game over
- startGame();
+ // Return to menu after a short delay
+ LK.setTimeout(function () {
+ // Hide game elements
+ if (background) {
+ background.visible = false;
+ }
+ if (lava) {
+ lava.visible = false;
+ }
+ if (paddle) {
+ paddle.visible = false;
+ }
+ if (scoreTxt) {
+ scoreTxt.visible = false;
+ }
+ if (levelTxt) {
+ levelTxt.visible = false;
+ }
+ if (comboTxt) {
+ comboTxt.visible = false;
+ }
+ // Clear any remaining balls
+ for (var i = 0; i < balls.length; i++) {
+ balls[i].destroy();
+ }
+ balls = [];
+ ballsInPlay = 0;
+ // Show menu
+ currentState = GAME_STATE.MENU;
+ mainMenu.visible = true;
+ }, 1000);
}
// Start the game
function startGame() {
// Reset variables
@@ -280,15 +537,16 @@
}
balls = [];
// Start with one ball
createBall();
- // Play music
- LK.playMusic('gameMusic', {
- fade: {
- start: 0,
- end: 0.6,
- duration: 1000
- }
- });
+ // Play music if enabled
+ if (!settingsMenu || settingsMenu.musicEnabled) {
+ LK.playMusic('gameMusic', {
+ fade: {
+ start: 0,
+ end: 0.6,
+ duration: 1000
+ }
+ });
+ }
}
-// Start the game
-startGame();
\ No newline at end of file
+// Game will start when player presses the Play button in the menu
\ No newline at end of file