User prompt
Lägg pengar i också. ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Den får hoppa högre.
User prompt
Gör plattformarna större och tjockare.
User prompt
Den får gå snabbare höger och vänster.
User prompt
Den får hoppa högre.
User prompt
Den får hoppa snabbare.
User prompt
Gör karaktären snabbare!
Code edit (1 edits merged)
Please save this source code
User prompt
Doodle Jump
Initial prompt
doodle jump
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ var Coin = Container.expand(function () { var self = Container.call(this); var coinGraphics = self.attachAsset('coin', { anchorX: 0.5, anchorY: 0.5 }); self.collected = false; self.bobOffset = Math.random() * Math.PI * 2; self.originalY = 0; self.update = function () { if (!self.collected) { self.y = self.originalY + Math.sin(LK.ticks * 0.1 + self.bobOffset) * 10; self.rotation += 0.05; } }; self.collect = function () { if (!self.collected) { self.collected = true; LK.getSound('coin').play(); tween(self, { scaleX: 1.5, scaleY: 1.5, alpha: 0 }, { duration: 300, onFinish: function onFinish() { self.destroy(); } }); return true; } return false; }; return self; }); var Platform = Container.expand(function (type) { var self = Container.call(this); self.type = type || 'normal'; self.used = false; self.moveDirection = 1; self.moveSpeed = 2; var assetId = 'platform'; if (self.type === 'breakable') assetId = 'breakablePlatform';else if (self.type === 'moving') assetId = 'movingPlatform';else if (self.type === 'spring') assetId = 'springPlatform'; var platformGraphics = self.attachAsset(assetId, { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { if (self.type === 'moving') { self.x += self.moveSpeed * self.moveDirection; if (self.x <= 140 || self.x >= 1908) { self.moveDirection *= -1; } } }; self.onLanded = function () { if (self.type === 'breakable' && !self.used) { self.used = true; tween(self, { alpha: 0, scaleY: 0.1 }, { duration: 200, onFinish: function onFinish() { self.destroy(); } }); LK.getSound('break').play(); return false; // Don't jump } else if (self.type === 'spring') { LK.getSound('spring').play(); return -45; // Extra jump power } return true; // Normal jump }; return self; }); var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.velocityY = 0; self.velocityX = 0; self.gravity = 0.6; self.jumpPower = -35; self.maxVelocityX = 18; self.friction = 0.9; self.isJumping = false; self.update = function () { // Apply gravity self.velocityY += self.gravity; // Apply velocities self.y += self.velocityY; self.x += self.velocityX; // Apply friction to horizontal movement self.velocityX *= self.friction; // Wrap around screen horizontally if (self.x < -40) { self.x = 2048 + 40; } else if (self.x > 2048 + 40) { self.x = -40; } // Check if falling (for jump detection) self.isJumping = self.velocityY > 0; }; self.jump = function (power) { if (!power) power = self.jumpPower; self.velocityY = power; LK.getSound('jump').play(); }; self.moveLeft = function () { self.velocityX = Math.max(self.velocityX - 4.0, -self.maxVelocityX); }; self.moveRight = function () { self.velocityX = Math.min(self.velocityX + 4.0, self.maxVelocityX); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB }); /**** * Game Code ****/ var player; var platforms = []; var coins = []; var camera = { y: 0 }; var maxHeight = 0; var platformSpacing = 200; var lastPlatformY = 2732; var totalCoins = storage.totalCoins || 0; // Initialize score display var scoreTxt = new Text2('0', { size: 80, fill: 0x000000 }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Initialize coin display var coinTxt = new Text2('Coins: ' + totalCoins, { size: 60, fill: 0xffd700 }); coinTxt.anchor.set(1, 0); coinTxt.x = -20; coinTxt.y = 20; LK.gui.topRight.addChild(coinTxt); // Create player player = game.addChild(new Player()); player.x = 1024; player.y = 2500; // Create initial platforms function createPlatform(x, y, type) { var platform = new Platform(type); platform.x = x; platform.y = y; platforms.push(platform); game.addChild(platform); return platform; } // Create coin function function createCoin(x, y) { var coin = new Coin(); coin.x = x; coin.y = y; coin.originalY = y; coins.push(coin); game.addChild(coin); return coin; } // Generate initial platforms for (var i = 0; i < 15; i++) { var platformY = 2732 - i * platformSpacing; var platformX = Math.random() * (2048 - 280) + 140; var platformType = 'normal'; if (i > 2) { var rand = Math.random(); if (rand < 0.1) platformType = 'breakable';else if (rand < 0.2) platformType = 'moving';else if (rand < 0.25) platformType = 'spring'; } createPlatform(platformX, platformY, platformType); // Add coins near some platforms if (i > 0 && Math.random() < 0.4) { var coinX = platformX + (Math.random() - 0.5) * 200; coinX = Math.max(40, Math.min(2008, coinX)); createCoin(coinX, platformY - 80); } lastPlatformY = platformY; } // Generate more platforms as needed function generatePlatforms() { while (lastPlatformY > camera.y - 1000) { lastPlatformY -= platformSpacing + (Math.random() * 100 - 50); var platformX = Math.random() * (2048 - 280) + 140; var platformType = 'normal'; var rand = Math.random(); if (rand < 0.15) platformType = 'breakable';else if (rand < 0.3) platformType = 'moving';else if (rand < 0.35) platformType = 'spring'; createPlatform(platformX, lastPlatformY, platformType); // Add coins near some platforms if (Math.random() < 0.4) { var coinX = platformX + (Math.random() - 0.5) * 200; coinX = Math.max(40, Math.min(2008, coinX)); createCoin(coinX, lastPlatformY - 80); } } } // Input handling game.down = function (x, y, obj) { if (x < 1024) { player.moveLeft(); } else { player.moveRight(); } }; game.update = function () { // Update camera to follow player var targetCameraY = player.y - 1800; if (targetCameraY < camera.y) { camera.y = targetCameraY; game.y = -camera.y; } // Update max height and score var currentHeight = Math.max(0, Math.floor((2732 - player.y) / 10)); if (currentHeight > maxHeight) { maxHeight = currentHeight; LK.setScore(maxHeight); scoreTxt.setText(maxHeight.toString()); } // Generate new platforms generatePlatforms(); // Check coin collisions for (var i = coins.length - 1; i >= 0; i--) { var coin = coins[i]; // Remove coins that are too far below if (coin.y > camera.y + 3000) { coin.destroy(); coins.splice(i, 1); continue; } // Check collision with player if (!coin.collected && player.intersects(coin)) { if (coin.collect()) { totalCoins++; storage.totalCoins = totalCoins; coinTxt.setText('Coins: ' + totalCoins); coins.splice(i, 1); } } } // Check platform collisions for (var i = platforms.length - 1; i >= 0; i--) { var platform = platforms[i]; // Remove platforms that are too far below if (platform.y > camera.y + 3000) { platform.destroy(); platforms.splice(i, 1); continue; } // Check collision with player if (player.isJumping && player.intersects(platform)) { var playerBottom = player.y + 40; var platformTop = platform.y - 20; if (playerBottom > platformTop && playerBottom < platformTop + 50) { var jumpResult = platform.onLanded(); if (jumpResult === false) { // Breakable platform - no jump continue; } else if (typeof jumpResult === 'number') { // Spring platform - custom jump power player.jump(jumpResult); } else { // Normal platform - regular jump player.jump(); } } } } // Game over condition if (player.y > camera.y + 2732 + 200) { LK.showGameOver(); } };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Coin = Container.expand(function () {
var self = Container.call(this);
var coinGraphics = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
self.collected = false;
self.bobOffset = Math.random() * Math.PI * 2;
self.originalY = 0;
self.update = function () {
if (!self.collected) {
self.y = self.originalY + Math.sin(LK.ticks * 0.1 + self.bobOffset) * 10;
self.rotation += 0.05;
}
};
self.collect = function () {
if (!self.collected) {
self.collected = true;
LK.getSound('coin').play();
tween(self, {
scaleX: 1.5,
scaleY: 1.5,
alpha: 0
}, {
duration: 300,
onFinish: function onFinish() {
self.destroy();
}
});
return true;
}
return false;
};
return self;
});
var Platform = Container.expand(function (type) {
var self = Container.call(this);
self.type = type || 'normal';
self.used = false;
self.moveDirection = 1;
self.moveSpeed = 2;
var assetId = 'platform';
if (self.type === 'breakable') assetId = 'breakablePlatform';else if (self.type === 'moving') assetId = 'movingPlatform';else if (self.type === 'spring') assetId = 'springPlatform';
var platformGraphics = self.attachAsset(assetId, {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
if (self.type === 'moving') {
self.x += self.moveSpeed * self.moveDirection;
if (self.x <= 140 || self.x >= 1908) {
self.moveDirection *= -1;
}
}
};
self.onLanded = function () {
if (self.type === 'breakable' && !self.used) {
self.used = true;
tween(self, {
alpha: 0,
scaleY: 0.1
}, {
duration: 200,
onFinish: function onFinish() {
self.destroy();
}
});
LK.getSound('break').play();
return false; // Don't jump
} else if (self.type === 'spring') {
LK.getSound('spring').play();
return -45; // Extra jump power
}
return true; // Normal jump
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityY = 0;
self.velocityX = 0;
self.gravity = 0.6;
self.jumpPower = -35;
self.maxVelocityX = 18;
self.friction = 0.9;
self.isJumping = false;
self.update = function () {
// Apply gravity
self.velocityY += self.gravity;
// Apply velocities
self.y += self.velocityY;
self.x += self.velocityX;
// Apply friction to horizontal movement
self.velocityX *= self.friction;
// Wrap around screen horizontally
if (self.x < -40) {
self.x = 2048 + 40;
} else if (self.x > 2048 + 40) {
self.x = -40;
}
// Check if falling (for jump detection)
self.isJumping = self.velocityY > 0;
};
self.jump = function (power) {
if (!power) power = self.jumpPower;
self.velocityY = power;
LK.getSound('jump').play();
};
self.moveLeft = function () {
self.velocityX = Math.max(self.velocityX - 4.0, -self.maxVelocityX);
};
self.moveRight = function () {
self.velocityX = Math.min(self.velocityX + 4.0, self.maxVelocityX);
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
var player;
var platforms = [];
var coins = [];
var camera = {
y: 0
};
var maxHeight = 0;
var platformSpacing = 200;
var lastPlatformY = 2732;
var totalCoins = storage.totalCoins || 0;
// Initialize score display
var scoreTxt = new Text2('0', {
size: 80,
fill: 0x000000
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Initialize coin display
var coinTxt = new Text2('Coins: ' + totalCoins, {
size: 60,
fill: 0xffd700
});
coinTxt.anchor.set(1, 0);
coinTxt.x = -20;
coinTxt.y = 20;
LK.gui.topRight.addChild(coinTxt);
// Create player
player = game.addChild(new Player());
player.x = 1024;
player.y = 2500;
// Create initial platforms
function createPlatform(x, y, type) {
var platform = new Platform(type);
platform.x = x;
platform.y = y;
platforms.push(platform);
game.addChild(platform);
return platform;
}
// Create coin function
function createCoin(x, y) {
var coin = new Coin();
coin.x = x;
coin.y = y;
coin.originalY = y;
coins.push(coin);
game.addChild(coin);
return coin;
}
// Generate initial platforms
for (var i = 0; i < 15; i++) {
var platformY = 2732 - i * platformSpacing;
var platformX = Math.random() * (2048 - 280) + 140;
var platformType = 'normal';
if (i > 2) {
var rand = Math.random();
if (rand < 0.1) platformType = 'breakable';else if (rand < 0.2) platformType = 'moving';else if (rand < 0.25) platformType = 'spring';
}
createPlatform(platformX, platformY, platformType);
// Add coins near some platforms
if (i > 0 && Math.random() < 0.4) {
var coinX = platformX + (Math.random() - 0.5) * 200;
coinX = Math.max(40, Math.min(2008, coinX));
createCoin(coinX, platformY - 80);
}
lastPlatformY = platformY;
}
// Generate more platforms as needed
function generatePlatforms() {
while (lastPlatformY > camera.y - 1000) {
lastPlatformY -= platformSpacing + (Math.random() * 100 - 50);
var platformX = Math.random() * (2048 - 280) + 140;
var platformType = 'normal';
var rand = Math.random();
if (rand < 0.15) platformType = 'breakable';else if (rand < 0.3) platformType = 'moving';else if (rand < 0.35) platformType = 'spring';
createPlatform(platformX, lastPlatformY, platformType);
// Add coins near some platforms
if (Math.random() < 0.4) {
var coinX = platformX + (Math.random() - 0.5) * 200;
coinX = Math.max(40, Math.min(2008, coinX));
createCoin(coinX, lastPlatformY - 80);
}
}
}
// Input handling
game.down = function (x, y, obj) {
if (x < 1024) {
player.moveLeft();
} else {
player.moveRight();
}
};
game.update = function () {
// Update camera to follow player
var targetCameraY = player.y - 1800;
if (targetCameraY < camera.y) {
camera.y = targetCameraY;
game.y = -camera.y;
}
// Update max height and score
var currentHeight = Math.max(0, Math.floor((2732 - player.y) / 10));
if (currentHeight > maxHeight) {
maxHeight = currentHeight;
LK.setScore(maxHeight);
scoreTxt.setText(maxHeight.toString());
}
// Generate new platforms
generatePlatforms();
// Check coin collisions
for (var i = coins.length - 1; i >= 0; i--) {
var coin = coins[i];
// Remove coins that are too far below
if (coin.y > camera.y + 3000) {
coin.destroy();
coins.splice(i, 1);
continue;
}
// Check collision with player
if (!coin.collected && player.intersects(coin)) {
if (coin.collect()) {
totalCoins++;
storage.totalCoins = totalCoins;
coinTxt.setText('Coins: ' + totalCoins);
coins.splice(i, 1);
}
}
}
// Check platform collisions
for (var i = platforms.length - 1; i >= 0; i--) {
var platform = platforms[i];
// Remove platforms that are too far below
if (platform.y > camera.y + 3000) {
platform.destroy();
platforms.splice(i, 1);
continue;
}
// Check collision with player
if (player.isJumping && player.intersects(platform)) {
var playerBottom = player.y + 40;
var platformTop = platform.y - 20;
if (playerBottom > platformTop && playerBottom < platformTop + 50) {
var jumpResult = platform.onLanded();
if (jumpResult === false) {
// Breakable platform - no jump
continue;
} else if (typeof jumpResult === 'number') {
// Spring platform - custom jump power
player.jump(jumpResult);
} else {
// Normal platform - regular jump
player.jump();
}
}
}
}
// Game over condition
if (player.y > camera.y + 2732 + 200) {
LK.showGameOver();
}
};