User prompt
Arka plan görseli olsun
User prompt
Arka plan olarak assetlerle uzay teması oluştur
User prompt
Oyun çok zor biraz kolaylaştır ama çok da kolay olmasın
User prompt
Yukarıdan düşen toplar gibi 2. Asset oluştur
User prompt
background müziği player ball adlı nesneye deydiği anda çalması ve game over olana kadar durmaması lazım
User prompt
Şarkı ilk top yakalandıktan sonra başlasın
User prompt
background adlı müzik çalmıyor
User prompt
Toplar çok daha hızlı düşmeli şarkıyla uyumlu olması gerekiyor
Code edit (1 edits merged)
Please save this source code
User prompt
Ball Catcher
Initial prompt
Yukarıdan toplar düşecek aşağıda bir kup topları yakalayabilirse oyun devam edecek. Arkada şarkı çalacak. Toplar yakalanamazsa şarkı biter oyun biter.
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Ball = Container.expand(function () {
var self = Container.call(this);
var ballGraphics = self.attachAsset('ball', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 8 + Math.random() * 4; // Random speed between 8-12 for easier gameplay
self.lastY = 0;
self.lastCaught = false;
self.update = function () {
self.y += self.speed;
};
return self;
});
var Crystal = Container.expand(function () {
var self = Container.call(this);
var crystalGraphics = self.attachAsset('crystal', {
anchorX: 0.5,
anchorY: 0.5
});
crystalGraphics.rotation = Math.PI / 4; // Rotate 45 degrees for visual distinction
self.speed = 7 + Math.random() * 3; // Slower speed range for easier gameplay
self.lastY = 0;
self.lastCaught = false;
self.update = function () {
self.y += self.speed;
crystalGraphics.rotation += 0.1; // Rotate while falling
};
return self;
});
var Nebula = Container.expand(function () {
var self = Container.call(this);
var nebulaGraphics = self.attachAsset('nebula', {
anchorX: 0.5,
anchorY: 0.5
});
nebulaGraphics.alpha = 0.2;
self.pulseTimer = 0;
self.update = function () {
self.pulseTimer += 0.02;
nebulaGraphics.alpha = 0.1 + Math.sin(self.pulseTimer) * 0.1;
};
return self;
});
var Planet = Container.expand(function () {
var self = Container.call(this);
var planetType = Math.random() < 0.5 ? 'planet1' : 'planet2';
var planetGraphics = self.attachAsset(planetType, {
anchorX: 0.5,
anchorY: 0.5
});
planetGraphics.alpha = 0.6;
self.rotationSpeed = 0.005 + Math.random() * 0.01;
self.update = function () {
planetGraphics.rotation += self.rotationSpeed;
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
return self;
});
var Star = Container.expand(function () {
var self = Container.call(this);
var starType = Math.random() < 0.8 ? 'star' : 'bigStar';
var starGraphics = self.attachAsset(starType, {
anchorX: 0.5,
anchorY: 0.5
});
self.twinkleTimer = Math.random() * 120;
self.update = function () {
self.twinkleTimer++;
if (self.twinkleTimer >= 120) {
self.twinkleTimer = 0;
starGraphics.alpha = 0.3 + Math.random() * 0.7;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2c3e50
});
/****
* Game Code
****/
// Game variables
var player;
var balls = [];
var crystals = [];
var dragNode = null;
var ballSpawnTimer = 0;
var ballSpawnInterval = 75; // Spawn every 1.25 seconds at 60fps for easier pace
// Space background elements
var stars = [];
var planets = [];
var nebulae = [];
// Create space background
// Add nebulae first (background layer)
for (var n = 0; n < 3; n++) {
var nebula = game.addChild(new Nebula());
nebula.x = Math.random() * 2048;
nebula.y = Math.random() * 2732;
nebulae.push(nebula);
}
// Add planets
for (var p = 0; p < 2; p++) {
var planet = game.addChild(new Planet());
planet.x = Math.random() * 2048;
planet.y = Math.random() * 2732;
planets.push(planet);
}
// Add stars (foreground layer)
for (var s = 0; s < 50; s++) {
var star = game.addChild(new Star());
star.x = Math.random() * 2048;
star.y = Math.random() * 2732;
stars.push(star);
}
// Score display
var scoreTxt = new Text2('0', {
size: 120,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Create player
player = game.addChild(new Player());
player.x = 2048 / 2;
player.y = 2732 - 150; // Near bottom of screen
// Music will start after first ball is caught
var musicStarted = false;
// Move handler
function handleMove(x, y, obj) {
if (dragNode) {
dragNode.x = x;
// Keep player within screen bounds
if (dragNode.x < 80) dragNode.x = 80;
if (dragNode.x > 2048 - 80) dragNode.x = 2048 - 80;
}
}
// Event handlers
game.move = handleMove;
game.down = function (x, y, obj) {
dragNode = player;
handleMove(x, y, obj);
};
game.up = function (x, y, obj) {
dragNode = null;
};
// Main game update loop
game.update = function () {
// Spawn balls and crystals
ballSpawnTimer++;
if (ballSpawnTimer >= ballSpawnInterval) {
ballSpawnTimer = 0;
// Randomly spawn either a ball or crystal
if (Math.random() < 0.7) {
// 70% chance for ball
var newBall = new Ball();
newBall.x = 100 + Math.random() * (2048 - 200); // Random x position
newBall.y = -50; // Start above screen
newBall.lastY = newBall.y;
balls.push(newBall);
game.addChild(newBall);
} else {
// 30% chance for crystal
var newCrystal = new Crystal();
newCrystal.x = 100 + Math.random() * (2048 - 200); // Random x position
newCrystal.y = -50; // Start above screen
newCrystal.lastY = newCrystal.y;
crystals.push(newCrystal);
game.addChild(newCrystal);
}
}
// Update balls and check collisions
for (var i = balls.length - 1; i >= 0; i--) {
var ball = balls[i];
// Check if ball touches player
var currentCaught = ball.intersects(player);
if (!ball.lastCaught && currentCaught) {
// Start music when ball first touches player
if (!musicStarted) {
LK.playMusic('background');
musicStarted = true;
}
// Ball just got caught
LK.setScore(LK.getScore() + 1);
scoreTxt.setText(LK.getScore());
LK.getSound('catch').play();
ball.destroy();
balls.splice(i, 1);
continue;
}
// Check if ball hit the ground (missed)
if (ball.lastY < 2732 && ball.y >= 2732) {
// Ball just hit the ground - game over
LK.stopMusic();
LK.showGameOver();
return;
}
// Remove balls that are way off screen
if (ball.y > 2732 + 100) {
ball.destroy();
balls.splice(i, 1);
continue;
}
// Update last states
ball.lastY = ball.y;
ball.lastCaught = currentCaught;
}
// Update crystals and check collisions
for (var j = crystals.length - 1; j >= 0; j--) {
var crystal = crystals[j];
// Check if crystal touches player
var currentCrystalCaught = crystal.intersects(player);
if (!crystal.lastCaught && currentCrystalCaught) {
// Start music when crystal first touches player
if (!musicStarted) {
LK.playMusic('background');
musicStarted = true;
}
// Crystal just got caught - worth more points
LK.setScore(LK.getScore() + 2);
scoreTxt.setText(LK.getScore());
LK.getSound('catch').play();
crystal.destroy();
crystals.splice(j, 1);
continue;
}
// Check if crystal hit the ground (missed)
if (crystal.lastY < 2732 && crystal.y >= 2732) {
// Crystal just hit the ground - game over
LK.stopMusic();
LK.showGameOver();
return;
}
// Remove crystals that are way off screen
if (crystal.y > 2732 + 100) {
crystal.destroy();
crystals.splice(j, 1);
continue;
}
// Update last states
crystal.lastY = crystal.y;
crystal.lastCaught = currentCrystalCaught;
}
}; ===================================================================
--- original.js
+++ change.js
@@ -35,16 +35,61 @@
crystalGraphics.rotation += 0.1; // Rotate while falling
};
return self;
});
+var Nebula = Container.expand(function () {
+ var self = Container.call(this);
+ var nebulaGraphics = self.attachAsset('nebula', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ nebulaGraphics.alpha = 0.2;
+ self.pulseTimer = 0;
+ self.update = function () {
+ self.pulseTimer += 0.02;
+ nebulaGraphics.alpha = 0.1 + Math.sin(self.pulseTimer) * 0.1;
+ };
+ return self;
+});
+var Planet = Container.expand(function () {
+ var self = Container.call(this);
+ var planetType = Math.random() < 0.5 ? 'planet1' : 'planet2';
+ var planetGraphics = self.attachAsset(planetType, {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ planetGraphics.alpha = 0.6;
+ self.rotationSpeed = 0.005 + Math.random() * 0.01;
+ self.update = function () {
+ planetGraphics.rotation += self.rotationSpeed;
+ };
+ return self;
+});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
return self;
});
+var Star = Container.expand(function () {
+ var self = Container.call(this);
+ var starType = Math.random() < 0.8 ? 'star' : 'bigStar';
+ var starGraphics = self.attachAsset(starType, {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.twinkleTimer = Math.random() * 120;
+ self.update = function () {
+ self.twinkleTimer++;
+ if (self.twinkleTimer >= 120) {
+ self.twinkleTimer = 0;
+ starGraphics.alpha = 0.3 + Math.random() * 0.7;
+ }
+ };
+ return self;
+});
/****
* Initialize Game
****/
@@ -61,8 +106,34 @@
var crystals = [];
var dragNode = null;
var ballSpawnTimer = 0;
var ballSpawnInterval = 75; // Spawn every 1.25 seconds at 60fps for easier pace
+// Space background elements
+var stars = [];
+var planets = [];
+var nebulae = [];
+// Create space background
+// Add nebulae first (background layer)
+for (var n = 0; n < 3; n++) {
+ var nebula = game.addChild(new Nebula());
+ nebula.x = Math.random() * 2048;
+ nebula.y = Math.random() * 2732;
+ nebulae.push(nebula);
+}
+// Add planets
+for (var p = 0; p < 2; p++) {
+ var planet = game.addChild(new Planet());
+ planet.x = Math.random() * 2048;
+ planet.y = Math.random() * 2732;
+ planets.push(planet);
+}
+// Add stars (foreground layer)
+for (var s = 0; s < 50; s++) {
+ var star = game.addChild(new Star());
+ star.x = Math.random() * 2048;
+ star.y = Math.random() * 2732;
+ stars.push(star);
+}
// Score display
var scoreTxt = new Text2('0', {
size: 120,
fill: 0xFFFFFF