User prompt
her bir hedefi vurmamız için 5 saniyemiz olsun 5 saniye bittiğinde kaybedelim
User prompt
kaskı silelim
User prompt
karakterimizin kafasında bir kask olsun
User prompt
başla tuşuna basınca başlasın
User prompt
oyuna bir giriş menüsü ekleyelim
User prompt
skor 10'un katlarına ulaştığında bir rozet kazanalım
User prompt
baktığımız yere göre silah hareket etsin
User prompt
karakterin elinde bir silah olsun
User prompt
arkadaki yeşil şeyler konteynır olsun
User prompt
arkaplanda poligon gibi olsun
User prompt
ortada karakterimiz olsun
User prompt
mermi hedefe çarptığında hedef yok olsun
User prompt
When we click, a bullet goes
Code edit (1 edits merged)
Please save this source code
User prompt
Quick Aim Challenge
Initial prompt
Let's make an aim game
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ /**** * End of file ****/ // Badge class for visual badge reward var Badge = Container.expand(function () { var self = Container.call(this); // Use the 'miss' asset as a placeholder badge, but tint it gold var badgeAsset = self.attachAsset('miss', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.1, scaleY: 1.1, alpha: 0.92, tint: 0xffd700 // gold color }); // Animate badge pop badgeAsset.scaleX = 0.2; badgeAsset.scaleY = 0.2; tween(badgeAsset, { scaleX: 1.1, scaleY: 1.1, alpha: 1 }, { duration: 220, easing: tween.easeOut }); // Animate badge fade out after 1s tween(badgeAsset, { alpha: 0 }, { delay: 900, duration: 400, onFinish: function onFinish() { self.destroy(); } }); return self; }); // Bullet class var Bullet = Container.expand(function () { var self = Container.call(this); var bulletAsset = self.attachAsset('tapfx', { anchorX: 0.5, anchorY: 0.5, scaleX: 0.5, scaleY: 0.5, alpha: 0.9 }); self.speed = 48; // Fast bullet for tap feel self.dirX = 0; self.dirY = 0; self.lifetime = 30; // frames self.age = 0; self.update = function () { self.x += self.dirX * self.speed; self.y += self.dirY * self.speed; self.age++; if (self.age > self.lifetime) { self.destroy(); } }; return self; }); // Character class var Character = Container.expand(function () { var self = Container.call(this); var charAsset = self.attachAsset('miss', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.1, scaleY: 1.1, alpha: 0.7 }); // Add gun asset to character's hand var gunAsset = self.attachAsset('gun', { anchorX: 0.2, // grip of gun anchorY: 0.7, // handle of gun x: charAsset.width * 0.32, // right hand side of character y: charAsset.height * 0.18, scaleX: 1.0, scaleY: 1.0, rotation: -0.18 // slight angle for natural look }); // Make sure gun is above the character's hand visually self.addChild(gunAsset); return self; }); // Target class var Target = Container.expand(function () { var self = Container.call(this); var targetAsset = self.attachAsset('target', { anchorX: 0.5, anchorY: 0.5 }); self.radius = targetAsset.width / 2; self.active = true; self.appearedAt = LK.ticks; self.lifetime = 90; // 1.5 seconds at 60fps // Show tap feedback self.showTapFx = function () { var fx = LK.getAsset('tapfx', { anchorX: 0.5, anchorY: 0.5, x: 0, y: 0, scaleX: 1, scaleY: 1, alpha: 0.7 }); self.addChild(fx); tween(fx, { scaleX: 1.5, scaleY: 1.5, alpha: 0 }, { duration: 250, easing: tween.easeOut, onFinish: function onFinish() { fx.destroy(); } }); }; // Called when target is hit self.hit = function () { if (!self.active) return; self.active = false; self.showTapFx(); tween(targetAsset, { alpha: 0 }, { duration: 120, onFinish: function onFinish() { self.destroy(); } }); }; // Called when target times out (missed) self.miss = function () { if (!self.active) return; self.active = false; var missFx = LK.getAsset('miss', { anchorX: 0.5, anchorY: 0.5, x: 0, y: 0, alpha: 0.5, scaleX: 1, scaleY: 1 }); self.addChild(missFx); tween(missFx, { scaleX: 1.5, scaleY: 1.5, alpha: 0 }, { duration: 300, onFinish: function onFinish() { missFx.destroy(); } }); tween(targetAsset, { alpha: 0.2 }, { duration: 180, onFinish: function onFinish() { self.destroy(); } }); }; // Per-frame update self.update = function () { if (!self.active) return; if (LK.ticks - self.appearedAt > self.lifetime) { self.miss(); // Penalize time for miss timeLeft -= 1.5; if (timeLeft < 0) timeLeft = 0; } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x181c22 }); /**** * Game Code ****/ // Game state variables // Target: green ellipse, 180x180 // Miss feedback: red ellipse, 180x180 // Tap effect: yellow ellipse, 180x180 var score = 0; var timeLeft = 20; // seconds var target = null; var bullets = []; // --- Entry Menu Overlay --- var entryMenu = new Container(); var menuBg = LK.getAsset('containerbg_0', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2, scaleX: 2.2, scaleY: 2.2, alpha: 0.92 }); entryMenu.addChild(menuBg); var titleTxt = new Text2('Hedefe Dokun', { size: 180, fill: '#fff' }); titleTxt.anchor.set(0.5, 0.5); titleTxt.x = 2048 / 2; titleTxt.y = 900; entryMenu.addChild(titleTxt); var playBtn = new Text2('Başla', { size: 120, fill: '#27ae60' }); playBtn.anchor.set(0.5, 0.5); playBtn.x = 2048 / 2; playBtn.y = 1400; entryMenu.addChild(playBtn); var howtoTxt = new Text2('Hedeflere hızlıca dokun, süre bitmeden puan topla!', { size: 70, fill: '#fff' }); howtoTxt.anchor.set(0.5, 0.5); howtoTxt.x = 2048 / 2; howtoTxt.y = 1700; entryMenu.addChild(howtoTxt); game.addChild(entryMenu); // Block gameplay until menu is dismissed var gameStarted = false; game.down = function (x, y, obj) { if (!gameStarted) { // Only start if play button is tapped var dx = x - playBtn.x; var dy = y - playBtn.y; if (dx * dx + dy * dy < 400 * 400) { entryMenu.destroy(); gameStarted = true; } return; } // Only allow taps if game is running and target is active if (!target || !target.active || timeLeft <= 0) return; // --- Rotate gun towards tap/cursor position --- // Find the gun asset in the character if (character && character.children && character.children.length > 1) { // gunAsset is always the second child (after charAsset) var gunAsset = character.children[1]; // Gun's local position relative to character var gunLocalX = gunAsset.x; var gunLocalY = gunAsset.y; // Character's global position var charGlobalX = character.x; var charGlobalY = character.y; // Gun's global position var gunGlobalX = charGlobalX + gunLocalX - character.children[0].width * 0.5; var gunGlobalY = charGlobalY + gunLocalY - character.children[0].height * 0.5; // Calculate angle from gun to tap var dx2 = x - gunGlobalX; var dy2 = y - gunGlobalY; var angle = Math.atan2(dy2, dx2); gunAsset.rotation = angle; } // Fire a bullet towards tap location var bullet = new Bullet(); bullet.x = 1024; // center of screen (2048/2) bullet.y = 1366; // center of screen (2732/2) var distX = x - bullet.x; var distY = y - bullet.y; var dist = Math.sqrt(distX * distX + distY * distY); if (dist > 0) { bullet.dirX = distX / dist; bullet.dirY = distY / dist; } bullets.push(bullet); game.addChild(bullet); // Check if tap is inside target var dx3 = x - target.x; var dy3 = y - target.y; if (dx3 * dx3 + dy3 * dy3 <= target.radius * target.radius) { // Hit! target.hit(); score += 1; scoreTxt.setText(score); // Add 1.2s for quick hit, 0.8s for slow var hitTime = (LK.ticks - target.appearedAt) / 60; if (hitTime < 0.7) { timeLeft += 1.2; } else { timeLeft += 0.8; } if (timeLeft > 30) timeLeft = 30; // Cap max time spawnTarget(); } else { // Missed tap: penalize timeLeft -= 1.2; if (timeLeft < 0) timeLeft = 0; // Show quick miss feedback at tap var missFx = LK.getAsset('miss', { anchorX: 0.5, anchorY: 0.5, x: x, y: y, alpha: 0.4, scaleX: 1, scaleY: 1 }); game.addChild(missFx); tween(missFx, { scaleX: 1.5, scaleY: 1.5, alpha: 0 }, { duration: 250, onFinish: function onFinish() { missFx.destroy(); } }); } }; // Decorative green container-like background var containerBgShapes = []; (function createContainerBackground() { // Use greenish colors for containers var greens = [0x6fcf97, 0x27ae60, 0x219150, 0x43b97f, 0x8fd19e]; var shapes = [{ type: 'box', x: 400, y: 400, w: 900, h: 400, rot: 0.12, alpha: 0.18, color: greens[0] }, { type: 'box', x: 1600, y: 600, w: 800, h: 350, rot: -0.08, alpha: 0.15, color: greens[1] }, { type: 'ellipse', x: 1000, y: 1700, w: 700, h: 400, rot: 0.05, alpha: 0.13, color: greens[2] }, { type: 'box', x: 1550, y: 2100, w: 600, h: 500, rot: 0.22, alpha: 0.12, color: greens[3] }, { type: 'ellipse', x: 500, y: 2200, w: 600, h: 350, rot: -0.18, alpha: 0.11, color: greens[4] }]; for (var i = 0; i < shapes.length; i++) { var s = shapes[i]; // Dynamically create the shape asset if not already present var assetId = 'containerbg_' + i; // Register the asset if not already registered if (!LK.assets || !LK.assets[assetId]) {} var bgShape = LK.getAsset(assetId, { anchorX: 0.5, anchorY: 0.5, x: s.x, y: s.y, rotation: s.rot, alpha: s.alpha }); containerBgShapes.push(bgShape); game.addChild(bgShape); } })(); // Add character to center of screen var character = new Character(); character.x = 2048 / 2; character.y = 2732 / 2; game.addChild(character); var scoreTxt = new Text2('0', { size: 120, fill: '#fff' }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); var timerTxt = new Text2('20.0', { size: 90, fill: '#fff' }); timerTxt.anchor.set(0.5, 0); LK.gui.topRight.addChild(timerTxt); // Prevent UI overlap with top left menu (100x100) scoreTxt.y = 20; timerTxt.y = 20; // Spawn a new target at a random position function spawnTarget() { if (target && target.active) target.miss(); var t = new Target(); // Avoid top 200px and bottom 200px for UI and finger comfort var margin = 200; var x = margin + Math.random() * (2048 - 2 * margin); var y = margin + Math.random() * (2732 - 2 * margin); t.x = x; t.y = y; target = t; game.addChild(t); } // Handle tap/clicks // Main update loop game.update = function () { // Pause game logic if entry menu is up if (!gameStarted) return; // Update timer if (timeLeft > 0) { timeLeft -= 1 / 60; if (timeLeft < 0) timeLeft = 0; } timerTxt.setText(timeLeft.toFixed(1)); // End game if time runs out if (timeLeft <= 0) { if (target && target.active) target.miss(); LK.setScore(score); LK.showGameOver(); return; } // Spawn first target if needed if (!target || !target.active) { spawnTarget(); } // Update and clean up bullets for (var i = bullets.length - 1; i >= 0; i--) { var b = bullets[i]; // Check for bullet-target collision (only if both exist and are active) if (target && target.active && !b.destroyed && b.x !== undefined && b.y !== undefined && target.x !== undefined && target.y !== undefined) { var dx = b.x - target.x; var dy = b.y - target.y; if (dx * dx + dy * dy <= target.radius * target.radius) { target.hit(); b.destroy(); bullets.splice(i, 1); continue; } } if (b.destroyed) { bullets.splice(i, 1); } } }; // Reset game state on restart game.on('reset', function () { score = 0; timeLeft = 20; scoreTxt.setText(score); timerTxt.setText(timeLeft.toFixed(1)); if (target) { target.destroy(); target = null; } // Recreate entry menu if (entryMenu && !entryMenu.destroyed) entryMenu.destroy(); entryMenu = new Container(); var menuBg = LK.getAsset('containerbg_0', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2, scaleX: 2.2, scaleY: 2.2, alpha: 0.92 }); entryMenu.addChild(menuBg); var titleTxt = new Text2('Hedefe Dokun', { size: 180, fill: '#fff' }); titleTxt.anchor.set(0.5, 0.5); titleTxt.x = 2048 / 2; titleTxt.y = 900; entryMenu.addChild(titleTxt); var playBtn = new Text2('Başla', { size: 120, fill: '#27ae60' }); playBtn.anchor.set(0.5, 0.5); playBtn.x = 2048 / 2; playBtn.y = 1400; entryMenu.addChild(playBtn); var howtoTxt = new Text2('Hedeflere hızlıca dokun, süre bitmeden puan topla!', { size: 70, fill: '#fff' }); howtoTxt.anchor.set(0.5, 0.5); howtoTxt.x = 2048 / 2; howtoTxt.y = 1700; entryMenu.addChild(howtoTxt); game.addChild(entryMenu); gameStarted = false; }); score += 1; scoreTxt.setText(score); // Show badge if score is a multiple of 10 if (score > 0 && score % 10 === 0) { var badge = new Badge(); badge.x = 2048 / 2; badge.y = 2732 / 2 - 200; game.addChild(badge); }
===================================================================
--- original.js
+++ change.js
@@ -78,19 +78,8 @@
scaleX: 1.1,
scaleY: 1.1,
alpha: 0.7
});
- // Add helmet asset to character's head
- var helmetAsset = self.attachAsset('helmet', {
- anchorX: 0.5,
- anchorY: 0.8,
- x: charAsset.width * 0.5,
- y: charAsset.height * 0.13,
- scaleX: 1.05,
- scaleY: 1.05,
- alpha: 0.98
- });
- self.addChild(helmetAsset);
// Add gun asset to character's hand
var gunAsset = self.attachAsset('gun', {
anchorX: 0.2,
// grip of gun