/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1", { highScore: 0 }); /**** * Classes ****/ var BeachBall = Container.expand(function () { var self = Container.call(this); var ballGraphics = self.attachAsset('beach_ball', { anchorX: 0.5, anchorY: 0.5 }); self.velocity = { x: 0, y: 0 }; self.speed = 10; self.active = true; self.radius = ballGraphics.width / 2; self.reset = function () { self.x = 2048 / 2; self.y = 2732 / 2; self.velocity.x = (Math.random() > 0.5 ? 1 : -1) * self.speed; self.velocity.y = 7; }; self.reverseY = function () { self.velocity.y *= -1; LK.getSound('hit').play(); }; self.update = function () { if (!self.active) { return; } self.x += self.velocity.x; self.y += self.velocity.y; // Wall collision if (self.x - self.radius < 0 || self.x + self.radius > 2048) { self.velocity.x *= -1; LK.getSound('hit').play(); } }; self.reset(); return self; }); var Paddle = Container.expand(function () { var self = Container.call(this); var paddleGraphics = self.attachAsset('crab_paddle', { anchorX: 0.5, anchorY: 0.5 }); self.width = paddleGraphics.width; self.height = paddleGraphics.height; self.defaultWidth = self.width; self.expand = function () { tween(paddleGraphics, { width: self.defaultWidth * 1.5 }, { duration: 300, easing: tween.easeOut }); self.width = self.defaultWidth * 1.5; }; self.normal = function () { tween(paddleGraphics, { width: self.defaultWidth }, { duration: 300, easing: tween.easeOut }); self.width = self.defaultWidth; }; return self; }); var PowerUp = Container.expand(function () { var self = Container.call(this); var powerUpGraphics = self.attachAsset('power_up', { anchorX: 0.5, anchorY: 0.5 }); self.type = 'expand'; // Default type self.active = true; self.speed = 3; self.update = function () { if (!self.active) { return; } self.y += self.speed; // Remove if it goes off screen if (self.y > 2732 + 50) { self.active = false; } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB // Sky blue background }); /**** * Game Code ****/ // Game state variables var gameStarted = false; var score = 0; var highScore = storage.highScore || 0; var lives = 3; var powerUpTimer = 0; var powerUpActive = false; // Create beach environment var beach = LK.getAsset('beach_background', { anchorX: 0, anchorY: 0, x: 0, y: 0, width: 2048, height: 2732 }); game.addChild(beach); var water = LK.getAsset('water', { anchorX: 0, anchorY: 0, x: 0, y: 2200, width: 2048, alpha: 0.8 }); game.addChild(water); // Create player paddle (crab) var playerPaddle = new Paddle(); playerPaddle.x = 2048 / 2; playerPaddle.y = 2550; game.addChild(playerPaddle); // Create AI paddle (crab) var aiPaddle = new Paddle(); aiPaddle.x = 2048 / 2; aiPaddle.y = 200; // Use AI paddle asset instead of player paddle var aiPaddleGraphics = aiPaddle.children[0]; aiPaddleGraphics.texture = LK.getAsset('ai_paddle', {}).texture; game.addChild(aiPaddle); // Create beach ball var beachBall = new BeachBall(); game.addChild(beachBall); // Create power-ups array var powerUps = []; // Create GUI elements var scoreTxt = new Text2('Score: 0', { size: 80, fill: 0xFFFFFF }); scoreTxt.anchor.set(0, 0); LK.gui.topRight.addChild(scoreTxt); var livesTxt = new Text2('Lives: ' + lives, { size: 80, fill: 0xFFFFFF }); livesTxt.anchor.set(0, 0); LK.gui.topLeft.addChild(livesTxt); // Position it a bit to the right to avoid overlap with menu icon livesTxt.x = 120; var instructionsTxt = new Text2('Drag the crab to play!', { size: 100, fill: 0xFFFFFF }); instructionsTxt.anchor.set(0.5, 0.5); LK.gui.center.addChild(instructionsTxt); // Game drag functionality var isDragging = false; game.down = function (x, y, obj) { if (!gameStarted) { gameStarted = true; instructionsTxt.visible = false; } isDragging = true; playerPaddle.x = x; }; game.move = function (x, y, obj) { if (isDragging) { playerPaddle.x = x; // Keep paddle within bounds if (playerPaddle.x < playerPaddle.width / 2) { playerPaddle.x = playerPaddle.width / 2; } else if (playerPaddle.x > 2048 - playerPaddle.width / 2) { playerPaddle.x = 2048 - playerPaddle.width / 2; } } }; game.up = function (x, y, obj) { isDragging = false; }; // Simple AI movement function function updateAI() { // AI follows the ball with slight delay var targetX = beachBall.x; // Add some randomness to make AI beatable if (Math.random() < 0.3) { targetX += (Math.random() - 0.5) * 200; } // Move AI paddle towards target var dx = targetX - aiPaddle.x; aiPaddle.x += dx * 0.05; // Keep AI paddle within bounds if (aiPaddle.x < aiPaddle.width / 2) { aiPaddle.x = aiPaddle.width / 2; } else if (aiPaddle.x > 2048 - aiPaddle.width / 2) { aiPaddle.x = 2048 - aiPaddle.width / 2; } } // Function to check paddle collisions function checkPaddleCollisions() { // Check collision with player paddle if (beachBall.velocity.y > 0 && beachBall.y + beachBall.radius >= playerPaddle.y - playerPaddle.height / 2 && beachBall.y - beachBall.radius <= playerPaddle.y + playerPaddle.height / 2 && beachBall.x >= playerPaddle.x - playerPaddle.width / 2 && beachBall.x <= playerPaddle.x + playerPaddle.width / 2) { beachBall.reverseY(); // Calculate new x velocity based on hit position relative to paddle center var hitPos = (beachBall.x - playerPaddle.x) / (playerPaddle.width / 2); beachBall.velocity.x = hitPos * beachBall.speed * 1.5; // Increase speed slightly beachBall.speed += 0.2; if (beachBall.speed > 20) { beachBall.speed = 20; } } // Check collision with AI paddle if (beachBall.velocity.y < 0 && beachBall.y - beachBall.radius <= aiPaddle.y + aiPaddle.height / 2 && beachBall.y + beachBall.radius >= aiPaddle.y - aiPaddle.height / 2 && beachBall.x >= aiPaddle.x - aiPaddle.width / 2 && beachBall.x <= aiPaddle.x + aiPaddle.width / 2) { beachBall.reverseY(); // Calculate new x velocity based on hit position relative to paddle center var hitPos = (beachBall.x - aiPaddle.x) / (aiPaddle.width / 2); beachBall.velocity.x = hitPos * beachBall.speed * 1.5; } } // Function to spawn a power-up function spawnPowerUp() { var powerUp = new PowerUp(); powerUp.x = Math.random() * (2048 - 100) + 50; powerUp.y = -50; // Randomly select power-up type var types = ['expand', 'speed', 'multiball']; powerUp.type = types[Math.floor(Math.random() * types.length)]; // Set color based on type if (powerUp.type === 'expand') { powerUp.children[0].tint = 0x2ECC71; // Green } else if (powerUp.type === 'speed') { powerUp.children[0].tint = 0x3498DB; // Blue } else { powerUp.children[0].tint = 0x9B59B6; // Purple } powerUps.push(powerUp); game.addChild(powerUp); } // Function to check power-up collisions function checkPowerUpCollisions() { for (var i = powerUps.length - 1; i >= 0; i--) { var powerUp = powerUps[i]; if (!powerUp.active) { powerUp.destroy(); powerUps.splice(i, 1); continue; } // Check if player paddle caught the power-up if (powerUp.y + 35 >= playerPaddle.y - playerPaddle.height / 2 && powerUp.y - 35 <= playerPaddle.y + playerPaddle.height / 2 && powerUp.x >= playerPaddle.x - playerPaddle.width / 2 && powerUp.x <= playerPaddle.x + playerPaddle.width / 2) { // Apply power-up effect applyPowerUp(powerUp.type); // Play power-up sound LK.getSound('powerup').play(); // Remove power-up powerUp.destroy(); powerUps.splice(i, 1); } } } // Function to apply power-up effects function applyPowerUp(type) { powerUpActive = true; powerUpTimer = 300; // 5 seconds at 60fps if (type === 'expand') { playerPaddle.expand(); } else if (type === 'speed') { beachBall.speed *= 0.7; // Slow down ball } else if (type === 'multiball') { // Add another ball (not implemented in MVP) // Would require tracking multiple balls } } // Main game update function game.update = function () { if (!gameStarted) { return; } // Update ball beachBall.update(); // Update AI updateAI(); // Check paddle collisions checkPaddleCollisions(); // Update power-ups for (var i = 0; i < powerUps.length; i++) { powerUps[i].update(); } // Check power-up collisions checkPowerUpCollisions(); // Manage power-up timer if (powerUpActive) { powerUpTimer--; if (powerUpTimer <= 0) { powerUpActive = false; playerPaddle.normal(); beachBall.speed = 10; // Reset ball speed } } // Spawn power-ups occasionally if (LK.ticks % 300 === 0 && Math.random() < 0.5) { spawnPowerUp(); } // Check if ball went past AI (player scores) if (beachBall.y < -beachBall.radius) { score++; scoreTxt.setText('Score: ' + score); LK.getSound('score').play(); beachBall.reset(); // Update high score if needed if (score > highScore) { highScore = score; storage.highScore = highScore; } } // Check if ball went past player (lose life) if (beachBall.y > 2732 + beachBall.radius) { lives--; livesTxt.setText('Lives: ' + lives); beachBall.reset(); if (lives <= 0) { // Game over LK.effects.flashScreen(0xFF0000, 1000); LK.setScore(score); // Set score for game over screen LK.showGameOver(); } } }; // Start background music LK.playMusic('beach_music', { fade: { start: 0, end: 0.4, duration: 1000 } });
===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,355 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+var storage = LK.import("@upit/storage.v1", {
+ highScore: 0
+});
+
+/****
+* Classes
+****/
+var BeachBall = Container.expand(function () {
+ var self = Container.call(this);
+ var ballGraphics = self.attachAsset('beach_ball', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.velocity = {
+ x: 0,
+ y: 0
+ };
+ self.speed = 10;
+ self.active = true;
+ self.radius = ballGraphics.width / 2;
+ self.reset = function () {
+ self.x = 2048 / 2;
+ self.y = 2732 / 2;
+ self.velocity.x = (Math.random() > 0.5 ? 1 : -1) * self.speed;
+ self.velocity.y = 7;
+ };
+ self.reverseY = function () {
+ self.velocity.y *= -1;
+ LK.getSound('hit').play();
+ };
+ self.update = function () {
+ if (!self.active) {
+ return;
+ }
+ self.x += self.velocity.x;
+ self.y += self.velocity.y;
+ // Wall collision
+ if (self.x - self.radius < 0 || self.x + self.radius > 2048) {
+ self.velocity.x *= -1;
+ LK.getSound('hit').play();
+ }
+ };
+ self.reset();
+ return self;
+});
+var Paddle = Container.expand(function () {
+ var self = Container.call(this);
+ var paddleGraphics = self.attachAsset('crab_paddle', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.width = paddleGraphics.width;
+ self.height = paddleGraphics.height;
+ self.defaultWidth = self.width;
+ self.expand = function () {
+ tween(paddleGraphics, {
+ width: self.defaultWidth * 1.5
+ }, {
+ duration: 300,
+ easing: tween.easeOut
+ });
+ self.width = self.defaultWidth * 1.5;
+ };
+ self.normal = function () {
+ tween(paddleGraphics, {
+ width: self.defaultWidth
+ }, {
+ duration: 300,
+ easing: tween.easeOut
+ });
+ self.width = self.defaultWidth;
+ };
+ return self;
+});
+var PowerUp = Container.expand(function () {
+ var self = Container.call(this);
+ var powerUpGraphics = self.attachAsset('power_up', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.type = 'expand'; // Default type
+ self.active = true;
+ self.speed = 3;
+ self.update = function () {
+ if (!self.active) {
+ return;
+ }
+ self.y += self.speed;
+ // Remove if it goes off screen
+ if (self.y > 2732 + 50) {
+ self.active = false;
+ }
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
+ backgroundColor: 0x87CEEB // Sky blue background
+});
+
+/****
+* Game Code
+****/
+// Game state variables
+var gameStarted = false;
+var score = 0;
+var highScore = storage.highScore || 0;
+var lives = 3;
+var powerUpTimer = 0;
+var powerUpActive = false;
+// Create beach environment
+var beach = LK.getAsset('beach_background', {
+ anchorX: 0,
+ anchorY: 0,
+ x: 0,
+ y: 0,
+ width: 2048,
+ height: 2732
+});
+game.addChild(beach);
+var water = LK.getAsset('water', {
+ anchorX: 0,
+ anchorY: 0,
+ x: 0,
+ y: 2200,
+ width: 2048,
+ alpha: 0.8
+});
+game.addChild(water);
+// Create player paddle (crab)
+var playerPaddle = new Paddle();
+playerPaddle.x = 2048 / 2;
+playerPaddle.y = 2550;
+game.addChild(playerPaddle);
+// Create AI paddle (crab)
+var aiPaddle = new Paddle();
+aiPaddle.x = 2048 / 2;
+aiPaddle.y = 200;
+// Use AI paddle asset instead of player paddle
+var aiPaddleGraphics = aiPaddle.children[0];
+aiPaddleGraphics.texture = LK.getAsset('ai_paddle', {}).texture;
+game.addChild(aiPaddle);
+// Create beach ball
+var beachBall = new BeachBall();
+game.addChild(beachBall);
+// Create power-ups array
+var powerUps = [];
+// Create GUI elements
+var scoreTxt = new Text2('Score: 0', {
+ size: 80,
+ fill: 0xFFFFFF
+});
+scoreTxt.anchor.set(0, 0);
+LK.gui.topRight.addChild(scoreTxt);
+var livesTxt = new Text2('Lives: ' + lives, {
+ size: 80,
+ fill: 0xFFFFFF
+});
+livesTxt.anchor.set(0, 0);
+LK.gui.topLeft.addChild(livesTxt);
+// Position it a bit to the right to avoid overlap with menu icon
+livesTxt.x = 120;
+var instructionsTxt = new Text2('Drag the crab to play!', {
+ size: 100,
+ fill: 0xFFFFFF
+});
+instructionsTxt.anchor.set(0.5, 0.5);
+LK.gui.center.addChild(instructionsTxt);
+// Game drag functionality
+var isDragging = false;
+game.down = function (x, y, obj) {
+ if (!gameStarted) {
+ gameStarted = true;
+ instructionsTxt.visible = false;
+ }
+ isDragging = true;
+ playerPaddle.x = x;
+};
+game.move = function (x, y, obj) {
+ if (isDragging) {
+ playerPaddle.x = x;
+ // Keep paddle within bounds
+ if (playerPaddle.x < playerPaddle.width / 2) {
+ playerPaddle.x = playerPaddle.width / 2;
+ } else if (playerPaddle.x > 2048 - playerPaddle.width / 2) {
+ playerPaddle.x = 2048 - playerPaddle.width / 2;
+ }
+ }
+};
+game.up = function (x, y, obj) {
+ isDragging = false;
+};
+// Simple AI movement function
+function updateAI() {
+ // AI follows the ball with slight delay
+ var targetX = beachBall.x;
+ // Add some randomness to make AI beatable
+ if (Math.random() < 0.3) {
+ targetX += (Math.random() - 0.5) * 200;
+ }
+ // Move AI paddle towards target
+ var dx = targetX - aiPaddle.x;
+ aiPaddle.x += dx * 0.05;
+ // Keep AI paddle within bounds
+ if (aiPaddle.x < aiPaddle.width / 2) {
+ aiPaddle.x = aiPaddle.width / 2;
+ } else if (aiPaddle.x > 2048 - aiPaddle.width / 2) {
+ aiPaddle.x = 2048 - aiPaddle.width / 2;
+ }
+}
+// Function to check paddle collisions
+function checkPaddleCollisions() {
+ // Check collision with player paddle
+ if (beachBall.velocity.y > 0 && beachBall.y + beachBall.radius >= playerPaddle.y - playerPaddle.height / 2 && beachBall.y - beachBall.radius <= playerPaddle.y + playerPaddle.height / 2 && beachBall.x >= playerPaddle.x - playerPaddle.width / 2 && beachBall.x <= playerPaddle.x + playerPaddle.width / 2) {
+ beachBall.reverseY();
+ // Calculate new x velocity based on hit position relative to paddle center
+ var hitPos = (beachBall.x - playerPaddle.x) / (playerPaddle.width / 2);
+ beachBall.velocity.x = hitPos * beachBall.speed * 1.5;
+ // Increase speed slightly
+ beachBall.speed += 0.2;
+ if (beachBall.speed > 20) {
+ beachBall.speed = 20;
+ }
+ }
+ // Check collision with AI paddle
+ if (beachBall.velocity.y < 0 && beachBall.y - beachBall.radius <= aiPaddle.y + aiPaddle.height / 2 && beachBall.y + beachBall.radius >= aiPaddle.y - aiPaddle.height / 2 && beachBall.x >= aiPaddle.x - aiPaddle.width / 2 && beachBall.x <= aiPaddle.x + aiPaddle.width / 2) {
+ beachBall.reverseY();
+ // Calculate new x velocity based on hit position relative to paddle center
+ var hitPos = (beachBall.x - aiPaddle.x) / (aiPaddle.width / 2);
+ beachBall.velocity.x = hitPos * beachBall.speed * 1.5;
+ }
+}
+// Function to spawn a power-up
+function spawnPowerUp() {
+ var powerUp = new PowerUp();
+ powerUp.x = Math.random() * (2048 - 100) + 50;
+ powerUp.y = -50;
+ // Randomly select power-up type
+ var types = ['expand', 'speed', 'multiball'];
+ powerUp.type = types[Math.floor(Math.random() * types.length)];
+ // Set color based on type
+ if (powerUp.type === 'expand') {
+ powerUp.children[0].tint = 0x2ECC71; // Green
+ } else if (powerUp.type === 'speed') {
+ powerUp.children[0].tint = 0x3498DB; // Blue
+ } else {
+ powerUp.children[0].tint = 0x9B59B6; // Purple
+ }
+ powerUps.push(powerUp);
+ game.addChild(powerUp);
+}
+// Function to check power-up collisions
+function checkPowerUpCollisions() {
+ for (var i = powerUps.length - 1; i >= 0; i--) {
+ var powerUp = powerUps[i];
+ if (!powerUp.active) {
+ powerUp.destroy();
+ powerUps.splice(i, 1);
+ continue;
+ }
+ // Check if player paddle caught the power-up
+ if (powerUp.y + 35 >= playerPaddle.y - playerPaddle.height / 2 && powerUp.y - 35 <= playerPaddle.y + playerPaddle.height / 2 && powerUp.x >= playerPaddle.x - playerPaddle.width / 2 && powerUp.x <= playerPaddle.x + playerPaddle.width / 2) {
+ // Apply power-up effect
+ applyPowerUp(powerUp.type);
+ // Play power-up sound
+ LK.getSound('powerup').play();
+ // Remove power-up
+ powerUp.destroy();
+ powerUps.splice(i, 1);
+ }
+ }
+}
+// Function to apply power-up effects
+function applyPowerUp(type) {
+ powerUpActive = true;
+ powerUpTimer = 300; // 5 seconds at 60fps
+ if (type === 'expand') {
+ playerPaddle.expand();
+ } else if (type === 'speed') {
+ beachBall.speed *= 0.7; // Slow down ball
+ } else if (type === 'multiball') {
+ // Add another ball (not implemented in MVP)
+ // Would require tracking multiple balls
+ }
+}
+// Main game update function
+game.update = function () {
+ if (!gameStarted) {
+ return;
+ }
+ // Update ball
+ beachBall.update();
+ // Update AI
+ updateAI();
+ // Check paddle collisions
+ checkPaddleCollisions();
+ // Update power-ups
+ for (var i = 0; i < powerUps.length; i++) {
+ powerUps[i].update();
+ }
+ // Check power-up collisions
+ checkPowerUpCollisions();
+ // Manage power-up timer
+ if (powerUpActive) {
+ powerUpTimer--;
+ if (powerUpTimer <= 0) {
+ powerUpActive = false;
+ playerPaddle.normal();
+ beachBall.speed = 10; // Reset ball speed
+ }
+ }
+ // Spawn power-ups occasionally
+ if (LK.ticks % 300 === 0 && Math.random() < 0.5) {
+ spawnPowerUp();
+ }
+ // Check if ball went past AI (player scores)
+ if (beachBall.y < -beachBall.radius) {
+ score++;
+ scoreTxt.setText('Score: ' + score);
+ LK.getSound('score').play();
+ beachBall.reset();
+ // Update high score if needed
+ if (score > highScore) {
+ highScore = score;
+ storage.highScore = highScore;
+ }
+ }
+ // Check if ball went past player (lose life)
+ if (beachBall.y > 2732 + beachBall.radius) {
+ lives--;
+ livesTxt.setText('Lives: ' + lives);
+ beachBall.reset();
+ if (lives <= 0) {
+ // Game over
+ LK.effects.flashScreen(0xFF0000, 1000);
+ LK.setScore(score); // Set score for game over screen
+ LK.showGameOver();
+ }
+ }
+};
+// Start background music
+LK.playMusic('beach_music', {
+ fade: {
+ start: 0,
+ end: 0.4,
+ duration: 1000
+ }
});
\ No newline at end of file
red crab 2d 32 bit. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
gap sea water beach and sand top down anime style.
white plain sea turtle egg. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
polkadot white red seastar. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows