User prompt
Try again
User prompt
When game loads play music asset
User prompt
Delete the player asset
User prompt
Delete the player asset and re add it
User prompt
Delete the cube asset and re add it
User prompt
Make a ship asset when the player flys and its down jim
User prompt
Add a part where you can fly and dodge flying obstacles as your riding a ship
User prompt
Make the shop button in the middle of the screen
User prompt
Add a shop button that leads to a shop to buy icons and when buy ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Please fix the bug: 'TypeError: LK.pauseGame is not a function. (In 'LK.pauseGame()', 'LK.pauseGame' is undefined)' in or related to this line: 'LK.pauseGame();' Line Number: 555
User prompt
Add a shop button to teleport to the shop
User prompt
Please fix the bug: 'storage.getItem is not a function. (In 'storage.getItem('shop_' + iconId)', 'storage.getItem' is undefined)' in or related to this line: 'var purchased = !!storage.get('shop_' + iconId) || price === 0;' Line Number: 341 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Please fix the bug: 'storage.getItem is not a function. (In 'storage.getItem('shop_' + iconId)', 'storage.getItem' is undefined)' in or related to this line: 'var purchased = !!storage.getItem('shop_' + iconId) || price === 0;' Line Number: 341
User prompt
Redo the shop
User prompt
Please fix the bug: 'storage.get is not a function. (In 'storage.get('shop_' + iconId)', 'storage.get' is undefined)' in or related to this line: 'var purchased = storage.get('shop_' + iconId) || price === 0;' Line Number: 339
User prompt
Please fix the bug: 'Can't find variable: storage' in or related to this line: 'var purchased = storage.get('shop_' + iconId) || price === 0;' Line Number: 338 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Add a shop that you can buy icons in and when the icons are clicked the player icon replaces with the icon the player chose to buy from shop
User prompt
Make a progress bar when it hits 100% the game pauses and theres a text that says you win! And theres an option to replay the game
User prompt
When you collect the minicoins the sound asset plays
User prompt
When the player dies the music restarts
User prompt
Whenever the game starts it plays music asset
User prompt
Make the player go up the blocks bot respawn him
User prompt
Dont make 4 spikes in the structures just 1
User prompt
Make the player jump higher
User prompt
Make the structures possible to pass and decrease the speed of the jump
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// Block obstacle
var Block = Container.expand(function () {
var self = Container.call(this);
var blockGfx = self.attachAsset('block', {
anchorX: 0.5,
anchorY: 1
});
self.width = blockGfx.width;
self.height = blockGfx.height;
self.type = 'block';
self.update = function () {
self.x -= obstacleSpeed;
};
return self;
});
// Player Cube
var Cube = Container.expand(function () {
var self = Container.call(this);
var cubeGfx = self.attachAsset('cube', {
anchorX: 0.5,
anchorY: 1
});
self.width = cubeGfx.width;
self.height = cubeGfx.height;
self.velY = 0;
self.isOnGround = false;
// Jump method
self.jump = function () {
if (self.isOnGround) {
self.velY = -36; // Increased jump velocity for higher jump
self.isOnGround = false;
}
};
// Update method
self.update = function () {
// Gravity
self.velY += 2.1; // Slightly increased gravity to balance higher jump arc
if (self.velY > 60) self.velY = 60;
self.y += self.velY;
// Check for landing on top of a block
self.isOnGround = false;
for (var i = 0; i < obstacles.length; ++i) {
var obs = obstacles[i];
if (obs.type === 'block') {
// Check if cube is falling and feet are just above the block, and horizontally overlapping
var cubeBottom = self.y;
var prevCubeBottom = self.y - self.velY;
var blockTop = obs.y - obs.height;
var blockLeft = obs.x - obs.width / 2;
var blockRight = obs.x + obs.width / 2;
var cubeLeft = self.x - self.width / 2;
var cubeRight = self.x + self.width / 2;
if (self.velY >= 0 && prevCubeBottom <= blockTop && cubeBottom >= blockTop && cubeRight > blockLeft && cubeLeft < blockRight) {
self.y = blockTop;
self.velY = 0;
self.isOnGround = true;
break;
}
}
}
// Prevent falling below ground
if (self.y > groundY) {
self.y = groundY;
self.velY = 0;
self.isOnGround = true;
}
};
return self;
});
// Minicoin collectible
var Minicoin = Container.expand(function () {
var self = Container.call(this);
var coinGfx = self.attachAsset('minicoin', {
anchorX: 0.5,
anchorY: 1
});
self.width = coinGfx.width;
self.height = coinGfx.height;
self.type = 'minicoin';
self.collected = false;
self.update = function () {
self.x -= obstacleSpeed;
};
return self;
});
// Spike obstacle
var Spike = Container.expand(function () {
var self = Container.call(this);
var spikeGfx = self.attachAsset('spike', {
anchorX: 0.5,
anchorY: 1
});
self.width = spikeGfx.width;
self.height = spikeGfx.height;
self.type = 'spike';
self.update = function () {
self.x -= obstacleSpeed;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0xf0f0f0
});
/****
* Game Code
****/
// Block obstacle
// Spike obstacle
// Ground
// Cube player
// Constants
var groundHeight = 80;
var groundY = 2732 - groundHeight;
var startX = 400;
var startY = groundY;
var obstacleSpeed = 12;
var minObstacleGap = 420;
var maxObstacleGap = 700;
var lastObstacleX = 0;
var score = 0;
var gameStarted = false;
// Arrays
var obstacles = [];
// Add background
var background = LK.getAsset('background', {
anchorX: 0,
anchorY: 0
});
background.x = 0;
background.y = 0;
game.addChild(background);
// Add ground
var ground = LK.getAsset('ground', {
anchorX: 0,
anchorY: 0
});
ground.x = 0;
ground.y = groundY;
game.addChild(ground);
// Add player cube
var cube = new Cube();
cube.x = startX;
cube.y = startY;
game.addChild(cube);
// Score text
var scoreTxt = new Text2('0', {
size: 120,
fill: 0x222222
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Progress bar variables
var progressBarBg = LK.getAsset('block', {
anchorX: 0,
anchorY: 0
});
progressBarBg.width = 800;
progressBarBg.height = 40;
progressBarBg.x = 624; // center horizontally (2048-800)/2
progressBarBg.y = 160;
progressBarBg.tint = 0xcccccc;
var progressBarFill = LK.getAsset('block', {
anchorX: 0,
anchorY: 0
});
progressBarFill.width = 0;
progressBarFill.height = 40;
progressBarFill.x = 624;
progressBarFill.y = 160;
progressBarFill.tint = 0x44bb44;
LK.gui.top.addChild(progressBarBg);
LK.gui.top.addChild(progressBarFill);
var progressPercent = 0;
var progressMax = 100; // 100%
var progressPerScore = 2; // Each point increases progress by 2%
var winShown = false;
// Win text and replay button
var winText = new Text2('You win!', {
size: 180,
fill: 0x228822
});
winText.anchor.set(0.5, 0.5);
winText.x = 2048 / 2;
winText.y = 2732 / 2 - 120;
winText.visible = false;
var replayBtn = new Text2('Replay', {
size: 120,
fill: 0x2266cc
});
replayBtn.anchor.set(0.5, 0.5);
replayBtn.x = 2048 / 2;
replayBtn.y = 2732 / 2 + 80;
replayBtn.visible = false;
LK.gui.center.addChild(winText);
LK.gui.center.addChild(replayBtn);
// Replay handler
replayBtn.down = function (x, y, obj) {
if (winShown) {
winText.visible = false;
replayBtn.visible = false;
winShown = false;
resetGame();
gameStarted = true;
LK.playMusic('Mad');
}
};
// Helper: spawn obstacle
function spawnObstacle() {
// Randomly choose spike or block structure
var type = Math.random() < 0.6 ? 'spike' : 'block';
if (type === 'spike') {
var obs = new Spike();
obs.x = 2048 + 100;
obs.y = groundY;
obstacles.push(obs);
game.addChild(obs);
lastObstacleX = obs.x;
} else {
// Structure: always 1 block high for passable platforms
var platformHeight = 1;
var platformLength = Math.floor(Math.random() * 3) + 2; // 2 to 4 blocks long
var baseX = 2048 + 100;
var blockW = 120;
var blockH = 120;
var minicoinsOnTop = Math.random() < 0.8; // 80% chance to spawn coins
for (var i = 0; i < platformLength; ++i) {
// Only one block high
var block = new Block();
block.x = baseX + i * blockW;
block.y = groundY - 0 * blockH;
obstacles.push(block);
game.addChild(block);
lastObstacleX = block.x;
// Place minicoins on top of the structure
if (minicoinsOnTop) {
var coin = new Minicoin();
coin.x = baseX + i * blockW;
coin.y = groundY - blockH - 10; // 10px above top block
obstacles.push(coin);
game.addChild(coin);
}
}
// Place a single spike on a random block in the structure
if (platformLength > 1) {
var spikeIndex = Math.floor(Math.random() * platformLength);
var spike = new Spike();
spike.x = baseX + spikeIndex * blockW;
spike.y = groundY;
obstacles.push(spike);
game.addChild(spike);
}
}
}
// Helper: reset game state
function resetGame() {
// Remove obstacles
for (var i = 0; i < obstacles.length; ++i) {
obstacles[i].destroy();
}
obstacles.length = 0;
cube.x = startX;
cube.y = startY;
cube.velY = 0;
cube.isOnGround = true;
lastObstacleX = 1200;
score = 0;
scoreTxt.setText(score);
progressPercent = 0;
progressBarFill.width = 0;
winText.visible = false;
replayBtn.visible = false;
winShown = false;
gameStarted = false;
}
// Start game on first tap
game.down = function (x, y, obj) {
if (!gameStarted) {
gameStarted = true;
return;
}
cube.jump();
};
// Main update loop
game.update = function () {
if (!gameStarted || winShown) return;
// Update player
cube.update();
// Update obstacles
for (var i = obstacles.length - 1; i >= 0; --i) {
var obs = obstacles[i];
obs.update();
// Remove if off screen
if (obs.x < -200) {
obs.destroy();
obstacles.splice(i, 1);
continue;
}
// Collision detection
if (obs.type === 'minicoin') {
if (!obs.collected && cube.intersects(obs)) {
obs.collected = true;
score += 5; // Minicoin gives 5 points
scoreTxt.setText(score);
// Play coin sound
LK.getSound('Coin').play();
// Update progress
progressPercent = Math.min(progressPercent + progressPerScore * 5, progressMax);
progressBarFill.width = progressPercent / progressMax * 800;
if (progressPercent >= progressMax && !winShown) {
winShown = true;
gameStarted = false;
winText.visible = true;
replayBtn.visible = true;
LK.pauseGame();
}
obs.destroy();
obstacles.splice(i, 1);
continue;
}
} else {
if (cube.intersects(obs)) {
// Flash screen and game over
LK.effects.flashScreen(0xff0000, 800);
LK.showGameOver();
return;
}
// Score: passed obstacle
if (!obs.passed && obs.x + obs.width / 2 < cube.x - cube.width / 2) {
obs.passed = true;
score += 1;
scoreTxt.setText(score);
// Update progress
progressPercent = Math.min(progressPercent + progressPerScore, progressMax);
progressBarFill.width = progressPercent / progressMax * 800;
if (progressPercent >= progressMax && !winShown) {
winShown = true;
gameStarted = false;
winText.visible = true;
replayBtn.visible = true;
LK.pauseGame();
}
}
}
}
// Spawn new obstacles
if (obstacles.length === 0 || 2048 - lastObstacleX > minObstacleGap + Math.random() * (maxObstacleGap - minObstacleGap)) {
spawnObstacle();
}
};
// Reset game on game over
LK.on('gameover', function () {
resetGame();
LK.playMusic('Mad');
});
// Initial state
resetGame();
// Play music asset when the game starts
LK.playMusic('Mad'); ===================================================================
--- original.js
+++ change.js
@@ -161,8 +161,63 @@
fill: 0x222222
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
+// Progress bar variables
+var progressBarBg = LK.getAsset('block', {
+ anchorX: 0,
+ anchorY: 0
+});
+progressBarBg.width = 800;
+progressBarBg.height = 40;
+progressBarBg.x = 624; // center horizontally (2048-800)/2
+progressBarBg.y = 160;
+progressBarBg.tint = 0xcccccc;
+var progressBarFill = LK.getAsset('block', {
+ anchorX: 0,
+ anchorY: 0
+});
+progressBarFill.width = 0;
+progressBarFill.height = 40;
+progressBarFill.x = 624;
+progressBarFill.y = 160;
+progressBarFill.tint = 0x44bb44;
+LK.gui.top.addChild(progressBarBg);
+LK.gui.top.addChild(progressBarFill);
+var progressPercent = 0;
+var progressMax = 100; // 100%
+var progressPerScore = 2; // Each point increases progress by 2%
+var winShown = false;
+// Win text and replay button
+var winText = new Text2('You win!', {
+ size: 180,
+ fill: 0x228822
+});
+winText.anchor.set(0.5, 0.5);
+winText.x = 2048 / 2;
+winText.y = 2732 / 2 - 120;
+winText.visible = false;
+var replayBtn = new Text2('Replay', {
+ size: 120,
+ fill: 0x2266cc
+});
+replayBtn.anchor.set(0.5, 0.5);
+replayBtn.x = 2048 / 2;
+replayBtn.y = 2732 / 2 + 80;
+replayBtn.visible = false;
+LK.gui.center.addChild(winText);
+LK.gui.center.addChild(replayBtn);
+// Replay handler
+replayBtn.down = function (x, y, obj) {
+ if (winShown) {
+ winText.visible = false;
+ replayBtn.visible = false;
+ winShown = false;
+ resetGame();
+ gameStarted = true;
+ LK.playMusic('Mad');
+ }
+};
// Helper: spawn obstacle
function spawnObstacle() {
// Randomly choose spike or block structure
var type = Math.random() < 0.6 ? 'spike' : 'block';
@@ -222,8 +277,13 @@
cube.isOnGround = true;
lastObstacleX = 1200;
score = 0;
scoreTxt.setText(score);
+ progressPercent = 0;
+ progressBarFill.width = 0;
+ winText.visible = false;
+ replayBtn.visible = false;
+ winShown = false;
gameStarted = false;
}
// Start game on first tap
game.down = function (x, y, obj) {
@@ -234,9 +294,9 @@
cube.jump();
};
// Main update loop
game.update = function () {
- if (!gameStarted) return;
+ if (!gameStarted || winShown) return;
// Update player
cube.update();
// Update obstacles
for (var i = obstacles.length - 1; i >= 0; --i) {
@@ -255,8 +315,18 @@
score += 5; // Minicoin gives 5 points
scoreTxt.setText(score);
// Play coin sound
LK.getSound('Coin').play();
+ // Update progress
+ progressPercent = Math.min(progressPercent + progressPerScore * 5, progressMax);
+ progressBarFill.width = progressPercent / progressMax * 800;
+ if (progressPercent >= progressMax && !winShown) {
+ winShown = true;
+ gameStarted = false;
+ winText.visible = true;
+ replayBtn.visible = true;
+ LK.pauseGame();
+ }
obs.destroy();
obstacles.splice(i, 1);
continue;
}
@@ -271,8 +341,18 @@
if (!obs.passed && obs.x + obs.width / 2 < cube.x - cube.width / 2) {
obs.passed = true;
score += 1;
scoreTxt.setText(score);
+ // Update progress
+ progressPercent = Math.min(progressPercent + progressPerScore, progressMax);
+ progressBarFill.width = progressPercent / progressMax * 800;
+ if (progressPercent >= progressMax && !winShown) {
+ winShown = true;
+ gameStarted = false;
+ winText.visible = true;
+ replayBtn.visible = true;
+ LK.pauseGame();
+ }
}
}
}
// Spawn new obstacles