User prompt
Make it so that the plane can not go out of the frame
User prompt
Now make it so, when you get a new highscore, it permanently saves even if you refresh ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Move the score text up by 100 pixels
User prompt
Move the score text up by 30 pixels
User prompt
Move the score text up by 150 pixels
User prompt
Move the score text up by 150 pixels
User prompt
Move it down and to the rightl
User prompt
Now put the score text on the top left corner of the screen
User prompt
Now keep that and make a new text on the middle of the screen that displays your score
User prompt
Make a brand new text on the top right hand clrner of the screen and it says highscore
User prompt
Yo can you make a highscore text on the top right corner of the screen
User prompt
Make it so that every asteroid you pass it adds a number to the meter
User prompt
Add a highscore meter on the top
User prompt
Change the game name to "Space escape"
User prompt
Make the galaxy asset the backround
User prompt
Make it so that the backround is an epic galaxy
User prompt
Make it so that the longer the player is alive, the faster the rocks come down.
Initial prompt
My pet rock
/**** * Plugins ****/ var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ //<Assets used in the game will automatically appear here> // Highscore class to display the highscore var Highscore = Container.expand(function () { var self = Container.call(this); self.highscore = storage.highscore || 0; var scoreText = new Text2('Highscore: 0', { size: 150, fill: 0xFFFFFF }); scoreText.anchor.set(1, 0); // Anchor to the top right self.addChild(scoreText); self.update = function () { scoreText.setText('Highscore: ' + self.highscore); }; }); // Rock class representing falling rocks var Rock = Container.expand(function () { var self = Container.call(this); var rockGraphics = self.attachAsset('rock', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5 + Math.floor(LK.ticks / 600); // Speed at which the rock falls increases over time self.update = function () { self.y += self.speed; }; }); // Score class to display the current score var Score = Container.expand(function () { var self = Container.call(this); var scoreText = new Text2('Score: 0', { size: 150, fill: 0xFFFFFF }); scoreText.anchor.set(0.5, 0.5); // Anchor to the center self.addChild(scoreText); self.update = function () { scoreText.setText('Score: ' + LK.getScore()); }; }); /**** * Initialize Game ****/ var game = new LK.Game({ title: 'Space escape', backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ var galaxyBackground = game.attachAsset('Galaxy', { anchorX: 0.5, anchorY: 0.5, scaleX: 2048 / 100, // Scale to fit the screen width scaleY: 2732 / 100 // Scale to fit the screen height }); galaxyBackground.x = 2048 / 2; // Center the background galaxyBackground.y = 2732 / 2; // Center the background // Initialize variables var rocks = []; var player; var score = 0; // Create player character function createPlayer() { player = new Container(); var playerGraphics = player.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); player.x = 2048 / 2; player.y = 2732 - 150; // Position player near the bottom game.addChild(player); } // Handle player movement game.move = function (x, y, obj) { // Restrict the player's x position to within the game frame player.x = Math.max(0, Math.min(2048, x)); }; // Create rocks at random positions function createRock() { var rock = new Rock(); rock.x = Math.random() * 2048; rock.y = -50; // Start above the screen rocks.push(rock); game.addChild(rock); } // Update game state game.update = function () { // Create a new rock every 60 frames if (LK.ticks % 60 === 0) { createRock(); } // Update rocks for (var i = rocks.length - 1; i >= 0; i--) { var rock = rocks[i]; rock.speed = 5 + Math.floor(LK.ticks / 600); // Update the rock's falling speed rock.update(); // Check if rock is off-screen if (rock.y > 2732) { rock.destroy(); rocks.splice(i, 1); LK.setScore(LK.getScore() + 1); // Increment score for each asteroid passed if (LK.getScore() > highscore.highscore) { highscore.highscore = LK.getScore(); storage.highscore = LK.getScore(); } continue; } // Check for collision with player if (rock.intersects(player)) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); return; } } }; // Initialize game elements createPlayer(); var highscore = new Highscore(); highscore.x = 2048; // Position to the right edge of the screen highscore.y = 0; game.addChild(highscore); var score = new Score(); score.x = 500; // Position to the right score.y = 70; // Position up by 100 pixels game.addChild(score); ;
===================================================================
--- original.js
+++ change.js
@@ -83,9 +83,10 @@
game.addChild(player);
}
// Handle player movement
game.move = function (x, y, obj) {
- player.x = x;
+ // Restrict the player's x position to within the game frame
+ player.x = Math.max(0, Math.min(2048, x));
};
// Create rocks at random positions
function createRock() {
var rock = new Rock();