User prompt
Kısa tiklamayla gear olusturma.
User prompt
Gear ekledigimde ona ait sesi surekli çal. Gear tek kısa tıklamayla silinsin ve sesi sussun.
User prompt
Herbir gear çeşidi icin bir ses ekle
User prompt
Sesler gear olduğu surece surekli tekrar etsin.
User prompt
Gearin üstüne cift tıklayinca gear silinsin ve ses sussun.
User prompt
5 farklı gear için 5 farkli ses ekle
User prompt
5 farklı gear için 5 farkli ses ekle
User prompt
Tümünü 2 kat büyüt.
User prompt
dişli dişi yerine sadece dişli ifadesini kullan tüm isimleri değiştir
User prompt
5 farklı dişli asset olsun.
User prompt
Üst üste gelmesinler dişli içini kaldır. Büyüklük dokunma süresiyle orantılı olsun.
User prompt
Dişliler her defasında farklı boyut olsun. 5 farklı dönme sesi ekle
Code edit (1 edits merged)
Please save this source code
User prompt
Dönen Dişliler
Initial prompt
Tıkladıkca dişli ekleyeyim. Oluşan dişli çevirdiğim tarafa sürekli dönsün.
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Gear class: represents a single gear that rotates in a given direction and speed var Gear = Container.expand(function () { var self = Container.call(this); // Randomly select one of 5 gear assets var gearAssetIdx = Math.floor(Math.random() * 5) + 1; var gear = self.attachAsset('gear' + gearAssetIdx, { anchorX: 0.5, anchorY: 0.5 }); // Set up default size for asset (will be overridden externally) gear.width = 270 * 2; gear.height = 270 * 2; // Rotation speed in radians per frame (set externally) self.rotationSpeed = 0; // Play and loop the correct gear sound as long as this gear exists self._soundIdx = gearAssetIdx; self._sound = null; self._playLoopingSound = function () { if (self._sound) { self._sound.stop(); self._sound = null; } var s = LK.getSound('gearRotate' + self._soundIdx); if (s && s.play) { self._sound = s; s.play({ loop: true }); } }; // Start looping sound on creation self._playLoopingSound(); // Update method: rotates the gear self.update = function () { self.rotation += self.rotationSpeed; // Defensive: if sound stopped for any reason, restart it if (self._sound && !self._sound.isPlaying) { self._playLoopingSound(); } }; // Double-tap detection variables self._lastTapTime = 0; self._tapTimeout = null; // Helper to stop all gear sounds self._stopAllGearSounds = function () { for (var i = 1; i <= 5; i++) { var s = LK.getSound('gearRotate' + i); if (s && s.stop) s.stop(); } }; // Handle down event for double-tap self.down = function (x, y, obj) { var now = Date.now(); if (self._lastTapTime && now - self._lastTapTime < 350) { // Double-tap detected: remove gear and stop sound if (self._sound && self._sound.stop) { self._sound.stop(); self._sound = null; } // Remove from game and gears array if (self.parent) self.parent.removeChild(self); for (var i = 0; i < gears.length; i++) { if (gears[i] === self) { gears.splice(i, 1); break; } } // Prevent further taps self._lastTapTime = 0; if (self._tapTimeout) { LK.clearTimeout(self._tapTimeout); self._tapTimeout = null; } return; } self._lastTapTime = now; // Clear tap after 400ms if no second tap if (self._tapTimeout) LK.clearTimeout(self._tapTimeout); self._tapTimeout = LK.setTimeout(function () { self._lastTapTime = 0; self._tapTimeout = null; }, 400); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0xffffff // White background for clarity }); /**** * Game Code ****/ // List of all gears in the game // We need tween for smooth rotation animations var gears = []; // For drag direction detection var isDragging = false; var dragStart = null; // {x, y} var dragCurrent = null; // {x, y} // Helper: calculate angle between two points (in radians) function getAngle(x1, y1, x2, y2) { return Math.atan2(y2 - y1, x2 - x1); } // Helper: clamp rotation speed function clamp(val, min, max) { if (val < min) return min; if (val > max) return max; return val; } // Show a simple instruction at the top (not in topLeft) var infoTxt = new Text2('Ekrana basılı tut, çek ve bırak: Dişli ekle!', { size: 90, fill: 0x333333 }); infoTxt.anchor.set(0.5, 0); LK.gui.top.addChild(infoTxt); // Main game event handlers // On press down: start drag game.down = function (x, y, obj) { isDragging = true; game._touchStartTime = Date.now(); dragStart = { x: x, y: y }; dragCurrent = { x: x, y: y }; }; // On move: update drag current position game.move = function (x, y, obj) { if (isDragging) { dragCurrent.x = x; dragCurrent.y = y; } }; // On release: create a new gear at dragStart, rotating in the direction of drag game.up = function (x, y, obj) { if (!isDragging || !dragStart) return; // Calculate drag vector var dx = dragCurrent.x - dragStart.x; var dy = dragCurrent.y - dragStart.y; var dist = Math.sqrt(dx * dx + dy * dy); // If drag is too short, set a default direction (upwards) var angle; if (dist < 30) { angle = -Math.PI / 2; // Upwards } else { angle = getAngle(dragStart.x, dragStart.y, dragCurrent.x, dragCurrent.y); } // Rotation speed: proportional to drag length, with min/max // 0.01 rad/frame (slow) to 0.07 rad/frame (fast) var speed = clamp(dist / 3000, 0.01, 0.07); // Direction: clockwise if drag is rightwards, counterclockwise if leftwards // We'll use the sign of dx to determine direction if (dx < 0) speed = -speed; // Create and position the gear var gear = new Gear(); // Calculate touch duration for proportional size if (!game._touchStartTime) game._touchStartTime = Date.now(); var touchDuration = Date.now() - game._touchStartTime; if (touchDuration < 80) touchDuration = 80; // minimum if (touchDuration > 1800) touchDuration = 1800; // maximum // Map duration to gear size (gear diameter: 240-780) var minGear = 120 * 2, maxGear = 390 * 2; var gearSize = minGear + (maxGear - minGear) * ((touchDuration - 80) / (1800 - 80)); if (gearSize < minGear) gearSize = minGear; if (gearSize > maxGear) gearSize = maxGear; // Place gear at drag start gear.x = dragStart.x; gear.y = dragStart.y; gear.rotationSpeed = speed; // Prevent overlapping: check if new gear would overlap any existing gear var overlap = false; for (var i = 0; i < gears.length; i++) { var other = gears[i]; var dxg = gear.x - other.x; var dyg = gear.y - other.y; var distg = Math.sqrt(dxg * dxg + dyg * dyg); var otherGear = other.children[0].width; // Only gear asset if (distg < (gearSize + otherGear) / 2 + 10) { // 10px buffer overlap = true; break; } } if (overlap) { // Do not add gear, just reset drag state isDragging = false; dragStart = null; dragCurrent = null; game._touchStartTime = null; return; } // Set gear size (only gear asset) gear.children[0].width = gearSize; gear.children[0].height = gearSize; // (Sound is now handled per-gear and loops as long as the gear exists) // Add to game and to gears array game.addChild(gear); gears.push(gear); // Reset drag state isDragging = false; dragStart = null; dragCurrent = null; game._touchStartTime = null; }; // Update loop: update all gears game.update = function () { for (var i = 0; i < gears.length; i++) { if (gears[i].update) gears[i].update(); } };
===================================================================
--- original.js
+++ change.js
red gear top view tranparent. In-Game asset. 2d. High contrast. No shadows
yellow gear top view tranparent. In-Game asset. 2d. High contrast. No shadows
Green gear top view tranparent. In-Game asset. 2d. High contrast. No shadows
Mavi renk deniz manzarası. In-Game asset. 2d. High contrast. No shadows
Just a finger top view. In-Game asset. 2d. High contrast. No shadows