User prompt
Her toplamaya ses ekle
User prompt
Add missed raindrops counter variable to track raindrops that reach bottom ✅ Add missed raindrops display text to show current missed count ✅ Update missed counter and check game over condition when raindrops go off screen ✅ Remove win condition since game should be endless
User prompt
Oyun sonsuz olacak fakat oyuncu 10dan fazla yağmur damlası yakalayamazsa sonlanacak
Code edit (1 edits merged)
Please save this source code
User prompt
Raindrop Collector
Initial prompt
Drop raindrop from ipler to screen and player can collect those airdrops and score count
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Collector = Container.expand(function () {
var self = Container.call(this);
var collectorGraphics = self.attachAsset('collector', {
anchorX: 0.5,
anchorY: 0.5
});
return self;
});
var Raindrop = Container.expand(function () {
var self = Container.call(this);
var raindropGraphics = self.attachAsset('raindrop', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 8;
self.lastY = undefined;
self.update = function () {
self.y += self.speed;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1E3A8A
});
/****
* Game Code
****/
// Create score display
var scoreTxt = new Text2('0', {
size: 100,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Create missed raindrops display
var missedTxt = new Text2('Missed: 0/10', {
size: 60,
fill: 0xFF4444
});
missedTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(missedTxt);
// Create collector
var collector = game.addChild(new Collector());
collector.x = 2048 / 2;
collector.y = 2732 - 150;
// Track raindrops
var raindrops = [];
// Track missed raindrops
var missedRaindrops = 0;
// Dragging variables
var dragNode = null;
// Spawn timer
var spawnTimer = 0;
var spawnDelay = 45; // Spawn every 45 ticks (about 0.75 seconds at 60fps)
function handleMove(x, y, obj) {
if (dragNode) {
dragNode.x = x;
// Keep collector within screen bounds
if (dragNode.x < 60) dragNode.x = 60;
if (dragNode.x > 2048 - 60) dragNode.x = 2048 - 60;
}
;
;
}
game.move = handleMove;
game.down = function (x, y, obj) {
dragNode = collector;
handleMove(x, y, obj);
};
game.up = function (x, y, obj) {
dragNode = null;
};
game.update = function () {
// Spawn raindrops
spawnTimer++;
if (spawnTimer >= spawnDelay) {
spawnTimer = 0;
var newRaindrop = new Raindrop();
newRaindrop.x = Math.random() * (2048 - 60) + 30;
newRaindrop.y = -25;
newRaindrop.lastY = newRaindrop.y;
newRaindrop.lastCollected = false;
raindrops.push(newRaindrop);
game.addChild(newRaindrop);
}
// Update raindrops
for (var i = raindrops.length - 1; i >= 0; i--) {
var raindrop = raindrops[i];
// Initialize tracking variables
if (raindrop.lastY === undefined) raindrop.lastY = raindrop.y;
if (raindrop.lastCollected === undefined) raindrop.lastCollected = false;
// Check if raindrop went off screen
if (raindrop.lastY < 2732 + 50 && raindrop.y >= 2732 + 50) {
// Increment missed raindrops counter
missedRaindrops++;
missedTxt.setText('Missed: ' + missedRaindrops + '/10');
// Check game over condition
if (missedRaindrops >= 10) {
LK.showGameOver();
}
raindrop.destroy();
raindrops.splice(i, 1);
continue;
}
// Check collision with collector
var currentCollected = raindrop.intersects(collector);
if (!raindrop.lastCollected && currentCollected) {
// Raindrop just got collected
LK.setScore(LK.getScore() + 1);
scoreTxt.setText(LK.getScore());
// Play collect sound
LK.getSound('collect').play();
// Add a small tween effect
tween(collector, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 100,
onFinish: function onFinish() {
tween(collector, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
}
});
raindrop.destroy();
raindrops.splice(i, 1);
continue;
}
// Update last known states
raindrop.lastY = raindrop.y;
raindrop.lastCollected = currentCollected;
}
}; ===================================================================
--- original.js
+++ change.js
@@ -72,8 +72,9 @@
if (dragNode.x < 60) dragNode.x = 60;
if (dragNode.x > 2048 - 60) dragNode.x = 2048 - 60;
}
;
+ ;
}
game.move = handleMove;
game.down = function (x, y, obj) {
dragNode = collector;