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 ****/ // 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 }); 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 = []; // Decorative polygon-like background var polyBgShapes = []; (function createPolygonBackground() { // We'll use a few large, semi-transparent polygons (as boxes/ellipses) for a polygonal look var colors = [0x23283a, 0x1a1e2b, 0x22263a, 0x20243a, 0x181c22]; var shapes = [{ type: 'box', x: 400, y: 300, w: 1200, h: 900, rot: 0.18, alpha: 0.18, color: colors[0] }, { type: 'box', x: 1200, y: 800, w: 1100, h: 700, rot: -0.12, alpha: 0.13, color: colors[1] }, { type: 'ellipse', x: 900, y: 1800, w: 900, h: 600, rot: 0.07, alpha: 0.11, color: colors[2] }, { type: 'box', x: 1600, y: 2000, w: 700, h: 900, rot: 0.32, alpha: 0.10, color: colors[3] }, { type: 'ellipse', x: 400, y: 2200, w: 800, h: 500, rot: -0.22, alpha: 0.09, color: colors[4] }]; for (var i = 0; i < shapes.length; i++) { var s = shapes[i]; var assetId = 'polybg_' + i; // Dynamically create the shape asset if not already present var bgShape = LK.getAsset(assetId, { anchorX: 0.5, anchorY: 0.5, x: s.x, y: s.y, rotation: s.rot, alpha: s.alpha }); polyBgShapes.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 game.down = function (x, y, obj) { // Only allow taps if game is running and target is active if (!target || !target.active || timeLeft <= 0) return; // 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 dx = x - target.x; var dy = y - target.y; if (dx * dx + dy * dy <= 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(); } }); } }; // Main update loop game.update = function () { // 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; } }); /**** * End of file ****/
===================================================================
--- original.js
+++ change.js
@@ -155,8 +155,75 @@
var score = 0;
var timeLeft = 20; // seconds
var target = null;
var bullets = [];
+// Decorative polygon-like background
+var polyBgShapes = [];
+(function createPolygonBackground() {
+ // We'll use a few large, semi-transparent polygons (as boxes/ellipses) for a polygonal look
+ var colors = [0x23283a, 0x1a1e2b, 0x22263a, 0x20243a, 0x181c22];
+ var shapes = [{
+ type: 'box',
+ x: 400,
+ y: 300,
+ w: 1200,
+ h: 900,
+ rot: 0.18,
+ alpha: 0.18,
+ color: colors[0]
+ }, {
+ type: 'box',
+ x: 1200,
+ y: 800,
+ w: 1100,
+ h: 700,
+ rot: -0.12,
+ alpha: 0.13,
+ color: colors[1]
+ }, {
+ type: 'ellipse',
+ x: 900,
+ y: 1800,
+ w: 900,
+ h: 600,
+ rot: 0.07,
+ alpha: 0.11,
+ color: colors[2]
+ }, {
+ type: 'box',
+ x: 1600,
+ y: 2000,
+ w: 700,
+ h: 900,
+ rot: 0.32,
+ alpha: 0.10,
+ color: colors[3]
+ }, {
+ type: 'ellipse',
+ x: 400,
+ y: 2200,
+ w: 800,
+ h: 500,
+ rot: -0.22,
+ alpha: 0.09,
+ color: colors[4]
+ }];
+ for (var i = 0; i < shapes.length; i++) {
+ var s = shapes[i];
+ var assetId = 'polybg_' + i;
+ // Dynamically create the shape asset if not already present
+ var bgShape = LK.getAsset(assetId, {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: s.x,
+ y: s.y,
+ rotation: s.rot,
+ alpha: s.alpha
+ });
+ polyBgShapes.push(bgShape);
+ game.addChild(bgShape);
+ }
+})();
// Add character to center of screen
var character = new Character();
character.x = 2048 / 2;
character.y = 2732 / 2;