User prompt
if you get score 10, it goes to level two and level two is different
User prompt
Make the score go up one every time you pass a spike
User prompt
Make the score not go up every second
User prompt
Make the score go up when you pass a spike and make it infinite when you pass a spike like the numbers keep going on and until you end the game
User prompt
I don’t hear any noise make the sound sound like what they’re titled
User prompt
Make the sounds play when needed
User prompt
Make the square jump higher, but not so high, so it can finally dodged the spikes ↪💡 Consider importing and using the following plugins: @upit/tween.v1
Code edit (1 edits merged)
Please save this source code
User prompt
Spike Dash
Initial prompt
Add geometry Dash with spikes because that’s why it comes with
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1", {
highScore: 0,
currentLevel: 1
});
/****
* Classes
****/
var Particle = Container.expand(function () {
var self = Container.call(this);
var particleGraphics = self.attachAsset('particle', {
anchorX: 0.5,
anchorY: 0.5
});
self.velX = (Math.random() - 0.5) * 10;
self.velY = (Math.random() - 0.5) * 10 - 5;
self.gravity = 0.3;
self.life = 30 + Math.random() * 30;
self.maxLife = self.life;
self.update = function () {
self.velY += self.gravity;
self.x += self.velX;
self.y += self.velY;
self.life--;
self.alpha = self.life / self.maxLife;
if (self.life <= 0) {
self.destroy();
var index = particles.indexOf(self);
if (index !== -1) {
particles.splice(index, 1);
}
}
};
return self;
});
var Platform = Container.expand(function () {
var self = Container.call(this);
var platformGraphics = self.attachAsset('platform', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.active = true;
self.update = function () {
if (!self.active) {
return;
}
self.x -= self.speed;
// If platform is off-screen to the left, deactivate it
if (self.x < -platformGraphics.width) {
self.active = false;
}
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.gravity = 0.6;
self.jumpForce = -19;
self.velocity = 0;
self.isJumping = false;
self.isDead = false;
self.isOnGround = false;
self.jump = function () {
if (self.isOnGround && !self.isDead) {
self.velocity = self.jumpForce;
self.isJumping = true;
self.isOnGround = false;
LK.getSound('jump').play();
self.createJumpEffect();
// Add a small boost at the peak of jump for better spike dodging
LK.setTimeout(function () {
if (self.isJumping && !self.isDead && self.velocity > -2 && self.velocity < 2) {
// Small horizontal push
tween(self, {
x: self.x + 20
}, {
duration: 300,
easing: tween.easeOut
});
}
}, 300);
}
};
self.createJumpEffect = function () {
for (var i = 0; i < 5; i++) {
var particle = new Particle();
particle.x = self.x;
particle.y = self.y + 30;
game.addChild(particle);
particles.push(particle);
}
};
self.die = function () {
if (!self.isDead) {
self.isDead = true;
LK.getSound('death').play();
LK.effects.flashObject(self, 0xff0000, 500);
LK.effects.flashScreen(0xff0000, 300);
// Create death particles
for (var i = 0; i < 15; i++) {
var particle = new Particle();
particle.x = self.x;
particle.y = self.y;
game.addChild(particle);
particles.push(particle);
}
LK.setTimeout(function () {
LK.showGameOver();
}, 1000);
}
};
self.update = function () {
if (self.isDead) {
return;
}
// Apply gravity
self.velocity += self.gravity;
self.y += self.velocity;
// Check ground collision
if (self.y >= groundY - playerGraphics.height / 2) {
self.y = groundY - playerGraphics.height / 2;
self.velocity = 0;
self.isJumping = false;
self.isOnGround = true;
}
// Check ceiling collision
if (self.y <= ceilingY + playerGraphics.height / 2) {
self.y = ceilingY + playerGraphics.height / 2;
self.velocity = 0;
}
// Rotate player based on movement
if (self.isJumping) {
playerGraphics.rotation += 0.1;
} else {
// Gradually reset rotation when on ground
playerGraphics.rotation = playerGraphics.rotation % (Math.PI * 2);
if (playerGraphics.rotation > 0.1) {
playerGraphics.rotation -= 0.1;
} else if (playerGraphics.rotation < -0.1) {
playerGraphics.rotation += 0.1;
} else {
playerGraphics.rotation = 0;
}
}
};
return self;
});
var Spike = Container.expand(function () {
var self = Container.call(this);
var spikeGraphics = self.attachAsset('spike', {
anchorX: 0.5,
anchorY: 0.5
});
self.rotation = Math.PI / 4; // Rotate to make it look like a spike
self.speed = 5;
self.active = true;
self.update = function () {
if (!self.active) {
return;
}
self.x -= self.speed;
// If spike is off-screen to the left, deactivate it
if (self.x < -50) {
self.active = false;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x34495e
});
/****
* Game Code
****/
// Game variables
var player;
var obstacles = [];
var platforms = [];
var particles = [];
var groundY = 2500;
var ceilingY = 200;
var score = 0;
var obstacleTimer = 0;
var obstacleInterval = 90; // Frames between obstacle spawns
var platformTimer = 0;
var platformInterval = 180; // Frames between platform spawns
var difficultyTimer = 0;
var difficultyInterval = 600; // Frames before increasing difficulty
var gameSpeed = 5;
var maxGameSpeed = 12;
var isGameStarted = false;
var distanceTraveled = 0;
// Create score text
var scoreTxt = new Text2('0', {
size: 100,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Create level text
var levelTxt = new Text2('Level 1', {
size: 60,
fill: 0xFFFFFF
});
levelTxt.anchor.set(0.5, 0);
levelTxt.y = 120;
LK.gui.top.addChild(levelTxt);
// Create ground
var ground = game.addChild(LK.getAsset('ground', {
anchorX: 0,
anchorY: 0,
x: 0,
y: groundY
}));
// Create ceiling
var ceiling = game.addChild(LK.getAsset('ceiling', {
anchorX: 0,
anchorY: 0,
x: 0,
y: ceilingY - 40
}));
// Create player
player = new Player();
player.x = 400;
player.y = groundY - 100;
game.addChild(player);
// Create instructions text
var instructionsTxt = new Text2('Tap to jump and avoid spikes!', {
size: 80,
fill: 0xFFFFFF
});
instructionsTxt.anchor.set(0.5, 0.5);
instructionsTxt.x = 2048 / 2;
instructionsTxt.y = 2732 / 2;
game.addChild(instructionsTxt);
// Create tap to start text
var startTxt = new Text2('Tap to Start', {
size: 120,
fill: 0xFFFFFF
});
startTxt.anchor.set(0.5, 0.5);
startTxt.x = 2048 / 2;
startTxt.y = 2732 / 2 + 200;
game.addChild(startTxt);
// Handle user input
game.down = function (x, y, obj) {
if (!isGameStarted) {
startGame();
} else if (!player.isDead) {
player.jump();
}
};
function startGame() {
isGameStarted = true;
instructionsTxt.visible = false;
startTxt.visible = false;
// Reset score and level
score = 0;
updateScore(0);
updateLevel(storage.currentLevel);
// Play background music
LK.playMusic('gameMusic');
}
function createSpike() {
var spike = new Spike();
spike.x = 2100;
spike.y = groundY - spike.height / 2;
game.addChild(spike);
obstacles.push(spike);
}
function createPlatform() {
var platform = new Platform();
platform.x = 2100;
// Random y position but ensure it's not too close to ground or ceiling
var minY = ceilingY + 200;
var maxY = groundY - 200;
platform.y = minY + Math.random() * (maxY - minY);
game.addChild(platform);
platforms.push(platform);
}
function updateScore(value) {
score = value;
scoreTxt.setText('Score: ' + score);
LK.setScore(score);
// Update high score if needed
if (score > storage.highScore) {
storage.highScore = score;
}
}
function updateLevel(level) {
storage.currentLevel = level;
levelTxt.setText('Level ' + level);
// Adjust difficulty based on level
obstacleInterval = Math.max(30, 90 - (level - 1) * 10);
platformInterval = Math.max(60, 180 - (level - 1) * 20);
gameSpeed = Math.min(maxGameSpeed, 5 + (level - 1) * 0.5);
// Update obstacle speeds
obstacles.forEach(function (obstacle) {
if (obstacle.active) {
obstacle.speed = gameSpeed;
}
});
// Update platform speeds
platforms.forEach(function (platform) {
if (platform.active) {
platform.speed = gameSpeed;
}
});
}
function checkCollisions() {
if (player.isDead) {
return;
}
// Check spike collisions
for (var i = 0; i < obstacles.length; i++) {
var obstacle = obstacles[i];
if (obstacle.active && player.intersects(obstacle)) {
player.die();
return;
}
}
// Check platform collisions
var wasOnPlatform = false;
for (var j = 0; j < platforms.length; j++) {
var platform = platforms[j];
if (platform.active && player.intersects(platform)) {
// Only if player is falling and above the platform
if (player.velocity > 0 && player.y < platform.y - platform.height / 2) {
player.y = platform.y - platform.height / 2 - player.height / 2;
player.velocity = 0;
player.isJumping = false;
player.isOnGround = true;
wasOnPlatform = true;
}
}
}
// If not on a platform and not on the ground, player is in the air
if (!wasOnPlatform && player.y < groundY - player.height / 2) {
player.isOnGround = false;
}
}
function clearInactiveObjects() {
// Clear inactive obstacles
for (var i = obstacles.length - 1; i >= 0; i--) {
if (!obstacles[i].active) {
obstacles[i].destroy();
obstacles.splice(i, 1);
}
}
// Clear inactive platforms
for (var j = platforms.length - 1; j >= 0; j--) {
if (!platforms[j].active) {
platforms[j].destroy();
platforms.splice(j, 1);
}
}
}
function levelComplete() {
LK.getSound('levelComplete').play();
LK.effects.flashScreen(0x27ae60, 500);
var levelCompleteTxt = new Text2('LEVEL COMPLETE!', {
size: 120,
fill: 0xFFFFFF
});
levelCompleteTxt.anchor.set(0.5, 0.5);
levelCompleteTxt.x = 2048 / 2;
levelCompleteTxt.y = 2732 / 2;
game.addChild(levelCompleteTxt);
// Clear all obstacles and platforms
obstacles.forEach(function (obstacle) {
obstacle.destroy();
});
obstacles = [];
platforms.forEach(function (platform) {
platform.destroy();
});
platforms = [];
// Reset player position
player.x = 400;
player.y = groundY - 100;
player.velocity = 0;
player.isJumping = false;
player.isOnGround = true;
// Advance to next level after a short delay
LK.setTimeout(function () {
levelCompleteTxt.destroy();
updateLevel(storage.currentLevel + 1);
}, 2000);
}
// Main game update loop
game.update = function () {
if (!isGameStarted || player.isDead) {
return;
}
// Increase distance traveled and score
distanceTraveled += gameSpeed;
if (distanceTraveled % 100 === 0) {
updateScore(score + 1);
}
// Check for level completion
if (score > 0 && score % 100 === 0) {
// Only trigger once when exactly hitting the target
if (score % 200 !== 0) {
levelComplete();
}
}
// Spawn new obstacles
obstacleTimer++;
if (obstacleTimer >= obstacleInterval) {
createSpike();
obstacleTimer = 0;
}
// Spawn new platforms
platformTimer++;
if (platformTimer >= platformInterval) {
createPlatform();
platformTimer = 0;
}
// Increase difficulty over time
difficultyTimer++;
if (difficultyTimer >= difficultyInterval) {
gameSpeed = Math.min(maxGameSpeed, gameSpeed + 0.1);
difficultyTimer = 0;
}
// Update obstacles
for (var i = 0; i < obstacles.length; i++) {
obstacles[i].update();
}
// Update platforms
for (var j = 0; j < platforms.length; j++) {
platforms[j].update();
}
// Update particles
for (var k = 0; k < particles.length; k++) {
particles[k].update();
}
// Update player
player.update();
// Check collisions
checkCollisions();
// Clean up inactive objects
clearInactiveObjects();
}; ===================================================================
--- original.js
+++ change.js
@@ -62,10 +62,10 @@
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
- self.gravity = 0.7;
- self.jumpForce = -15;
+ self.gravity = 0.6;
+ self.jumpForce = -19;
self.velocity = 0;
self.isJumping = false;
self.isDead = false;
self.isOnGround = false;
@@ -75,8 +75,20 @@
self.isJumping = true;
self.isOnGround = false;
LK.getSound('jump').play();
self.createJumpEffect();
+ // Add a small boost at the peak of jump for better spike dodging
+ LK.setTimeout(function () {
+ if (self.isJumping && !self.isDead && self.velocity > -2 && self.velocity < 2) {
+ // Small horizontal push
+ tween(self, {
+ x: self.x + 20
+ }, {
+ duration: 300,
+ easing: tween.easeOut
+ });
+ }
+ }, 300);
}
};
self.createJumpEffect = function () {
for (var i = 0; i < 5; i++) {