User prompt
tekrar dene hala hata veriyorsa değiştir
User prompt
tekrar dene
User prompt
topladığımız puanları kullanabileceğimiz bir format ayarla
User prompt
oyunu geliştir
User prompt
speed boost yerine gölgeleri yavaşlatan gücü ekle
User prompt
özel güçler ekle
User prompt
özel güçler ekle
User prompt
ekrandan topladığımız bir kaç saniye süren özel güçler ekle hız gibi
Code edit (1 edits merged)
Please save this source code
User prompt
Shadow Swap: Işık ve Karanlık
Initial prompt
bana kendine özgü bir oyun yap
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ // LightOrb (Player) class var LightOrb = Container.expand(function () { var self = Container.call(this); var orb = self.attachAsset('lightOrb', { anchorX: 0.5, anchorY: 0.5 }); // For touch feedback self.flash = function () { tween(orb, { alpha: 0.6 }, { duration: 80, onFinish: function onFinish() { tween(orb, { alpha: 1 }, { duration: 120 }); } }); }; // No update needed; position is set by player return self; }); // PowerUp (Special Ability) class var PowerUp = Container.expand(function () { var self = Container.call(this); // Types: 'slow', 'shield', 'score' self.type = 'slow'; // Visuals: color by type var color = 0x00eaff; if (self.type === 'shield') color = 0x7fff00; if (self.type === 'score') color = 0xffd700; var asset = self.attachAsset('lightOrb', { anchorX: 0.5, anchorY: 0.5 }); asset.width = 90; asset.height = 90; asset.tint = color; // For state tracking self.lastIntersecting = false; // No update needed; position is static return self; }); // Shadow (Enemy) class var Shadow = Container.expand(function () { var self = Container.call(this); var shadow = self.attachAsset('shadow', { anchorX: 0.5, anchorY: 0.5 }); // Movement properties self.vx = 0; self.vy = 0; self.speed = 2; // Will be set on spawn // For state tracking self.lastIntersecting = false; // Called every tick self.update = function () { self.x += self.vx * self.speed; self.y += self.vy * self.speed; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x181c24 }); /**** * Game Code ****/ // Game area // Light orb (player) // Shadow (enemy) // Score text will use Text2, no asset needed var GAME_W = 2048; var GAME_H = 2732; // Player (light orb) var lightOrb = new LightOrb(); lightOrb.x = GAME_W / 2; lightOrb.y = GAME_H * 0.75; game.addChild(lightOrb); // Shadows (enemies) var shadows = []; // PowerUps (special abilities) var powerUps = []; // PowerUp state var powerUpActive = false; var powerUpType = null; var powerUpTimer = 0; // Score var score = 0; var scoreTxt = new Text2('0', { size: 120, fill: 0xFFFBE0 }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Persistent currency (points you can spend) var currency = storage.get('currency') || 0; var currencyTxt = new Text2(currency + ' 💎', { size: 80, fill: 0xFFD700 }); currencyTxt.anchor.set(1, 0); currencyTxt.x = GAME_W - 60; currencyTxt.y = 0; LK.gui.top.addChild(currencyTxt); // Helper to update and persist currency function updateCurrency(val) { currency = val; currencyTxt.setText(currency + ' 💎'); storage.set('currency', currency); } // Shop UI: simple buttons to buy powerups with currency var shopBtns = []; function showShop() { // Remove old buttons if any for (var i = 0; i < shopBtns.length; i++) { shopBtns[i].destroy(); } shopBtns = []; // Button data: [label, cost, powerupType] var btnData = [['Kalkan (Shield)', 20, 'shield'], ['Yavaşlat (Slow)', 20, 'slow'], ['Küçül (Shrink)', 20, 'shrink'], ['+10 Puan', 10, 'score']]; for (var i = 0; i < btnData.length; i++) { (function (i) { var btn = new Text2(btnData[i][0] + ' - ' + btnData[i][1] + '💎', { size: 70, fill: 0x222222, background: 0xFFFBE0, padding: 18 }); btn.anchor.set(0.5, 0); btn.x = GAME_W / 2; btn.y = 220 + i * 120; btn.interactive = true; btn.buttonMode = true; btn.down = function (x, y, obj) { if (currency >= btnData[i][1] && !powerUpActive) { updateCurrency(currency - btnData[i][1]); // Activate powerup effect instantly powerUpActive = true; powerUpType = btnData[i][2]; powerUpTimer = 0; LK.effects.flashObject(lightOrb, 0xFFFBE0, 400); // Score boost is instant if (powerUpType === 'score') { updateScore(score + 10); powerUpActive = false; powerUpType = null; } hideShop(); } }; LK.gui.center.addChild(btn); shopBtns.push(btn); })(i); } // Close button var closeBtn = new Text2('Kapat', { size: 60, fill: 0xFFFBE0, background: 0x222222, padding: 14 }); closeBtn.anchor.set(0.5, 0); closeBtn.x = GAME_W / 2; closeBtn.y = 220 + btnData.length * 120; closeBtn.interactive = true; closeBtn.buttonMode = true; closeBtn.down = function (x, y, obj) { hideShop(); }; LK.gui.center.addChild(closeBtn); shopBtns.push(closeBtn); } function hideShop() { for (var i = 0; i < shopBtns.length; i++) { shopBtns[i].destroy(); } shopBtns = []; } // Shop open button var shopOpenBtn = new Text2('Mağaza', { size: 70, fill: 0xFFFBE0, background: 0x222222, padding: 14 }); shopOpenBtn.anchor.set(1, 0); shopOpenBtn.x = GAME_W - 60; shopOpenBtn.y = 100; shopOpenBtn.interactive = true; shopOpenBtn.buttonMode = true; shopOpenBtn.down = function (x, y, obj) { showShop(); }; LK.gui.top.addChild(shopOpenBtn); // Difficulty var shadowSpeed = 2.2; var shadowSpawnInterval = 120; // ticks var minShadowSpawnInterval = 36; var shadowCount = 2; var maxShadowCount = 8; // Dragging var dragging = false; // Helper: clamp position inside game area function clamp(val, min, max) { return Math.max(min, Math.min(max, val)); } // Helper: spawn a shadow at a random edge, moving in a random direction function spawnShadow() { var s = new Shadow(); // Random edge: 0=top, 1=bottom, 2=left, 3=right var edge = Math.floor(Math.random() * 4); var margin = 120; var x, y, angle; if (edge === 0) { // top x = margin + Math.random() * (GAME_W - 2 * margin); y = -90; angle = Math.PI / 4 + Math.random() * (Math.PI / 2); // 45-135 deg } else if (edge === 1) { // bottom x = margin + Math.random() * (GAME_W - 2 * margin); y = GAME_H + 90; angle = -Math.PI / 4 - Math.random() * (Math.PI / 2); // -45 to -135 deg } else if (edge === 2) { // left x = -90; y = margin + Math.random() * (GAME_H - 2 * margin); angle = -Math.PI / 4 + Math.random() * (Math.PI / 2); // -45 to 45 deg } else { // right x = GAME_W + 90; y = margin + Math.random() * (GAME_H - 2 * margin); angle = Math.PI * (1.25 + Math.random() * 0.5); // 225-315 deg } s.x = x; s.y = y; s.speed = shadowSpeed + Math.random() * 0.7; s.vx = Math.cos(angle); s.vy = Math.sin(angle); // Add to game and array game.addChild(s); shadows.push(s); } // Score update function updateScore(val) { score = val; scoreTxt.setText(score); } // Difficulty ramp function increaseDifficulty() { if (shadowSpawnInterval > minShadowSpawnInterval) { shadowSpawnInterval -= 6; } if (shadowCount < maxShadowCount) { shadowCount += 1; } shadowSpeed += 0.18; } // Move handler (drag orb) function handleMove(x, y, obj) { if (dragging) { // Clamp to game area, avoid top left 100x100 var nx = clamp(x, 100 + lightOrb.width / 2, GAME_W - lightOrb.width / 2); var ny = clamp(y, lightOrb.height / 2, GAME_H - lightOrb.height / 2); lightOrb.x = nx; lightOrb.y = ny; } } game.move = handleMove; // Down handler (start drag) game.down = function (x, y, obj) { // Only start drag if touch is on orb var dx = x - lightOrb.x; var dy = y - lightOrb.y; var dist = Math.sqrt(dx * dx + dy * dy); if (dist < lightOrb.width / 2 + 30) { dragging = true; lightOrb.flash(); handleMove(x, y, obj); } }; // Up handler (stop drag) game.up = function (x, y, obj) { dragging = false; }; // Shadow spawn timer var shadowTick = 0; // Main update loop game.update = function () { if (LK.isGameOver()) { // Use LK.resetGame() to fully reset the game state for retry LK.resetGame(); return; } // Spawn shadows shadowTick++; if (shadowTick >= shadowSpawnInterval) { shadowTick = 0; for (var i = 0; i < shadowCount; i++) { spawnShadow(); } } // PowerUp spawn: every 6-10 seconds, if none active or on field if (!powerUpActive && powerUps.length === 0 && Math.random() < 0.012) { var p = new PowerUp(); // Random type, now includes 'shrink' var types = ['slow', 'shield', 'score', 'shrink']; p.type = types[Math.floor(Math.random() * types.length)]; // Color by type var color = 0x00eaff; if (p.type === 'shield') color = 0x7fff00; if (p.type === 'score') color = 0xffd700; if (p.type === 'shrink') color = 0xff66cc; p.children[0].tint = color; // Place randomly, not too close to edges or player var safe = false, px, py, tries = 0; while (!safe && tries < 20) { px = 200 + Math.random() * (GAME_W - 400); py = 200 + Math.random() * (GAME_H - 400); var dx = px - lightOrb.x, dy = py - lightOrb.y; if (Math.sqrt(dx * dx + dy * dy) > 300) safe = true; tries++; } p.x = px; p.y = py; game.addChild(p); powerUps.push(p); } // Update shadows for (var i = shadows.length - 1; i >= 0; i--) { var s = shadows[i]; s.update(); // Out of bounds: if shadow is far outside, remove and score if (s.x < -300 || s.x > GAME_W + 300 || s.y < -300 || s.y > GAME_H + 300) { s.destroy(); shadows.splice(i, 1); // Score for successful dodge updateScore(score + 1); // Award 1 currency for each dodge updateCurrency(currency + 1); // Every 5 points, ramp up difficulty if (score > 0 && score % 5 === 0) { increaseDifficulty(); } continue; } // Collision with player var intersecting = s.intersects(lightOrb); if (!s.lastIntersecting && intersecting) { // If shield powerup is active, destroy shadow and continue if (powerUpActive && powerUpType === 'shield') { s.destroy(); shadows.splice(i, 1); continue; } // Flash screen, game over LK.effects.flashScreen(0xff2222, 900); LK.showGameOver(); return; } s.lastIntersecting = intersecting; } // PowerUp collection and effect for (var i = powerUps.length - 1; i >= 0; i--) { var p = powerUps[i]; var intersecting = p.intersects(lightOrb); if (!p.lastIntersecting && intersecting) { // Activate effect powerUpActive = true; powerUpType = p.type; powerUpTimer = 0; // Visual feedback LK.effects.flashObject(lightOrb, p.children[0].tint, 600); // Score boost: instant if (p.type === 'score') { updateScore(score + 10); // Award 5 currency for score powerup updateCurrency(currency + 5); powerUpActive = false; powerUpType = null; } // Shrink: shrink orb for 4 seconds if (p.type === 'shrink') { // Store original size if (!lightOrb._origW) { lightOrb._origW = lightOrb.width; lightOrb._origH = lightOrb.height; } lightOrb.width = lightOrb._origW * 0.55; lightOrb.height = lightOrb._origH * 0.55; } // Remove powerup from field p.destroy(); powerUps.splice(i, 1); continue; } p.lastIntersecting = intersecting; } // PowerUp timer/effect duration if (powerUpActive) { powerUpTimer++; // Shadow slow: 4 seconds if (powerUpType === 'slow') { // Visual feedback: pulse effect while slow is active if (powerUpTimer % 30 === 0) { LK.effects.flashObject(lightOrb, 0x00eaff, 200); } // Slow down all shadows for (var j = 0; j < shadows.length; j++) { shadows[j].speed = 0.7; } shadowSpeed = 0.7; if (powerUpTimer > 240) { powerUpActive = false; powerUpType = null; shadowSpeed = 2.2 + Math.floor(score / 5) * 0.18; // Restore all shadows to normal speed for (var j = 0; j < shadows.length; j++) { shadows[j].speed = shadowSpeed + Math.random() * 0.7; } } } // Shield: 4 seconds if (powerUpType === 'shield') { // Visual feedback: pulse effect while shield is active if (powerUpTimer % 30 === 0) { LK.effects.flashObject(lightOrb, 0x7fff00, 200); } if (powerUpTimer > 240) { powerUpActive = false; powerUpType = null; } } // Shrink: 4 seconds if (powerUpType === 'shrink') { // Visual feedback: pulse effect while shrink is active if (powerUpTimer % 30 === 0) { LK.effects.flashObject(lightOrb, 0xff66cc, 200); } if (powerUpTimer > 240) { powerUpActive = false; powerUpType = null; // Restore orb size if (lightOrb._origW) { lightOrb.width = lightOrb._origW; lightOrb.height = lightOrb._origH; } } } } else { // Reset shadowSpeed if not under slow powerup shadowSpeed = 2.2 + Math.floor(score / 5) * 0.18; for (var j = 0; j < shadows.length; j++) { shadows[j].speed = shadowSpeed + Math.random() * 0.7; } } }; // Initial score updateScore(0);
===================================================================
--- original.js
+++ change.js
@@ -306,35 +306,10 @@
var shadowTick = 0;
// Main update loop
game.update = function () {
if (LK.isGameOver()) {
- // Reset all game state for retry
- // Remove all shadows
- for (var i = 0; i < shadows.length; i++) {
- shadows[i].destroy();
- }
- shadows = [];
- // Remove all powerups
- for (var i = 0; i < powerUps.length; i++) {
- powerUps[i].destroy();
- }
- powerUps = [];
- // Reset player position
- lightOrb.x = GAME_W / 2;
- lightOrb.y = GAME_H * 0.75;
- // Reset powerup state
- powerUpActive = false;
- powerUpType = null;
- powerUpTimer = 0;
- // Reset difficulty
- shadowSpeed = 2.2;
- shadowSpawnInterval = 120;
- shadowCount = 2;
- // Reset dragging
- dragging = false;
- // Reset score
- updateScore(0);
- // Don't run rest of update until next tick
+ // Use LK.resetGame() to fully reset the game state for retry
+ LK.resetGame();
return;
}
// Spawn shadows
shadowTick++;