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"); /**** * 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: 'speed', 'shield', 'score' self.type = 'speed'; // 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); // 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 () { // 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 var types = ['speed', 'shield', 'score']; 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; 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); // 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); powerUpActive = false; powerUpType = null; } // Remove powerup from field p.destroy(); powerUps.splice(i, 1); continue; } p.lastIntersecting = intersecting; } // PowerUp timer/effect duration if (powerUpActive) { powerUpTimer++; // Speed boost: 4 seconds if (powerUpType === 'speed') { shadowSpeed = 1.1; // Slow down shadows if (powerUpTimer > 240) { powerUpActive = false; powerUpType = null; shadowSpeed = 2.2 + Math.floor(score / 5) * 0.18; } } // Shield: 4 seconds if (powerUpType === 'shield') { if (powerUpTimer > 240) { powerUpActive = false; powerUpType = null; } } } else { // Reset shadowSpeed if not under speed powerup shadowSpeed = 2.2 + Math.floor(score / 5) * 0.18; } }; // Initial score updateScore(0);
===================================================================
--- original.js
+++ change.js
@@ -30,8 +30,29 @@
};
// 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: 'speed', 'shield', 'score'
+ self.type = 'speed';
+ // 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', {
@@ -74,8 +95,14 @@
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,
@@ -185,8 +212,37 @@
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
+ var types = ['speed', 'shield', 'score'];
+ 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;
+ 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();
@@ -204,14 +260,67 @@
}
// 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);
+ powerUpActive = false;
+ powerUpType = null;
+ }
+ // Remove powerup from field
+ p.destroy();
+ powerUps.splice(i, 1);
+ continue;
+ }
+ p.lastIntersecting = intersecting;
+ }
+ // PowerUp timer/effect duration
+ if (powerUpActive) {
+ powerUpTimer++;
+ // Speed boost: 4 seconds
+ if (powerUpType === 'speed') {
+ shadowSpeed = 1.1; // Slow down shadows
+ if (powerUpTimer > 240) {
+ powerUpActive = false;
+ powerUpType = null;
+ shadowSpeed = 2.2 + Math.floor(score / 5) * 0.18;
+ }
+ }
+ // Shield: 4 seconds
+ if (powerUpType === 'shield') {
+ if (powerUpTimer > 240) {
+ powerUpActive = false;
+ powerUpType = null;
+ }
+ }
+ } else {
+ // Reset shadowSpeed if not under speed powerup
+ shadowSpeed = 2.2 + Math.floor(score / 5) * 0.18;
+ }
};
// Initial score
updateScore(0);
\ No newline at end of file