User prompt
giriş ekranı oluştur
User prompt
mıknatıs özelliğinin süresini uzat
User prompt
hataları düzelt ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
mıknartıs özelliği 3 saniye boyunca çürük elma hariç bütün elmalrı çeksi ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
özelliklerin gelme olasığını biraz arttır
User prompt
Please fix the bug: 'TypeError: tween.to is not a function' in or related to this line: 'tween.to(comboTxt, {' Line Number: 253 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
oyuna yeni özlelikler ekle
User prompt
oyuna bir son ekle
User prompt
oynayan kişilerin sıralaması olsun ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
altın elmada olsun nadir gelsin ama yakalanınca +3 puan versin
User prompt
arka planda bulutlar olsun sağa ve sola hareket eden ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
elmalar biraz daha hızı gelsin
Code edit (1 edits merged)
Please save this source code
User prompt
Apple Catch
Initial prompt
elma yeme oyunu yap
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Apple = Container.expand(function (isRotten, isGolden) {
var self = Container.call(this);
self.isRotten = isRotten || false;
self.isGolden = isGolden || false;
self.speed = 6;
self.lastY = 0;
var assetName = self.isGolden ? 'goldenApple' : self.isRotten ? 'rottenApple' : 'redApple';
var appleGraphics = self.attachAsset(assetName, {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
self.y += self.speed;
};
return self;
});
var Basket = Container.expand(function () {
var self = Container.call(this);
var basketGraphics = self.attachAsset('basket', {
anchorX: 0.5,
anchorY: 0.5
});
return self;
});
var Cloud = Container.expand(function () {
var self = Container.call(this);
var cloudGraphics = self.attachAsset('cloud', {
anchorX: 0.5,
anchorY: 0.5
});
// Random properties for variety
self.speed = Math.random() * 1 + 0.5; // Speed between 0.5 and 1.5
self.direction = Math.random() < 0.5 ? 1 : -1; // Random left or right direction
cloudGraphics.alpha = 0.6; // Semi-transparent
cloudGraphics.scaleX = Math.random() * 0.8 + 0.6; // Scale between 0.6 and 1.4
cloudGraphics.scaleY = Math.random() * 0.8 + 0.6;
self.update = function () {
self.x += self.speed * self.direction;
// Wrap around screen
if (self.direction > 0 && self.x > 2048 + 100) {
self.x = -100;
} else if (self.direction < 0 && self.x < -100) {
self.x = 2048 + 100;
}
};
return self;
});
var Particle = Container.expand(function (x, y, color) {
var self = Container.call(this);
self.x = x;
self.y = y;
self.velocityX = (Math.random() - 0.5) * 10;
self.velocityY = Math.random() * -8 - 2;
self.life = 60; // 1 second at 60fps
self.maxLife = 60;
var particle = self.attachAsset('redApple', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.2,
scaleY: 0.2,
tint: color
});
self.update = function () {
self.x += self.velocityX;
self.y += self.velocityY;
self.velocityY += 0.3; // Gravity
self.life--;
// Fade out
particle.alpha = self.life / self.maxLife;
if (self.life <= 0) {
self.destroy();
}
};
return self;
});
var PowerUp = Container.expand(function (type) {
var self = Container.call(this);
self.type = type; // 'speed' or 'magnet'
self.speed = 4;
self.lastY = 0;
var assetName = self.type === 'speed' ? 'speedPowerup' : 'magnetPowerup';
var powerupGraphics = self.attachAsset(assetName, {
anchorX: 0.5,
anchorY: 0.5
});
// Add glowing effect
powerupGraphics.alpha = 0.9;
self.update = function () {
self.y += self.speed;
// Add floating animation
powerupGraphics.rotation += 0.05;
powerupGraphics.scaleX = 1 + Math.sin(LK.ticks * 0.1) * 0.1;
powerupGraphics.scaleY = 1 + Math.sin(LK.ticks * 0.1) * 0.1;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Game state management
var gameState = 'start'; // 'start', 'playing', 'gameOver'
var startScreen = new Container();
var gameContainer = new Container();
// Add containers to game
game.addChild(startScreen);
game.addChild(gameContainer);
// Create start screen elements
var titleTxt = new Text2('APPLE CATCHER', {
size: 150,
fill: 0x000000
});
titleTxt.anchor.set(0.5, 0.5);
titleTxt.x = 2048 / 2;
titleTxt.y = 2732 / 2 - 300;
startScreen.addChild(titleTxt);
var instructionTxt = new Text2('Catch red and golden apples\nAvoid rotten brown apples', {
size: 80,
fill: 0x333333
});
instructionTxt.anchor.set(0.5, 0.5);
instructionTxt.x = 2048 / 2;
instructionTxt.y = 2732 / 2 - 100;
startScreen.addChild(instructionTxt);
var startButton = new Text2('TAP TO START', {
size: 100,
fill: 0x00AA00
});
startButton.anchor.set(0.5, 0.5);
startButton.x = 2048 / 2;
startButton.y = 2732 / 2 + 200;
startScreen.addChild(startButton);
// Create game elements in game container
var basket = gameContainer.addChild(new Basket());
basket.x = 2048 / 2;
basket.y = 2732 - 150;
// Game variables - will be initialized when game starts
var apples = [];
var clouds = [];
var powerups = [];
var particles = [];
var dropTimer = 0;
var dropInterval = 90;
var speedIncreaseTimer = 0;
var currentSpeed = 6;
var cloudTimer = 0;
var gameTimer = 0;
var gameTimeLimit = 3600; // 60 seconds at 60fps
var timeWarningShown = false;
var powerupTimer = 0;
// Power-up system
var speedBoostActive = false;
var speedBoostTimer = 0;
var magnetActive = false;
var magnetTimer = 0;
// Combo system
var comboCount = 0;
var comboTimer = 0;
var lastCatchTime = 0;
// Function to initialize game
function initializeGame() {
// Reset all game variables
apples = [];
clouds = [];
powerups = [];
particles = [];
dropTimer = 0;
dropInterval = 90;
speedIncreaseTimer = 0;
currentSpeed = 6;
cloudTimer = 0;
gameTimer = 0;
timeWarningShown = false;
powerupTimer = 0;
speedBoostActive = false;
speedBoostTimer = 0;
magnetActive = false;
magnetTimer = 0;
comboCount = 0;
comboTimer = 0;
lastCatchTime = 0;
// Clear existing game objects
for (var i = gameContainer.children.length - 1; i >= 0; i--) {
var child = gameContainer.children[i];
if (child !== basket) {
child.destroy();
}
}
// Create initial clouds
for (var c = 0; c < 5; c++) {
var cloud = new Cloud();
cloud.x = Math.random() * 2048;
cloud.y = Math.random() * 800 + 200; // Between y 200-1000
clouds.push(cloud);
gameContainer.addChild(cloud);
}
// Reset score
LK.setScore(0);
scoreTxt.setText('0');
// Reset basket position
basket.x = 2048 / 2;
basket.y = 2732 - 150;
}
var scoreTxt = new Text2('0', {
size: 120,
fill: 0x000000
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
scoreTxt.y = 50;
// Initialize leaderboard
var leaderboard = storage.leaderboard || [];
var highScore = storage.highScore || 0;
// Display high score
var highScoreTxt = new Text2('High Score: ' + highScore, {
size: 60,
fill: 0x000000
});
highScoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(highScoreTxt);
highScoreTxt.y = 180;
// Add time display
var timeTxt = new Text2('Time: 60', {
size: 60,
fill: 0x000000
});
timeTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(timeTxt);
timeTxt.x = -20;
timeTxt.y = 50;
// Add combo display
var comboTxt = new Text2('', {
size: 80,
fill: 0xFF6600
});
comboTxt.anchor.set(0.5, 0.5);
LK.gui.center.addChild(comboTxt);
comboTxt.y = -200;
// Initialize game state
gameContainer.visible = false;
startScreen.visible = true;
var dragNode = null;
function handleMove(x, y, obj) {
if (dragNode) {
dragNode.x = Math.max(80, Math.min(2048 - 80, x));
}
}
game.move = handleMove;
game.down = function (x, y, obj) {
if (gameState === 'start') {
// Start the game
gameState = 'playing';
startScreen.visible = false;
gameContainer.visible = true;
initializeGame();
} else if (gameState === 'playing') {
dragNode = basket;
handleMove(x, y, obj);
}
};
game.up = function (x, y, obj) {
dragNode = null;
};
// Leaderboard management functions
function updateLeaderboard(score) {
// Update high score if needed
if (score > highScore) {
highScore = score;
storage.highScore = highScore;
highScoreTxt.setText('High Score: ' + highScore);
}
// Add score to leaderboard
leaderboard.push(score);
// Sort leaderboard (highest first) and keep only top 10
leaderboard.sort(function (a, b) {
return b - a;
});
if (leaderboard.length > 10) {
leaderboard = leaderboard.slice(0, 10);
}
// Save to storage
storage.leaderboard = leaderboard;
}
function resetToStartScreen() {
gameState = 'start';
startScreen.visible = true;
gameContainer.visible = false;
comboTxt.setText('');
}
function displayLeaderboard() {
console.log('=== LEADERBOARD ===');
for (var i = 0; i < leaderboard.length; i++) {
console.log(i + 1 + '. ' + leaderboard[i] + ' points');
}
}
function createParticles(x, y, color, count) {
for (var p = 0; p < count; p++) {
var particle = new Particle(x, y, color);
particles.push(particle);
game.addChild(particle);
}
}
function updateCombo() {
comboCount++;
comboTimer = 180; // 3 seconds to maintain combo
if (comboCount >= 3) {
comboTxt.setText('COMBO x' + comboCount + '!');
comboTxt.alpha = 1;
// Scale animation for combo text
tween(comboTxt, {
scaleX: 1.5,
scaleY: 1.5
}, {
duration: 200,
onFinish: function onFinish() {
// Scale back to normal after scaling up
tween(comboTxt, {
scaleX: 1,
scaleY: 1
}, {
duration: 200
});
}
});
}
}
game.update = function () {
// Handle start screen animation
if (gameState === 'start') {
// Animate start button
startButton.alpha = 0.5 + Math.sin(LK.ticks * 0.1) * 0.5;
return;
}
// Only run game logic when in playing state
if (gameState !== 'playing') {
return;
}
// Update game timer
gameTimer++;
var remainingTime = Math.ceil((gameTimeLimit - gameTimer) / 60);
timeTxt.setText('Time: ' + Math.max(0, remainingTime));
// Show warning when 10 seconds left
if (!timeWarningShown && remainingTime <= 10 && remainingTime > 0) {
timeWarningShown = true;
LK.effects.flashScreen(0xFFFF00, 800); // Yellow warning flash
}
// End game when time runs out
if (gameTimer >= gameTimeLimit) {
updateLeaderboard(LK.getScore());
if (LK.getScore() >= 30) {
LK.showYouWin(); // Good performance ending
} else {
LK.showGameOver(); // Time's up ending
}
return; // Stop further execution
}
// Update drop timer and spawn apples
dropTimer++;
if (dropTimer >= dropInterval) {
dropTimer = 0;
var randomValue = Math.random();
var isGolden = randomValue < 0.15; // 15% chance for golden apple
var isRotten = !isGolden && randomValue < 0.35; // 30% chance for rotten (if not golden)
var newApple = new Apple(isRotten, isGolden);
newApple.x = Math.random() * (2048 - 120) + 60;
newApple.y = -30;
newApple.speed = currentSpeed;
newApple.lastY = newApple.y;
newApple.lastIntersecting = false;
apples.push(newApple);
game.addChild(newApple);
}
// Spawn new clouds occasionally
cloudTimer++;
if (cloudTimer >= 300) {
// Every 5 seconds
cloudTimer = 0;
if (clouds.length < 8) {
// Limit number of clouds
var newCloud = new Cloud();
newCloud.x = newCloud.direction > 0 ? -100 : 2048 + 100;
newCloud.y = Math.random() * 800 + 200;
clouds.push(newCloud);
game.addChild(newCloud);
}
}
// Spawn power-ups occasionally
powerupTimer++;
if (powerupTimer >= 480) {
// Every 8 seconds
powerupTimer = 0;
var powerupType = Math.random() < 0.5 ? 'speed' : 'magnet';
var newPowerup = new PowerUp(powerupType);
newPowerup.x = Math.random() * (2048 - 120) + 60;
newPowerup.y = -30;
newPowerup.lastY = newPowerup.y;
newPowerup.lastIntersecting = false;
powerups.push(newPowerup);
game.addChild(newPowerup);
}
// Update power-up timers
if (speedBoostActive) {
speedBoostTimer--;
if (speedBoostTimer <= 0) {
speedBoostActive = false;
}
}
if (magnetActive) {
magnetTimer--;
if (magnetTimer <= 0) {
magnetActive = false;
}
}
// Update combo timer
if (comboTimer > 0) {
comboTimer--;
if (comboTimer <= 0) {
comboCount = 0;
comboTxt.setText('');
}
}
// Update particles
for (var p = particles.length - 1; p >= 0; p--) {
var particle = particles[p];
if (particle.life <= 0) {
particle.destroy();
particles.splice(p, 1);
}
}
// Increase difficulty over time
speedIncreaseTimer++;
if (speedIncreaseTimer >= 600) {
// Every 10 seconds at 60fps
speedIncreaseTimer = 0;
currentSpeed += 0.5;
dropInterval = Math.max(30, dropInterval - 5);
}
// Update power-ups
for (var pu = powerups.length - 1; pu >= 0; pu--) {
var powerup = powerups[pu];
// Check if powerup went off screen
if (powerup.lastY <= 2732 + 50 && powerup.y > 2732 + 50) {
powerup.destroy();
powerups.splice(pu, 1);
continue;
}
// Check collision with basket
var powerupIntersecting = powerup.intersects(basket);
if (!powerup.lastIntersecting && powerupIntersecting) {
if (powerup.type === 'speed') {
speedBoostActive = true;
speedBoostTimer = 600; // 10 seconds
LK.effects.flashScreen(0x00FFFF, 400);
} else if (powerup.type === 'magnet') {
magnetActive = true;
magnetTimer = 360; // 6 seconds
LK.effects.flashScreen(0xFF00FF, 400);
}
LK.getSound('powerup').play();
createParticles(powerup.x, powerup.y, 0xFFFFFF, 8);
powerup.destroy();
powerups.splice(pu, 1);
continue;
}
powerup.lastY = powerup.y;
powerup.lastIntersecting = powerupIntersecting;
}
// Update apples
for (var i = apples.length - 1; i >= 0; i--) {
var apple = apples[i];
// Magnet effect - attract all apples except rotten ones to basket
if (magnetActive && !apple.isRotten) {
var dx = basket.x - apple.x;
var dy = basket.y - apple.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance < 500) {
// Increased magnet range
var magnetStrength = 0.8;
var normalizedDx = dx / distance;
var normalizedDy = dy / distance;
apple.x += normalizedDx * magnetStrength * 8;
apple.y += normalizedDy * magnetStrength * 8;
}
}
// Speed boost effect
if (speedBoostActive) {
basket.x = Math.max(80, Math.min(2048 - 80, basket.x + (dragNode ? 0 : 0))); // Enhanced movement
}
// Check if apple went off screen
if (apple.lastY <= 2732 + 50 && apple.y > 2732 + 50) {
// Reset combo if apple missed
if (!apple.isRotten) {
comboCount = 0;
comboTxt.setText('');
}
apple.destroy();
apples.splice(i, 1);
continue;
}
// Check collision with basket
var currentIntersecting = apple.intersects(basket);
if (!apple.lastIntersecting && currentIntersecting) {
if (apple.isRotten) {
// Caught rotten apple - breaks combo
comboCount = 0;
comboTxt.setText('');
LK.setScore(LK.getScore() - 1);
LK.effects.flashScreen(0xFF0000, 500);
LK.getSound('catchBad').play();
createParticles(apple.x, apple.y, 0xFF0000, 6);
// Check lose condition
if (LK.getScore() <= -10) {
updateLeaderboard(LK.getScore());
LK.showGameOver();
}
} else if (apple.isGolden) {
// Caught golden apple
updateCombo();
var points = 3;
if (comboCount >= 5) points *= 2; // Double points for high combo
LK.setScore(LK.getScore() + points);
LK.effects.flashScreen(0xFFD700, 400);
LK.getSound('catchGood').play();
createParticles(apple.x, apple.y, 0xFFD700, 12);
// Check win condition
if (LK.getScore() >= 50) {
updateLeaderboard(LK.getScore());
LK.showYouWin();
}
} else {
// Caught regular red apple
updateCombo();
var points = 1;
if (comboCount >= 5) points *= 2; // Double points for high combo
LK.setScore(LK.getScore() + points);
LK.effects.flashScreen(0x00FF00, 300);
LK.getSound('catchGood').play();
createParticles(apple.x, apple.y, 0x00FF00, 8);
// Check win condition
if (LK.getScore() >= 50) {
updateLeaderboard(LK.getScore());
LK.showYouWin();
}
}
scoreTxt.setText(LK.getScore());
displayLeaderboard();
apple.destroy();
apples.splice(i, 1);
continue;
}
// Update tracking variables
apple.lastY = apple.y;
apple.lastIntersecting = currentIntersecting;
}
}; ===================================================================
--- original.js
+++ change.js
@@ -113,11 +113,45 @@
/****
* Game Code
****/
-var basket = game.addChild(new Basket());
+// Game state management
+var gameState = 'start'; // 'start', 'playing', 'gameOver'
+var startScreen = new Container();
+var gameContainer = new Container();
+// Add containers to game
+game.addChild(startScreen);
+game.addChild(gameContainer);
+// Create start screen elements
+var titleTxt = new Text2('APPLE CATCHER', {
+ size: 150,
+ fill: 0x000000
+});
+titleTxt.anchor.set(0.5, 0.5);
+titleTxt.x = 2048 / 2;
+titleTxt.y = 2732 / 2 - 300;
+startScreen.addChild(titleTxt);
+var instructionTxt = new Text2('Catch red and golden apples\nAvoid rotten brown apples', {
+ size: 80,
+ fill: 0x333333
+});
+instructionTxt.anchor.set(0.5, 0.5);
+instructionTxt.x = 2048 / 2;
+instructionTxt.y = 2732 / 2 - 100;
+startScreen.addChild(instructionTxt);
+var startButton = new Text2('TAP TO START', {
+ size: 100,
+ fill: 0x00AA00
+});
+startButton.anchor.set(0.5, 0.5);
+startButton.x = 2048 / 2;
+startButton.y = 2732 / 2 + 200;
+startScreen.addChild(startButton);
+// Create game elements in game container
+var basket = gameContainer.addChild(new Basket());
basket.x = 2048 / 2;
basket.y = 2732 - 150;
+// Game variables - will be initialized when game starts
var apples = [];
var clouds = [];
var powerups = [];
var particles = [];
@@ -138,15 +172,51 @@
// Combo system
var comboCount = 0;
var comboTimer = 0;
var lastCatchTime = 0;
-// Create initial clouds
-for (var c = 0; c < 5; c++) {
- var cloud = new Cloud();
- cloud.x = Math.random() * 2048;
- cloud.y = Math.random() * 800 + 200; // Between y 200-1000
- clouds.push(cloud);
- game.addChild(cloud);
+// Function to initialize game
+function initializeGame() {
+ // Reset all game variables
+ apples = [];
+ clouds = [];
+ powerups = [];
+ particles = [];
+ dropTimer = 0;
+ dropInterval = 90;
+ speedIncreaseTimer = 0;
+ currentSpeed = 6;
+ cloudTimer = 0;
+ gameTimer = 0;
+ timeWarningShown = false;
+ powerupTimer = 0;
+ speedBoostActive = false;
+ speedBoostTimer = 0;
+ magnetActive = false;
+ magnetTimer = 0;
+ comboCount = 0;
+ comboTimer = 0;
+ lastCatchTime = 0;
+ // Clear existing game objects
+ for (var i = gameContainer.children.length - 1; i >= 0; i--) {
+ var child = gameContainer.children[i];
+ if (child !== basket) {
+ child.destroy();
+ }
+ }
+ // Create initial clouds
+ for (var c = 0; c < 5; c++) {
+ var cloud = new Cloud();
+ cloud.x = Math.random() * 2048;
+ cloud.y = Math.random() * 800 + 200; // Between y 200-1000
+ clouds.push(cloud);
+ gameContainer.addChild(cloud);
+ }
+ // Reset score
+ LK.setScore(0);
+ scoreTxt.setText('0');
+ // Reset basket position
+ basket.x = 2048 / 2;
+ basket.y = 2732 - 150;
}
var scoreTxt = new Text2('0', {
size: 120,
fill: 0x000000
@@ -181,18 +251,29 @@
});
comboTxt.anchor.set(0.5, 0.5);
LK.gui.center.addChild(comboTxt);
comboTxt.y = -200;
+// Initialize game state
+gameContainer.visible = false;
+startScreen.visible = true;
var dragNode = null;
function handleMove(x, y, obj) {
if (dragNode) {
dragNode.x = Math.max(80, Math.min(2048 - 80, x));
}
}
game.move = handleMove;
game.down = function (x, y, obj) {
- dragNode = basket;
- handleMove(x, y, obj);
+ if (gameState === 'start') {
+ // Start the game
+ gameState = 'playing';
+ startScreen.visible = false;
+ gameContainer.visible = true;
+ initializeGame();
+ } else if (gameState === 'playing') {
+ dragNode = basket;
+ handleMove(x, y, obj);
+ }
};
game.up = function (x, y, obj) {
dragNode = null;
};
@@ -215,8 +296,14 @@
}
// Save to storage
storage.leaderboard = leaderboard;
}
+function resetToStartScreen() {
+ gameState = 'start';
+ startScreen.visible = true;
+ gameContainer.visible = false;
+ comboTxt.setText('');
+}
function displayLeaderboard() {
console.log('=== LEADERBOARD ===');
for (var i = 0; i < leaderboard.length; i++) {
console.log(i + 1 + '. ' + leaderboard[i] + ' points');
@@ -253,8 +340,18 @@
});
}
}
game.update = function () {
+ // Handle start screen animation
+ if (gameState === 'start') {
+ // Animate start button
+ startButton.alpha = 0.5 + Math.sin(LK.ticks * 0.1) * 0.5;
+ return;
+ }
+ // Only run game logic when in playing state
+ if (gameState !== 'playing') {
+ return;
+ }
// Update game timer
gameTimer++;
var remainingTime = Math.ceil((gameTimeLimit - gameTimer) / 60);
timeTxt.setText('Time: ' + Math.max(0, remainingTime));
kahverengi bir elma sepeti . No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
beyaz bir bulut. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
elma. In-Game asset. 2d. High contrast. No shadows
çürük elma. In-Game asset. 2d. High contrast. No shadows
altın bir elma. In-Game asset. 2d. High contrast. No shadows