User prompt
Undo the lava waves
User prompt
Make the waves on the lava bigger
User prompt
Make the lava have waves and move
User prompt
Make the score count in the center of screen
User prompt
Make the ball bounce in a random direction when it hits the paddle
User prompt
Make it so when the ball touches the paddle particles come out of the paddle
User prompt
make the ball bounce higher when it hits the paddle āŖš” Consider importing and using the following plugins: @upit/tween.v1
Code edit (1 edits merged)
Please save this source code
User prompt
Lava Bounce
Initial prompt
hey, can you make a game where there is a ball and a paddle and the ball falls down and if it hits the paddle the ball bounces up and you get one point and there lava at the bottom of the screen and if the ball touches the lava your points get reset
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1", {
highScore: 0
});
/****
* Classes
****/
var Ball = Container.expand(function () {
var self = Container.call(this);
var ballGraphics = self.attachAsset('ball', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = ballGraphics.width;
self.height = ballGraphics.height;
self.speedY = 5;
self.speedX = 0;
self.gravity = 0.2;
self.maxSpeed = 15;
self.reset = function () {
self.x = 2048 / 2;
self.y = 500;
self.speedY = 5;
self.speedX = Math.random() * 6 - 3;
};
self.update = function () {
// Apply gravity
self.speedY += self.gravity;
// Cap max speed
if (self.speedY > self.maxSpeed) {
self.speedY = self.maxSpeed;
}
// Update position
self.x += self.speedX;
self.y += self.speedY;
// Bounce off walls
if (self.x < self.width / 2) {
self.x = self.width / 2;
self.speedX = -self.speedX;
} else if (self.x > 2048 - self.width / 2) {
self.x = 2048 - self.width / 2;
self.speedX = -self.speedX;
}
};
return self;
});
var Lava = Container.expand(function () {
var self = Container.call(this);
var lavaGraphics = self.attachAsset('lava', {
anchorX: 0.5,
anchorY: 0.5
});
// Create a pulsing effect for the lava
self.pulse = function () {
tween(lavaGraphics, {
alpha: 0.7
}, {
duration: 800,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(lavaGraphics, {
alpha: 1
}, {
duration: 800,
easing: tween.easeInOut,
onFinish: self.pulse
});
}
});
};
self.pulse();
return self;
});
var Paddle = Container.expand(function () {
var self = Container.call(this);
var paddleGraphics = self.attachAsset('paddle', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = paddleGraphics.width;
self.height = paddleGraphics.height;
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x220000
});
/****
* Game Code
****/
// Game variables
var score = 0;
var highScore = storage.highScore || 0;
var difficulty = 1;
var difficultyIncreaseTimer = null;
// Create game objects
var paddle = new Paddle();
var ball = new Ball();
var lava = new Lava();
// Initialize paddle position
paddle.x = 2048 / 2;
paddle.y = 2732 - 300;
// Initialize ball position
ball.reset();
// Initialize lava position
lava.x = 2048 / 2;
lava.y = 2732 - 100;
// Add objects to game
game.addChild(paddle);
game.addChild(ball);
game.addChild(lava);
// Create score display
var scoreTxt = new Text2('Score: 0', {
size: 60,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0, 0);
LK.gui.topRight.addChild(scoreTxt);
// Create high score display
var highScoreTxt = new Text2('High Score: 0', {
size: 40,
fill: 0xFFBD00
});
highScoreTxt.anchor.set(1, 0);
highScoreTxt.setText('High Score: ' + highScore);
highScoreTxt.y = 70;
LK.gui.topRight.addChild(highScoreTxt);
// Touch/drag handling for paddle movement
var isDragging = false;
game.down = function (x, y, obj) {
isDragging = true;
paddle.x = x;
};
game.move = function (x, y, obj) {
if (isDragging) {
paddle.x = x;
// Clamp paddle position to keep it within screen bounds
if (paddle.x < paddle.width / 2) {
paddle.x = paddle.width / 2;
} else if (paddle.x > 2048 - paddle.width / 2) {
paddle.x = 2048 - paddle.width / 2;
}
}
};
game.up = function (x, y, obj) {
isDragging = false;
};
// Function to update score display
function updateScore() {
scoreTxt.setText('Score: ' + score);
// Update high score if current score is higher
if (score > highScore) {
highScore = score;
storage.highScore = highScore;
highScoreTxt.setText('High Score: ' + highScore);
}
}
// Function to increase difficulty over time
function increaseDifficulty() {
difficulty += 0.2;
// Cap maximum difficulty
if (difficulty > 3) {
difficulty = 3;
LK.clearInterval(difficultyIncreaseTimer);
}
// Update ball properties based on difficulty
ball.gravity = 0.2 * difficulty;
ball.maxSpeed = 15 * difficulty;
}
// Start difficulty increase timer
difficultyIncreaseTimer = LK.setInterval(increaseDifficulty, 10000);
// Play background music
LK.playMusic('gameMusic', {
fade: {
start: 0,
end: 0.5,
duration: 1000
}
});
// Game update loop
game.update = function () {
// Update ball position
ball.update();
// Check for collision with paddle
if (ball.speedY > 0 && ball.y + ball.height / 2 >= paddle.y - paddle.height / 2 && ball.y - ball.height / 2 <= paddle.y + paddle.height / 2 && ball.x + ball.width / 2 >= paddle.x - paddle.width / 2 && ball.x - ball.width / 2 <= paddle.x + paddle.width / 2) {
// Bounce the ball
ball.speedY = -ball.speedY * 0.8;
// Add horizontal velocity based on where the ball hit the paddle
var hitPosition = (ball.x - paddle.x) / (paddle.width / 2);
ball.speedX = hitPosition * 8;
// Flash paddle to indicate hit
LK.effects.flashObject(paddle, 0xffffff, 200);
// Play bounce sound
LK.getSound('bounce').play();
// Increment score
score++;
updateScore();
}
// Check if ball touches lava
if (ball.y + ball.height / 2 >= lava.y - lava.height / 2) {
// Play lava hit sound
LK.getSound('lava_hit').play();
// Flash screen red
LK.effects.flashScreen(0xff0000, 500);
// Reset score
score = 0;
updateScore();
// Reset ball
ball.reset();
// Reset difficulty
difficulty = 1;
ball.gravity = 0.2;
ball.maxSpeed = 15;
// Restart difficulty increase timer
LK.clearInterval(difficultyIncreaseTimer);
difficultyIncreaseTimer = LK.setInterval(increaseDifficulty, 10000);
}
// If ball goes too high, change direction
if (ball.y < 100) {
ball.speedY = Math.abs(ball.speedY) * 0.5;
}
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,230 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+var storage = LK.import("@upit/storage.v1", {
+ highScore: 0
+});
+
+/****
+* Classes
+****/
+var Ball = Container.expand(function () {
+ var self = Container.call(this);
+ var ballGraphics = self.attachAsset('ball', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.width = ballGraphics.width;
+ self.height = ballGraphics.height;
+ self.speedY = 5;
+ self.speedX = 0;
+ self.gravity = 0.2;
+ self.maxSpeed = 15;
+ self.reset = function () {
+ self.x = 2048 / 2;
+ self.y = 500;
+ self.speedY = 5;
+ self.speedX = Math.random() * 6 - 3;
+ };
+ self.update = function () {
+ // Apply gravity
+ self.speedY += self.gravity;
+ // Cap max speed
+ if (self.speedY > self.maxSpeed) {
+ self.speedY = self.maxSpeed;
+ }
+ // Update position
+ self.x += self.speedX;
+ self.y += self.speedY;
+ // Bounce off walls
+ if (self.x < self.width / 2) {
+ self.x = self.width / 2;
+ self.speedX = -self.speedX;
+ } else if (self.x > 2048 - self.width / 2) {
+ self.x = 2048 - self.width / 2;
+ self.speedX = -self.speedX;
+ }
+ };
+ return self;
+});
+var Lava = Container.expand(function () {
+ var self = Container.call(this);
+ var lavaGraphics = self.attachAsset('lava', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Create a pulsing effect for the lava
+ self.pulse = function () {
+ tween(lavaGraphics, {
+ alpha: 0.7
+ }, {
+ duration: 800,
+ easing: tween.easeInOut,
+ onFinish: function onFinish() {
+ tween(lavaGraphics, {
+ alpha: 1
+ }, {
+ duration: 800,
+ easing: tween.easeInOut,
+ onFinish: self.pulse
+ });
+ }
+ });
+ };
+ self.pulse();
+ return self;
+});
+var Paddle = Container.expand(function () {
+ var self = Container.call(this);
+ var paddleGraphics = self.attachAsset('paddle', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.width = paddleGraphics.width;
+ self.height = paddleGraphics.height;
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x220000
+});
+
+/****
+* Game Code
+****/
+// Game variables
+var score = 0;
+var highScore = storage.highScore || 0;
+var difficulty = 1;
+var difficultyIncreaseTimer = null;
+// Create game objects
+var paddle = new Paddle();
+var ball = new Ball();
+var lava = new Lava();
+// Initialize paddle position
+paddle.x = 2048 / 2;
+paddle.y = 2732 - 300;
+// Initialize ball position
+ball.reset();
+// Initialize lava position
+lava.x = 2048 / 2;
+lava.y = 2732 - 100;
+// Add objects to game
+game.addChild(paddle);
+game.addChild(ball);
+game.addChild(lava);
+// Create score display
+var scoreTxt = new Text2('Score: 0', {
+ size: 60,
+ fill: 0xFFFFFF
+});
+scoreTxt.anchor.set(0, 0);
+LK.gui.topRight.addChild(scoreTxt);
+// Create high score display
+var highScoreTxt = new Text2('High Score: 0', {
+ size: 40,
+ fill: 0xFFBD00
+});
+highScoreTxt.anchor.set(1, 0);
+highScoreTxt.setText('High Score: ' + highScore);
+highScoreTxt.y = 70;
+LK.gui.topRight.addChild(highScoreTxt);
+// Touch/drag handling for paddle movement
+var isDragging = false;
+game.down = function (x, y, obj) {
+ isDragging = true;
+ paddle.x = x;
+};
+game.move = function (x, y, obj) {
+ if (isDragging) {
+ paddle.x = x;
+ // Clamp paddle position to keep it within screen bounds
+ if (paddle.x < paddle.width / 2) {
+ paddle.x = paddle.width / 2;
+ } else if (paddle.x > 2048 - paddle.width / 2) {
+ paddle.x = 2048 - paddle.width / 2;
+ }
+ }
+};
+game.up = function (x, y, obj) {
+ isDragging = false;
+};
+// Function to update score display
+function updateScore() {
+ scoreTxt.setText('Score: ' + score);
+ // Update high score if current score is higher
+ if (score > highScore) {
+ highScore = score;
+ storage.highScore = highScore;
+ highScoreTxt.setText('High Score: ' + highScore);
+ }
+}
+// Function to increase difficulty over time
+function increaseDifficulty() {
+ difficulty += 0.2;
+ // Cap maximum difficulty
+ if (difficulty > 3) {
+ difficulty = 3;
+ LK.clearInterval(difficultyIncreaseTimer);
+ }
+ // Update ball properties based on difficulty
+ ball.gravity = 0.2 * difficulty;
+ ball.maxSpeed = 15 * difficulty;
+}
+// Start difficulty increase timer
+difficultyIncreaseTimer = LK.setInterval(increaseDifficulty, 10000);
+// Play background music
+LK.playMusic('gameMusic', {
+ fade: {
+ start: 0,
+ end: 0.5,
+ duration: 1000
+ }
+});
+// Game update loop
+game.update = function () {
+ // Update ball position
+ ball.update();
+ // Check for collision with paddle
+ if (ball.speedY > 0 && ball.y + ball.height / 2 >= paddle.y - paddle.height / 2 && ball.y - ball.height / 2 <= paddle.y + paddle.height / 2 && ball.x + ball.width / 2 >= paddle.x - paddle.width / 2 && ball.x - ball.width / 2 <= paddle.x + paddle.width / 2) {
+ // Bounce the ball
+ ball.speedY = -ball.speedY * 0.8;
+ // Add horizontal velocity based on where the ball hit the paddle
+ var hitPosition = (ball.x - paddle.x) / (paddle.width / 2);
+ ball.speedX = hitPosition * 8;
+ // Flash paddle to indicate hit
+ LK.effects.flashObject(paddle, 0xffffff, 200);
+ // Play bounce sound
+ LK.getSound('bounce').play();
+ // Increment score
+ score++;
+ updateScore();
+ }
+ // Check if ball touches lava
+ if (ball.y + ball.height / 2 >= lava.y - lava.height / 2) {
+ // Play lava hit sound
+ LK.getSound('lava_hit').play();
+ // Flash screen red
+ LK.effects.flashScreen(0xff0000, 500);
+ // Reset score
+ score = 0;
+ updateScore();
+ // Reset ball
+ ball.reset();
+ // Reset difficulty
+ difficulty = 1;
+ ball.gravity = 0.2;
+ ball.maxSpeed = 15;
+ // Restart difficulty increase timer
+ LK.clearInterval(difficultyIncreaseTimer);
+ difficultyIncreaseTimer = LK.setInterval(increaseDifficulty, 10000);
+ }
+ // If ball goes too high, change direction
+ if (ball.y < 100) {
+ ball.speedY = Math.abs(ball.speedY) * 0.5;
+ }
+};
\ No newline at end of file