User prompt
Increase the stones even more and arrange them so that they do not hit each other
User prompt
If rocks hit each other, they will break into pieces
User prompt
rocks should not pass through each other and the number of rocks should gradually increase
User prompt
Let some rocks fall faster
Code edit (1 edits merged)
Please save this source code
User prompt
Rock Dodge
Initial prompt
Make a game where we run away from falling rocks
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 8;
return self;
});
var Rock = Container.expand(function (rockType) {
var self = Container.call(this);
var assetName = rockType || 'rock_medium';
var rockGraphics = self.attachAsset(assetName, {
anchorX: 0.5,
anchorY: 0.5
});
// Set falling speed based on rock type
if (assetName === 'rock_small') {
self.fallSpeed = 3;
} else if (assetName === 'rock_medium') {
self.fallSpeed = 4;
} else {
self.fallSpeed = 2;
}
// Add chance for fast-falling rocks (20% chance)
if (Math.random() < 0.2) {
self.fallSpeed *= 2.5; // Make some rocks fall much faster
}
self.update = function () {
// Check collision with other rocks before moving
var proposedY = self.y + self.fallSpeed;
var canMove = true;
// Check against all other rocks
for (var i = 0; i < rocks.length; i++) {
var otherRock = rocks[i];
if (otherRock === self) continue; // Skip self
// Check if we would collide with another rock
var tempY = self.y;
self.y = proposedY;
if (self.intersects(otherRock)) {
canMove = false;
}
self.y = tempY; // Restore original position
if (!canMove) break;
}
// Only move if no collision would occur
if (canMove) {
self.y = proposedY;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87ceeb
});
/****
* Game Code
****/
// Game variables
var player;
var rocks = [];
var rockSpawnTimer = 0;
var rockSpawnDelay = 90; // Initial spawn delay (60fps = 1.5 seconds)
var gameSpeed = 1;
var speedIncreaseTimer = 0;
var dragNode = null;
// UI Elements
var scoreTxt = new Text2('0', {
size: 100,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var timeTxt = new Text2('Time: 0s', {
size: 60,
fill: 0xFFFFFF
});
timeTxt.anchor.set(0, 0);
timeTxt.x = 50;
timeTxt.y = 150;
LK.gui.topLeft.addChild(timeTxt);
// Initialize player
player = game.addChild(new Player());
player.x = 2048 / 2;
player.y = 2732 - 150;
// Game state tracking
var gameTime = 0;
var lastIntersecting = false;
// Rock types for variety
var rockTypes = ['rock_small', 'rock_medium', 'rock_large'];
// Event handlers
function handleMove(x, y, obj) {
if (dragNode) {
// Convert to game coordinates and constrain to screen bounds
var newX = x;
var playerWidth = 40; // Half width for boundary checking
if (newX < playerWidth) {
newX = playerWidth;
} else if (newX > 2048 - playerWidth) {
newX = 2048 - playerWidth;
}
dragNode.x = newX;
}
}
game.move = handleMove;
game.down = function (x, y, obj) {
dragNode = player;
handleMove(x, y, obj);
};
game.up = function (x, y, obj) {
dragNode = null;
};
// Spawn rock function
function spawnRock() {
var rockType = rockTypes[Math.floor(Math.random() * rockTypes.length)];
var newRock = new Rock(rockType);
// Random horizontal position
newRock.x = Math.random() * (2048 - 200) + 100;
newRock.y = -100;
// Apply game speed multiplier
newRock.fallSpeed *= gameSpeed;
// Initialize tracking variables
newRock.lastY = newRock.y;
newRock.lastIntersecting = false;
rocks.push(newRock);
game.addChild(newRock);
}
// Main game update loop
game.update = function () {
gameTime++;
// Update score and time display
var seconds = Math.floor(gameTime / 60);
LK.setScore(seconds);
scoreTxt.setText(LK.getScore());
timeTxt.setText('Time: ' + seconds + 's');
// Increase difficulty over time
speedIncreaseTimer++;
if (speedIncreaseTimer >= 600) {
// Every 10 seconds
speedIncreaseTimer = 0;
gameSpeed += 0.1;
if (rockSpawnDelay > 20) {
rockSpawnDelay -= 8; // Reduce spawn delay more aggressively
}
}
// Spawn rocks
rockSpawnTimer++;
if (rockSpawnTimer >= rockSpawnDelay) {
rockSpawnTimer = 0;
// Spawn multiple rocks based on game progression
var rocksToSpawn = 1;
if (seconds > 30) rocksToSpawn = 2;
if (seconds > 60) rocksToSpawn = 3;
if (seconds > 120) rocksToSpawn = 4;
for (var spawnCount = 0; spawnCount < rocksToSpawn; spawnCount++) {
spawnRock();
}
}
// Update and check rocks
for (var i = rocks.length - 1; i >= 0; i--) {
var rock = rocks[i];
// Track off-screen removal
if (rock.lastY <= 2732 + 100 && rock.y > 2732 + 100) {
rock.destroy();
rocks.splice(i, 1);
continue;
}
// Check collision with player
var currentIntersecting = rock.intersects(player);
if (!rock.lastIntersecting && currentIntersecting) {
// Collision detected - game over
LK.getSound('hit').play();
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
return;
}
// Update tracking variables
rock.lastY = rock.y;
rock.lastIntersecting = currentIntersecting;
}
}; ===================================================================
--- original.js
+++ change.js
@@ -34,9 +34,28 @@
if (Math.random() < 0.2) {
self.fallSpeed *= 2.5; // Make some rocks fall much faster
}
self.update = function () {
- self.y += self.fallSpeed;
+ // Check collision with other rocks before moving
+ var proposedY = self.y + self.fallSpeed;
+ var canMove = true;
+ // Check against all other rocks
+ for (var i = 0; i < rocks.length; i++) {
+ var otherRock = rocks[i];
+ if (otherRock === self) continue; // Skip self
+ // Check if we would collide with another rock
+ var tempY = self.y;
+ self.y = proposedY;
+ if (self.intersects(otherRock)) {
+ canMove = false;
+ }
+ self.y = tempY; // Restore original position
+ if (!canMove) break;
+ }
+ // Only move if no collision would occur
+ if (canMove) {
+ self.y = proposedY;
+ }
};
return self;
});
@@ -132,17 +151,24 @@
if (speedIncreaseTimer >= 600) {
// Every 10 seconds
speedIncreaseTimer = 0;
gameSpeed += 0.1;
- if (rockSpawnDelay > 30) {
- rockSpawnDelay -= 5;
+ if (rockSpawnDelay > 20) {
+ rockSpawnDelay -= 8; // Reduce spawn delay more aggressively
}
}
// Spawn rocks
rockSpawnTimer++;
if (rockSpawnTimer >= rockSpawnDelay) {
rockSpawnTimer = 0;
- spawnRock();
+ // Spawn multiple rocks based on game progression
+ var rocksToSpawn = 1;
+ if (seconds > 30) rocksToSpawn = 2;
+ if (seconds > 60) rocksToSpawn = 3;
+ if (seconds > 120) rocksToSpawn = 4;
+ for (var spawnCount = 0; spawnCount < rocksToSpawn; spawnCount++) {
+ spawnRock();
+ }
}
// Update and check rocks
for (var i = rocks.length - 1; i >= 0; i--) {
var rock = rocks[i];