User prompt
itler olmasın
User prompt
npcler yakalanırsa -1 olsun puan
User prompt
köpek balığı belirli bölgelerde çıksın ve npcleri kovalasın
User prompt
itler belirli bölgelerde çıksın
User prompt
itler sola ve sağa gitsin
User prompt
npc kurtarilmadığında 5 numaralı efekt gelsin
User prompt
oyun başlayınca 6 numaralı müzik çalsın
User prompt
npcleri hareket etirelim
User prompt
güvenli böleyi hareket ettirelim ve adaya ulaşınca 5 adlı ses efkti duyulsun ↪💡 Consider importing and using the following plugins: @upit/tween.v1
Code edit (1 edits merged)
Please save this source code
User prompt
Can Kurtaran: Kurtarma Operasyonu
Initial prompt
bizim can kurtaran olup diğer oyuncuları kurtardığımız oyun
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Class for NPCs (people to rescue) var NPC = Container.expand(function () { var self = Container.call(this); // Attach NPC asset (ellipse, random color) var npcColor = 0x3498db + Math.floor(Math.random() * 0x222222); var npcAsset = self.attachAsset('npc', { width: 120, height: 120, color: npcColor, shape: 'ellipse', anchorX: 0.5, anchorY: 0.5 }); // Is this NPC being dragged? self.isDragging = false; // Mark if rescued (to avoid double rescue) self.rescued = false; // For drag offset self.dragOffsetX = 0; self.dragOffsetY = 0; // Called every tick self.update = function () { // If not being dragged, move down and also move horizontally if (!self.isDragging && !self.rescued) { // Move down self.y += self.fallSpeed; // Move horizontally if (typeof self.dir === "undefined") { // Randomly pick initial direction: -1 (left) or 1 (right) self.dir = Math.random() < 0.5 ? -1 : 1; } if (typeof self.horizSpeed === "undefined") { // Random horizontal speed between 1.2 and 2.5 self.horizSpeed = 1.2 + Math.random() * 1.3; } self.x += self.dir * self.horizSpeed; // Bounce off screen edges var margin = 70; if (self.x < margin) { self.x = margin; self.dir = 1; } if (self.x > 2048 - margin) { self.x = 2048 - margin; self.dir = -1; } } }; // On down (touch/click) self.down = function (x, y, obj) { if (self.rescued) return; self.isDragging = true; // Calculate offset between touch and center self.dragOffsetX = self.x - x; self.dragOffsetY = self.y - y; // Bring to front if (self.parent) { self.parent.setChildIndex(self, self.parent.children.length - 1); } }; // On up (touch/click release) self.up = function (x, y, obj) { self.isDragging = false; }; return self; }); // Class for Safe Zone var SafeZone = Container.expand(function () { var self = Container.call(this); // Attach safe zone asset (green ellipse) var safeAsset = self.attachAsset('safezone', { width: 400, height: 180, color: 0x2ecc40, shape: 'ellipse', anchorX: 0.5, anchorY: 0.5 }); // Add a label var label = new Text2('GÜVENLİ ALAN', { size: 60, fill: 0xFFFFFF }); label.anchor.set(0.5, 0.5); label.y = 0; self.addChild(label); return self; }); // Shark class: spawns in specific regions and chases nearest NPC var Shark = Container.expand(function () { var self = Container.call(this); // Attach shark asset (replace with a generic box for now) var sharkAsset = self.attachAsset('box', { width: 180, height: 100, color: 0x222222, shape: 'box', anchorX: 0.5, anchorY: 0.5 }); // Shark speed self.speed = 4 + Math.random() * 1.5; // Target NPC (to chase) self.target = null; // For region logic self.region = null; // For direction flip self.lastDir = 1; // Called every tick self.update = function () { // Find nearest NPC to chase if (npcs && npcs.length > 0) { var minDist = 99999; var closest = null; for (var i = 0; i < npcs.length; i++) { var npc = npcs[i]; if (npc.rescued) continue; var dx = npc.x - self.x; var dy = npc.y - self.y; var dist = dx * dx + dy * dy; if (dist < minDist) { minDist = dist; closest = npc; } } self.target = closest; } else { self.target = null; } // Move toward target NPC if (self.target) { var dx = self.target.x - self.x; var dy = self.target.y - self.y; var dist = Math.sqrt(dx * dx + dy * dy); if (dist > 1) { var moveX = dx / dist * self.speed; var moveY = dy / dist * self.speed * 0.7; // Slightly less vertical self.x += moveX; self.y += moveY; // Flip sprite if needed if (moveX < 0 && self.lastDir !== -1) { sharkAsset.scaleX = -1; self.lastDir = -1; } else if (moveX > 0 && self.lastDir !== 1) { sharkAsset.scaleX = 1; self.lastDir = 1; } } } // Clamp inside region if (self.region) { if (self.x < self.region.min) self.x = self.region.min; if (self.x > self.region.max) self.x = self.region.max; } // If shark goes below screen, respawn at top if (self.y > 2732 + 100) { self.respawn(); } }; // Respawn at top in a region self.respawn = function () { // Pick a region var sharkRegions = [{ min: 300, max: 600 }, { min: 900, max: 1200 }, { min: 1500, max: 1800 }]; var region = sharkRegions[Math.floor(Math.random() * sharkRegions.length)]; self.region = region; self.x = region.min + Math.random() * (region.max - region.min); self.y = -100 - Math.random() * 100; self.speed = 4 + Math.random() * 1.5; }; // Initial spawn self.respawn(); return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87ceeb // Sky blue }); /**** * Game Code ****/ // Tween plugin for animations // Game variables var npcs = []; // All NPCs on screen var sharks = []; // All sharks on screen var safeZone; // The safe zone object var score = 0; var scoreTxt; var spawnInterval = 180; // Initial spawn interval (frames) var npcFallSpeed = 2.5; // Initial NPC fall speed var minSpawnInterval = 60; // Minimum interval (hardest) var maxNPCs = 3; // Max NPCs on screen at once (increases with difficulty) var dragNode = null; // Currently dragged NPC var lastMoveX = 0, lastMoveY = 0; // Add Safe Zone at bottom center safeZone = new SafeZone(); safeZone.x = 2048 / 2; safeZone.y = 2732 - 200; safeZone.isDragging = false; safeZone.dragOffsetX = 0; safeZone.lastX = safeZone.x; game.addChild(safeZone); // Play music '6' at game start LK.playMusic('6'); // Score text at top center scoreTxt = new Text2('0', { size: 120, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Helper: Spawn a new NPC at random X, near top function spawnNPC() { if (npcs.length >= maxNPCs) return; var npc = new NPC(); // Spawn NPC at random X across the screen (excluding margins) var margin = 120; npc.x = margin + Math.random() * (2048 - 2 * margin); npc.y = 200 + Math.random() * 200; npc.fallSpeed = npcFallSpeed + Math.random() * 1.5; npc.isDragging = false; npc.rescued = false; npc.lastIntersecting = false; npcs.push(npc); game.addChild(npc); } // Helper: Remove NPC from game and array function removeNPC(npc) { var idx = npcs.indexOf(npc); if (idx !== -1) { npcs.splice(idx, 1); } npc.destroy(); } // Helper: Rescue NPC (with animation) function rescueNPC(npc) { npc.rescued = true; // Animate: scale up and fade out tween(npc, { scaleX: 1.5, scaleY: 1.5, alpha: 0 }, { duration: 400, easing: tween.easeOut, onFinish: function onFinish() { removeNPC(npc); } }); // Score up score += 1; LK.setScore(score); scoreTxt.setText(score); // Difficulty increases every 5 points if (score % 5 === 0 && spawnInterval > minSpawnInterval) { spawnInterval -= 15; npcFallSpeed += 0.5; maxNPCs = Math.min(6, maxNPCs + 1); // Flash safe zone to indicate difficulty up LK.effects.flashObject(safeZone, 0xffff00, 400); } } // Helper: Game over (NPC fell below screen) function triggerGameOver() { LK.effects.flashScreen(0xff0000, 800); LK.showGameOver(); } // Game move handler (drag NPCs) function handleMove(x, y, obj) { lastMoveX = x; lastMoveY = y; if (dragNode && !dragNode.rescued) { dragNode.x = x + dragNode.dragOffsetX; dragNode.y = y + dragNode.dragOffsetY; } // Safe zone dragging (horizontal only) if (safeZone.isDragging) { // Only allow horizontal movement, keep y fixed var newX = x + safeZone.dragOffsetX; // Clamp within screen var minX = safeZone.width / 2; var maxX = 2048 - safeZone.width / 2; if (newX < minX) newX = minX; if (newX > maxX) newX = maxX; safeZone.x = newX; } } game.move = handleMove; // On down: check if touching an NPC or safe zone game.down = function (x, y, obj) { // Find topmost NPC under pointer var found = false; for (var i = npcs.length - 1; i >= 0; i--) { var npc = npcs[i]; // Simple hit test (circle) var dx = x - npc.x; var dy = y - npc.y; var r = 60; if (dx * dx + dy * dy < r * r && !npc.rescued) { dragNode = npc; npc.down(x, y, obj); found = true; break; } } // If not on NPC, check if on safe zone (ellipse hit test) if (!found) { var dxz = x - safeZone.x; var dyz = y - safeZone.y; // Ellipse: (dx/a)^2 + (dy/b)^2 <= 1 var a = safeZone.width / 2; var b = safeZone.height / 2; if (dxz * dxz / (a * a) + dyz * dyz / (b * b) <= 1) { safeZone.isDragging = true; safeZone.dragOffsetX = safeZone.x - x; } } }; // On up: release drag game.up = function (x, y, obj) { if (dragNode) { dragNode.up(x, y, obj); dragNode = null; } if (safeZone.isDragging) { safeZone.isDragging = false; } }; // Main game update loop game.update = function () { // Spawn NPCs at interval if (LK.ticks % spawnInterval === 0) { spawnNPC(); } // Update all NPCs for (var i = npcs.length - 1; i >= 0; i--) { var npc = npcs[i]; // If being dragged, follow finger (handled in move) // If not, update position (handled in class update) // Check if rescued (intersecting safe zone) var isIntersecting = !npc.rescued && npc.intersects(safeZone); if (!npc.lastIntersecting && isIntersecting) { rescueNPC(npc); } npc.lastIntersecting = isIntersecting; // If NPC falls below screen, play sound and game over if (!npc.rescued && npc.y > 2732 + 80) { LK.getSound('5').play(); triggerGameOver(); return; } } // Update all sharks and check for shark-NPC collision for (var s = 0; s < sharks.length; s++) { var shark = sharks[s]; shark.update(); // Check collision with NPCs for (var n = npcs.length - 1; n >= 0; n--) { var npc = npcs[n]; if (!npc.rescued && shark.intersects(npc)) { // Remove NPC, play sound, and respawn shark LK.getSound('5').play(); removeNPC(npc); shark.respawn(); // Decrease score by 1 (minimum 0) score = Math.max(0, score - 1); LK.setScore(score); scoreTxt.setText(score); // Optional: flash shark or screen LK.effects.flashObject(shark, 0xff0000, 300); break; } } } // --- Safe zone left edge detection and sound effect --- if (typeof safeZone.lastX === "undefined") safeZone.lastX = safeZone.x; var leftEdge = safeZone.width / 2; if (safeZone.lastX > leftEdge && safeZone.x <= leftEdge) { // Play sound '5' when safe zone reaches the left edge LK.getSound('5').play(); } safeZone.lastX = safeZone.x; }; // Initial spawn for (var i = 0; i < 2; i++) { spawnNPC(); } // Spawn sharks (e.g. 2 sharks) for (var i = 0; i < 2; i++) { var shark = new Shark(); sharks.push(shark); game.addChild(shark); } score = 0; LK.setScore(score); scoreTxt.setText(score);
===================================================================
--- original.js
+++ change.js
@@ -96,12 +96,14 @@
});
// Shark class: spawns in specific regions and chases nearest NPC
var Shark = Container.expand(function () {
var self = Container.call(this);
- // Attach shark asset (use 'itler' for now, or replace with shark asset if available)
- var sharkAsset = self.attachAsset('itler', {
+ // Attach shark asset (replace with a generic box for now)
+ var sharkAsset = self.attachAsset('box', {
width: 180,
height: 100,
+ color: 0x222222,
+ shape: 'box',
anchorX: 0.5,
anchorY: 0.5
});
// Shark speed
@@ -231,24 +233,11 @@
// Helper: Spawn a new NPC at random X, near top
function spawnNPC() {
if (npcs.length >= maxNPCs) return;
var npc = new NPC();
- // --- itler (dogs) spawn at specific regions ---
- // Define allowed X regions for itler (dogs)
- var itlerRegions = [{
- min: 300,
- max: 600
- }, {
- min: 900,
- max: 1200
- }, {
- min: 1500,
- max: 1800
- }];
- // Pick a random region
- var region = itlerRegions[Math.floor(Math.random() * itlerRegions.length)];
- // Pick a random X within the region
- npc.x = region.min + Math.random() * (region.max - region.min);
+ // Spawn NPC at random X across the screen (excluding margins)
+ var margin = 120;
+ npc.x = margin + Math.random() * (2048 - 2 * margin);
npc.y = 200 + Math.random() * 200;
npc.fallSpeed = npcFallSpeed + Math.random() * 1.5;
npc.isDragging = false;
npc.rescued = false;