User prompt
Craft the scene so that the cube rotates gracefully in mid-air, suspended in an ethereal dance, untethered from the ground below. Its smooth surfaces reflect ambient light, creating a mesmerizing play of shadows and glimmers as it slowly spins, capturing the imagination with its enchanting motion. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'tween(cubeGlow).to({' Line Number: 124 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'tween(cubeGlow).to({' Line Number: 124
User prompt
Enhance the quality and value of the assets.
User prompt
Transform the spikes into elegant triangular forms, giving them a sharper and more dynamic appearance.
User prompt
Enable access to all levels right from the beginning, allowing players to explore the entire game world without restrictions.
User prompt
Make a starting screen where there is different levels that get harder and harder
User prompt
Make the assets better
User prompt
Make you jump higher
User prompt
Make it easier
Code edit (1 edits merged)
Please save this source code
User prompt
Dash Jump
Initial prompt
Make geometry dash
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Cube = Container.expand(function () {
var self = Container.call(this);
var cubeGraphics = self.attachAsset('cube', {
anchorX: 0.5,
anchorY: 1.0
});
var cubeHighlight = self.attachAsset('cubeHighlight', {
anchorX: 0.5,
anchorY: 1.0
});
cubeHighlight.alpha = 0.3;
var cubeCore = self.attachAsset('cubeCore', {
anchorX: 0.5,
anchorY: 1.0
});
self.velocityY = 0;
self.gravity = 0.5;
self.jumpForce = -18;
self.maxJumpForce = -24;
self.isGrounded = false;
self.groundY = 2400;
self.update = function () {
// Apply gravity
self.velocityY += self.gravity;
self.y += self.velocityY;
// Rotate cube continuously for visual appeal
self.rotation += 0.05;
// Ground collision
if (self.y >= self.groundY) {
self.y = self.groundY;
self.velocityY = 0;
self.isGrounded = true;
} else {
self.isGrounded = false;
}
};
self.jump = function (force) {
if (self.isGrounded) {
self.velocityY = force;
self.isGrounded = false;
LK.getSound('jump').play();
}
};
return self;
});
var Ground = Container.expand(function () {
var self = Container.call(this);
var groundGraphics = self.attachAsset('ground', {
anchorX: 0,
anchorY: 0
});
var groundPattern = self.attachAsset('groundPattern', {
anchorX: 0,
anchorY: 0
});
groundPattern.x = 10;
groundPattern.y = 10;
self.speed = -5;
self.update = function () {
self.x += self.speed;
};
return self;
});
var LevelButton = Container.expand(function (levelNum, config, unlocked) {
var self = Container.call(this);
self.levelNum = levelNum;
self.unlocked = unlocked;
// Button background
var buttonBg = self.attachAsset('ground', {
anchorX: 0.5,
anchorY: 0.5
});
buttonBg.width = 300;
buttonBg.height = 120;
if (!unlocked) {
buttonBg.tint = 0x666666;
}
// Level number text
var levelText = new Text2(levelNum.toString(), {
size: 60,
fill: unlocked ? 0xFFFFFF : 0x999999
});
levelText.anchor.set(0.5, 0.3);
self.addChild(levelText);
// Level name text
var nameText = new Text2(config.name, {
size: 30,
fill: unlocked ? 0xFFFFFF : 0x999999
});
nameText.anchor.set(0.5, 0.7);
self.addChild(nameText);
self.down = function (x, y, obj) {
if (self.unlocked) {
selectedLevel = self.levelNum;
startLevel(selectedLevel);
}
};
return self;
});
var Obstacle = Container.expand(function (type) {
var self = Container.call(this);
var obstacleGraphics;
self.type = type || 'spike';
self.speed = -5;
if (self.type === 'spike') {
obstacleGraphics = self.attachAsset('spike', {
anchorX: 0.5,
anchorY: 1.0
});
var spikeCore = self.attachAsset('spikeCore', {
anchorX: 0.5,
anchorY: 1.0
});
} else if (self.type === 'barrier') {
obstacleGraphics = self.attachAsset('barrier', {
anchorX: 0.5,
anchorY: 0.5
});
var barrierHighlight = self.attachAsset('barrierHighlight', {
anchorX: 0.5,
anchorY: 0.5
});
}
self.update = function () {
self.x += self.speed;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1e3c72
});
/****
* Game Code
****/
var cube;
var obstacles = [];
var groundTiles = [];
var isJumping = false;
var jumpStartTime = 0;
var gameSpeed = 5;
var distance = 0;
var obstacleTimer = 0;
var groundTimer = 0;
// Game state management
var gameState = 'menu'; // 'menu' or 'playing'
var selectedLevel = 1;
var maxUnlockedLevel = 1;
var levelButtons = [];
// Level configurations
var levelConfigs = [{
name: "Easy Jump",
speed: 3,
obstacleFreq: 120,
gravity: 0.3
}, {
name: "Medium Hop",
speed: 5,
obstacleFreq: 90,
gravity: 0.5
}, {
name: "Hard Leap",
speed: 7,
obstacleFreq: 70,
gravity: 0.7
}, {
name: "Expert Dash",
speed: 9,
obstacleFreq: 50,
gravity: 0.9
}, {
name: "Master Jump",
speed: 12,
obstacleFreq: 40,
gravity: 1.2
}];
function createMenu() {
gameState = 'menu';
// Clear any existing game elements
clearGameElements();
// Title
var titleText = new Text2('DASH JUMP', {
size: 120,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0);
titleText.x = 2048 / 2;
titleText.y = 400;
game.addChild(titleText);
// Level selection title
var selectText = new Text2('SELECT LEVEL', {
size: 60,
fill: 0xFFFFFF
});
selectText.anchor.set(0.5, 0);
selectText.x = 2048 / 2;
selectText.y = 600;
game.addChild(selectText);
// Create level buttons
levelButtons = [];
for (var i = 0; i < levelConfigs.length; i++) {
var levelNum = i + 1;
var unlocked = levelNum <= maxUnlockedLevel;
var button = game.addChild(new LevelButton(levelNum, levelConfigs[i], unlocked));
var row = Math.floor(i / 2);
var col = i % 2;
button.x = 2048 / 2 + (col - 0.5) * 350;
button.y = 800 + row * 200;
levelButtons.push(button);
}
}
function clearGameElements() {
// Remove all children except GUI elements
for (var i = game.children.length - 1; i >= 0; i--) {
game.children[i].destroy();
}
// Clear arrays
obstacles = [];
groundTiles = [];
levelButtons = [];
}
function startLevel(levelNum) {
gameState = 'playing';
var config = levelConfigs[levelNum - 1];
// Clear menu
clearGameElements();
// Apply level configuration
gameSpeed = config.speed;
// Initialize cube with level settings
cube = game.addChild(new Cube());
cube.x = 300;
cube.y = 2400;
cube.gravity = config.gravity;
// Initialize ground tiles
for (var i = 0; i < 15; i++) {
var groundTile = game.addChild(new Ground());
groundTile.x = i * 200;
groundTile.y = 2440;
groundTile.speed = -gameSpeed;
groundTiles.push(groundTile);
}
// Reset game variables
distance = 0;
obstacleTimer = 0;
groundTimer = 0;
isJumping = false;
// Update score display
scoreTxt.setText('Level ' + levelNum + ' - Distance: 0');
}
// Initialize menu instead of game
createMenu();
// Score display
var scoreTxt = new Text2('Distance: 0', {
size: 60,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
function spawnObstacle() {
var obstacleType = Math.random() < 0.7 ? 'spike' : 'barrier';
var obstacle = game.addChild(new Obstacle(obstacleType));
obstacle.x = 2200;
obstacle.speed = -gameSpeed;
if (obstacleType === 'spike') {
obstacle.y = 2400;
} else {
obstacle.y = Math.random() < 0.5 ? 2300 : 2200;
}
obstacles.push(obstacle);
}
function spawnGround() {
var groundTile = game.addChild(new Ground());
groundTile.x = 2200;
groundTile.y = 2440;
groundTile.speed = -gameSpeed;
groundTiles.push(groundTile);
}
game.down = function (x, y, obj) {
if (gameState === 'playing' && !isJumping) {
isJumping = true;
jumpStartTime = LK.ticks;
}
};
game.up = function (x, y, obj) {
if (gameState === 'playing' && isJumping) {
var holdDuration = LK.ticks - jumpStartTime;
var jumpForce = cube.jumpForce;
// Increase jump force based on hold duration (max 30 ticks)
if (holdDuration > 5) {
var extraForce = Math.min(holdDuration - 5, 25) * 0.2;
jumpForce = cube.jumpForce - extraForce;
jumpForce = Math.max(jumpForce, cube.maxJumpForce);
}
cube.jump(jumpForce);
isJumping = false;
}
};
game.update = function () {
if (gameState !== 'playing') return;
// Update distance
distance += 0.1;
scoreTxt.setText('Level ' + selectedLevel + ' - Distance: ' + Math.floor(distance));
// Check level completion (every 200 distance units)
if (Math.floor(distance) >= 200) {
// Level completed
if (selectedLevel < levelConfigs.length) {
// Unlock next level
if (selectedLevel + 1 > maxUnlockedLevel) {
maxUnlockedLevel = selectedLevel + 1;
}
}
createMenu();
return;
}
var config = levelConfigs[selectedLevel - 1];
// Spawn obstacles
obstacleTimer++;
if (obstacleTimer >= config.obstacleFreq + Math.random() * 30) {
spawnObstacle();
obstacleTimer = 0;
}
// Spawn ground tiles
groundTimer++;
if (groundTimer >= 25) {
spawnGround();
groundTimer = 0;
}
// Update and check obstacles
for (var i = obstacles.length - 1; i >= 0; i--) {
var obstacle = obstacles[i];
if (obstacle.lastX === undefined) obstacle.lastX = obstacle.x;
// Remove off-screen obstacles
if (obstacle.lastX >= -100 && obstacle.x < -100) {
obstacle.destroy();
obstacles.splice(i, 1);
continue;
}
// Check collision with cube
if (obstacle.intersects(cube)) {
LK.getSound('death').play();
LK.effects.flashScreen(0xff0000, 500);
createMenu();
return;
}
obstacle.lastX = obstacle.x;
}
// Update and check ground tiles
for (var j = groundTiles.length - 1; j >= 0; j--) {
var ground = groundTiles[j];
if (ground.lastX === undefined) ground.lastX = ground.x;
// Remove off-screen ground tiles
if (ground.lastX >= -200 && ground.x < -200) {
ground.destroy();
groundTiles.splice(j, 1);
continue;
}
ground.lastX = ground.x;
}
}; ===================================================================
--- original.js
+++ change.js
@@ -68,8 +68,44 @@
self.x += self.speed;
};
return self;
});
+var LevelButton = Container.expand(function (levelNum, config, unlocked) {
+ var self = Container.call(this);
+ self.levelNum = levelNum;
+ self.unlocked = unlocked;
+ // Button background
+ var buttonBg = self.attachAsset('ground', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ buttonBg.width = 300;
+ buttonBg.height = 120;
+ if (!unlocked) {
+ buttonBg.tint = 0x666666;
+ }
+ // Level number text
+ var levelText = new Text2(levelNum.toString(), {
+ size: 60,
+ fill: unlocked ? 0xFFFFFF : 0x999999
+ });
+ levelText.anchor.set(0.5, 0.3);
+ self.addChild(levelText);
+ // Level name text
+ var nameText = new Text2(config.name, {
+ size: 30,
+ fill: unlocked ? 0xFFFFFF : 0x999999
+ });
+ nameText.anchor.set(0.5, 0.7);
+ self.addChild(nameText);
+ self.down = function (x, y, obj) {
+ if (self.unlocked) {
+ selectedLevel = self.levelNum;
+ startLevel(selectedLevel);
+ }
+ };
+ return self;
+});
var Obstacle = Container.expand(function (type) {
var self = Container.call(this);
var obstacleGraphics;
self.type = type || 'spike';
@@ -117,19 +153,115 @@
var gameSpeed = 5;
var distance = 0;
var obstacleTimer = 0;
var groundTimer = 0;
-// Initialize cube
-cube = game.addChild(new Cube());
-cube.x = 300;
-cube.y = 2400;
-// Initialize ground tiles
-for (var i = 0; i < 15; i++) {
- var groundTile = game.addChild(new Ground());
- groundTile.x = i * 200;
- groundTile.y = 2440;
- groundTiles.push(groundTile);
+// Game state management
+var gameState = 'menu'; // 'menu' or 'playing'
+var selectedLevel = 1;
+var maxUnlockedLevel = 1;
+var levelButtons = [];
+// Level configurations
+var levelConfigs = [{
+ name: "Easy Jump",
+ speed: 3,
+ obstacleFreq: 120,
+ gravity: 0.3
+}, {
+ name: "Medium Hop",
+ speed: 5,
+ obstacleFreq: 90,
+ gravity: 0.5
+}, {
+ name: "Hard Leap",
+ speed: 7,
+ obstacleFreq: 70,
+ gravity: 0.7
+}, {
+ name: "Expert Dash",
+ speed: 9,
+ obstacleFreq: 50,
+ gravity: 0.9
+}, {
+ name: "Master Jump",
+ speed: 12,
+ obstacleFreq: 40,
+ gravity: 1.2
+}];
+function createMenu() {
+ gameState = 'menu';
+ // Clear any existing game elements
+ clearGameElements();
+ // Title
+ var titleText = new Text2('DASH JUMP', {
+ size: 120,
+ fill: 0xFFFFFF
+ });
+ titleText.anchor.set(0.5, 0);
+ titleText.x = 2048 / 2;
+ titleText.y = 400;
+ game.addChild(titleText);
+ // Level selection title
+ var selectText = new Text2('SELECT LEVEL', {
+ size: 60,
+ fill: 0xFFFFFF
+ });
+ selectText.anchor.set(0.5, 0);
+ selectText.x = 2048 / 2;
+ selectText.y = 600;
+ game.addChild(selectText);
+ // Create level buttons
+ levelButtons = [];
+ for (var i = 0; i < levelConfigs.length; i++) {
+ var levelNum = i + 1;
+ var unlocked = levelNum <= maxUnlockedLevel;
+ var button = game.addChild(new LevelButton(levelNum, levelConfigs[i], unlocked));
+ var row = Math.floor(i / 2);
+ var col = i % 2;
+ button.x = 2048 / 2 + (col - 0.5) * 350;
+ button.y = 800 + row * 200;
+ levelButtons.push(button);
+ }
}
+function clearGameElements() {
+ // Remove all children except GUI elements
+ for (var i = game.children.length - 1; i >= 0; i--) {
+ game.children[i].destroy();
+ }
+ // Clear arrays
+ obstacles = [];
+ groundTiles = [];
+ levelButtons = [];
+}
+function startLevel(levelNum) {
+ gameState = 'playing';
+ var config = levelConfigs[levelNum - 1];
+ // Clear menu
+ clearGameElements();
+ // Apply level configuration
+ gameSpeed = config.speed;
+ // Initialize cube with level settings
+ cube = game.addChild(new Cube());
+ cube.x = 300;
+ cube.y = 2400;
+ cube.gravity = config.gravity;
+ // Initialize ground tiles
+ for (var i = 0; i < 15; i++) {
+ var groundTile = game.addChild(new Ground());
+ groundTile.x = i * 200;
+ groundTile.y = 2440;
+ groundTile.speed = -gameSpeed;
+ groundTiles.push(groundTile);
+ }
+ // Reset game variables
+ distance = 0;
+ obstacleTimer = 0;
+ groundTimer = 0;
+ isJumping = false;
+ // Update score display
+ scoreTxt.setText('Level ' + levelNum + ' - Distance: 0');
+}
+// Initialize menu instead of game
+createMenu();
// Score display
var scoreTxt = new Text2('Distance: 0', {
size: 60,
fill: 0xFFFFFF
@@ -139,8 +271,9 @@
function spawnObstacle() {
var obstacleType = Math.random() < 0.7 ? 'spike' : 'barrier';
var obstacle = game.addChild(new Obstacle(obstacleType));
obstacle.x = 2200;
+ obstacle.speed = -gameSpeed;
if (obstacleType === 'spike') {
obstacle.y = 2400;
} else {
obstacle.y = Math.random() < 0.5 ? 2300 : 2200;
@@ -150,45 +283,19 @@
function spawnGround() {
var groundTile = game.addChild(new Ground());
groundTile.x = 2200;
groundTile.y = 2440;
+ groundTile.speed = -gameSpeed;
groundTiles.push(groundTile);
}
-function resetGame() {
- // Reset cube position
- cube.x = 300;
- cube.y = 2400;
- cube.velocityY = 0;
- cube.isGrounded = true;
- // Clear obstacles
- for (var i = obstacles.length - 1; i >= 0; i--) {
- obstacles[i].destroy();
- obstacles.splice(i, 1);
- }
- // Reset ground
- for (var j = groundTiles.length - 1; j >= 0; j--) {
- if (j >= 15) {
- groundTiles[j].destroy();
- groundTiles.splice(j, 1);
- } else {
- groundTiles[j].x = j * 200;
- }
- }
- // Reset game variables
- distance = 0;
- obstacleTimer = 0;
- groundTimer = 0;
- isJumping = false;
- scoreTxt.setText('Distance: 0');
-}
game.down = function (x, y, obj) {
- if (!isJumping) {
+ if (gameState === 'playing' && !isJumping) {
isJumping = true;
jumpStartTime = LK.ticks;
}
};
game.up = function (x, y, obj) {
- if (isJumping) {
+ if (gameState === 'playing' && isJumping) {
var holdDuration = LK.ticks - jumpStartTime;
var jumpForce = cube.jumpForce;
// Increase jump force based on hold duration (max 30 ticks)
if (holdDuration > 5) {
@@ -200,14 +307,28 @@
isJumping = false;
}
};
game.update = function () {
+ if (gameState !== 'playing') return;
// Update distance
distance += 0.1;
- scoreTxt.setText('Distance: ' + Math.floor(distance));
+ scoreTxt.setText('Level ' + selectedLevel + ' - Distance: ' + Math.floor(distance));
+ // Check level completion (every 200 distance units)
+ if (Math.floor(distance) >= 200) {
+ // Level completed
+ if (selectedLevel < levelConfigs.length) {
+ // Unlock next level
+ if (selectedLevel + 1 > maxUnlockedLevel) {
+ maxUnlockedLevel = selectedLevel + 1;
+ }
+ }
+ createMenu();
+ return;
+ }
+ var config = levelConfigs[selectedLevel - 1];
// Spawn obstacles
obstacleTimer++;
- if (obstacleTimer >= 90 + Math.random() * 90) {
+ if (obstacleTimer >= config.obstacleFreq + Math.random() * 30) {
spawnObstacle();
obstacleTimer = 0;
}
// Spawn ground tiles
@@ -229,9 +350,9 @@
// Check collision with cube
if (obstacle.intersects(cube)) {
LK.getSound('death').play();
LK.effects.flashScreen(0xff0000, 500);
- resetGame();
+ createMenu();
return;
}
obstacle.lastX = obstacle.x;
}
@@ -246,16 +367,5 @@
continue;
}
ground.lastX = ground.x;
}
- // Increase difficulty over time
- if (Math.floor(distance) % 150 === 0 && Math.floor(distance) > 0) {
- gameSpeed = Math.min(gameSpeed + 0.05, 10);
- // Update speeds for all moving objects
- for (var k = 0; k < obstacles.length; k++) {
- obstacles[k].speed = -gameSpeed;
- }
- for (var l = 0; l < groundTiles.length; l++) {
- groundTiles[l].speed = -gameSpeed;
- }
- }
};
\ No newline at end of file