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"); /**** * Classes ****/ 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 <= 90 || self.x >= 1958) { 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 -38; // 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 = -28; 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 camera = { y: 0 }; var maxHeight = 0; var platformSpacing = 200; var lastPlatformY = 2732; // Initialize score display var scoreTxt = new Text2('0', { size: 80, fill: 0x000000 }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // 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; } // Generate initial platforms for (var i = 0; i < 15; i++) { var platformY = 2732 - i * platformSpacing; var platformX = Math.random() * (2048 - 180) + 90; 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); 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 - 180) + 90; 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); } } // 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 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 - 10; if (playerBottom > platformTop && playerBottom < platformTop + 30) { 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(); } };
===================================================================
--- original.js
+++ change.js
@@ -57,9 +57,9 @@
self.velocityY = 0;
self.velocityX = 0;
self.gravity = 0.6;
self.jumpPower = -28;
- self.maxVelocityX = 12;
+ self.maxVelocityX = 18;
self.friction = 0.9;
self.isJumping = false;
self.update = function () {
// Apply gravity
@@ -83,12 +83,12 @@
self.velocityY = power;
LK.getSound('jump').play();
};
self.moveLeft = function () {
- self.velocityX = Math.max(self.velocityX - 2.5, -self.maxVelocityX);
+ self.velocityX = Math.max(self.velocityX - 4.0, -self.maxVelocityX);
};
self.moveRight = function () {
- self.velocityX = Math.min(self.velocityX + 2.5, self.maxVelocityX);
+ self.velocityX = Math.min(self.velocityX + 4.0, self.maxVelocityX);
};
return self;
});