User prompt
put a score counter in the top center
User prompt
make it so when you hit the ball your score only goes up by one and when you die your score is reset and put the score counter in the top center
User prompt
only one ball
Code edit (1 edits merged)
Please save this source code
User prompt
Lava Paddle Panic
Initial prompt
paddle game where you hit a falling ball to get points and avoid the ball falling into the lava
/**** * 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) { // Random horizontal position self.x = Math.random() * 1800 + 124; self.y = 200; // Random horizontal speed self.speedX = (Math.random() * 8 - 4) * speedMultiplier; self.speedY = (Math.random() * 2 + 3) * 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 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; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x34495e }); /**** * Game Code ****/ // Game variables var paddle; var lava; var balls = []; var score = 0; var level = 1; var combo = 0; var lastBallHit = 0; var gameActive = true; 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, 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); // 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 paddle movement game.down = function (x, y, obj) { paddle.x = x; }; game.move = function (x, y, obj) { paddle.x = x; }; // Update function game.update = function () { 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) { // Calculate bounce angle based on where the ball hit the paddle var hitPos = (ball.x - paddle.x) / (paddle.width / 2); ball.speedX = hitPos * 8 * speedMultiplier; ball.speedY = -Math.abs(ball.speedY) - 0.5; // Move ball above paddle to prevent multiple collisions ball.y = paddle.y - paddle.height / 2 - 20; // Handle scoring var now = Date.now(); if (now - lastBallHit < 1500) { combo++; score += 10 * combo; comboTxt.setText('Combo x' + combo + '!'); comboTxt.alpha = 1; tween(comboTxt, { alpha: 0 }, { duration: 1500 }); } else { combo = 1; score += 10; } lastBallHit = now; // Update score scoreTxt.setText('Score: ' + score); LK.setScore(score); // Play bounce sound 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(); // 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 speedMultiplier += 0.1; maxBalls = 1; // Keep maxBalls at 1 } function gameOver() { gameActive = false; // Game over - let LK handle it LK.showGameOver(); } // Start the game function startGame() { // Reset variables score = 0; level = 1; combo = 0; lastBallHit = 0; gameActive = true; speedMultiplier = 1.0; 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 LK.playMusic('gameMusic', { fade: { start: 0, end: 0.6, duration: 1000 } }); } // Start the game startGame();
===================================================================
--- original.js
+++ change.js
@@ -80,9 +80,9 @@
var combo = 0;
var lastBallHit = 0;
var gameActive = true;
var speedMultiplier = 1.0;
-var maxBalls = 5;
+var maxBalls = 1;
var ballsInPlay = 0;
var spawnInterval;
// UI elements
var scoreTxt;
@@ -159,10 +159,10 @@
game.update = function () {
if (!gameActive) {
return;
}
- // Spawn a new ball periodically
- if (LK.ticks % Math.floor(60 / Math.min(level, 3)) === 0 && ballsInPlay < maxBalls) {
+ // Only create a ball if none exists
+ if (ballsInPlay === 0) {
createBall();
}
// Update paddle
paddle.update();
@@ -261,9 +261,9 @@
}
});
// Increase difficulty
speedMultiplier += 0.1;
- maxBalls = Math.min(10, maxBalls + 1);
+ maxBalls = 1; // Keep maxBalls at 1
}
function gameOver() {
gameActive = false;
// Game over - let LK handle it
@@ -289,9 +289,9 @@
for (var i = 0; i < balls.length; i++) {
balls[i].destroy();
}
balls = [];
- // Start spawning balls
+ // Start with one ball
createBall();
// Play music
LK.playMusic('gameMusic', {
fade: {