User prompt
kaleci topu tutunca ungol çalsın
User prompt
gol atamayınca ungol çalsın
User prompt
gol atınca gol müziği çalsın
User prompt
kalecinin hızını arttır
User prompt
goal in enini büyüt
User prompt
timer i sağa yasla
User prompt
süreyi goal in sağına ekle
User prompt
süreyi sağa yasla
User prompt
score yi sola yasla
User prompt
gol ü sola yasla
User prompt
süreyi sola golü sağa yasla
User prompt
top alandan dışarı çıkmasın
User prompt
Süre 2 dakika olsun.
User prompt
Kaleciden şeker ise topa vurabilelim ve kalenin orada sınır olmasın
User prompt
Top hızlı gitsin.
User prompt
Kaleci daha fazla gol yesin ve köşeye çarpınca yanmasın top kaleye seksin
User prompt
Kalecinin hızını düşür
User prompt
Kaleyi biraz küçült
User prompt
Kaleci gaolin önüne al
User prompt
Süre 1dk olsun
User prompt
Süreyi gol tabiosunun yanına koy
User prompt
Kalecinin arada gol yesin
User prompt
Goal in enini büyüt
Code edit (1 edits merged)
Please save this source code
User prompt
Kaleye Gol!
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Football (Top) class var Ball = Container.expand(function () { var self = Container.call(this); // Attach football asset (ellipse, white) var ballAsset = self.attachAsset('ball', { anchorX: 0.5, anchorY: 0.5 }); // Ball state self.isMoving = false; self.vx = 0; self.vy = 0; // Ball radius for collision self.radius = ballAsset.width / 2; // Ball update: move if in motion self.update = function () { if (self.isMoving) { self.x += self.vx; self.y += self.vy; // Friction self.vx *= 0.98; self.vy *= 0.98; // Stop if slow enough if (Math.abs(self.vx) < 1 && Math.abs(self.vy) < 1) { self.vx = 0; self.vy = 0; self.isMoving = false; } } }; // Reset ball to initial position self.reset = function (x, y) { self.x = x; self.y = y; self.vx = 0; self.vy = 0; self.isMoving = false; }; return self; }); // Goal (Kale) class var Goal = Container.expand(function () { var self = Container.call(this); // Attach goal asset (rectangle, yellow) var goalAsset = self.attachAsset('goal', { anchorX: 0.5, anchorY: 0.5 }); return self; }); // Goalkeeper (Kaleci) class var Goalkeeper = Container.expand(function () { var self = Container.call(this); // Attach goalkeeper asset (rectangle, blue) var keeperAsset = self.attachAsset('goalkeeper', { anchorX: 0.5, anchorY: 0.5 }); // Movement bounds self.minX = 0; self.maxX = 2048; self.y = 420; // Just in front of goal // Speed self.speed = 9; // Reduced speed for slower goalkeeper // Target x (where to move) self.targetX = 1024; // Update: move towards targetX self.update = function () { if (Math.abs(self.x - self.targetX) > self.speed) { if (self.x < self.targetX) { self.x += self.speed; } else { self.x -= self.speed; } } else { self.x = self.targetX; } // Clamp if (self.x < self.minX + keeperAsset.width / 2) self.x = self.minX + keeperAsset.width / 2; if (self.x > self.maxX - keeperAsset.width / 2) self.x = self.maxX - keeperAsset.width / 2; }; // Set target x self.moveTo = function (x) { self.targetX = x; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x1a8f3c // Green football field }); /**** * Game Code ****/ // --- Game Variables --- // --- Asset Initialization --- var score = 0; var maxGoals = 5; var timeLimit = 60; // seconds (1 minute) var timeLeft = timeLimit; var dragging = false; var dragStart = { x: 0, y: 0 }; var dragBallStart = { x: 0, y: 0 }; var shotInProgress = false; var lastGoal = false; var gameEnded = false; // --- Create Game Elements --- // Goal var goal = new Goal(); goal.x = 1024; goal.y = 200; game.addChild(goal); // Goalkeeper var goalkeeper = new Goalkeeper(); goalkeeper.x = 1024; // Place goalkeeper just in front of the goal (align y with goal's bottom edge) goalkeeper.y = goal.y + goal.children[0].height / 2 + goalkeeper.children[0].height / 2 - 10; game.addChild(goalkeeper); // Ball var ball = new Ball(); ball.reset(1024, 2000); game.addChild(ball); // --- Score Display --- var scoreTxt = new Text2('Gol: 0', { size: 120, fill: 0xFFF700 }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // --- Timer Display --- var timerTxt = new Text2('Süre: ' + timeLeft, { size: 90, fill: 0xFFFFFF }); timerTxt.anchor.set(0, 0); // Anchor left-top for easier positioning next to score // Place timer next to score display // Wait for scoreTxt.width to be available (should be after creation) timerTxt.x = scoreTxt.x + scoreTxt.width / 2 + 40; // 40px gap to the right of score timerTxt.y = scoreTxt.y + 20; // Slightly lower for visual alignment LK.gui.top.addChild(timerTxt); // --- Helper: Check if ball is in goal --- function isGoal(ball) { // Ball must cross the goal line (y < goal.y + goal height/2) // and x within goal width var goalTop = goal.y - goal.children[0].height / 2; var goalLeft = goal.x - goal.children[0].width / 2; var goalRight = goal.x + goal.children[0].width / 2; return ball.y - ball.radius < goalTop && ball.x > goalLeft && ball.x < goalRight; } // --- Helper: Check collision with goalkeeper --- function isSaved(ball, goalkeeper) { // Simple AABB collision var keeper = goalkeeper.children[0]; var keeperLeft = goalkeeper.x - keeper.width / 2; var keeperRight = goalkeeper.x + keeper.width / 2; var keeperTop = goalkeeper.y - keeper.height / 2; var keeperBottom = goalkeeper.y + keeper.height / 2; var ballLeft = ball.x - ball.radius; var ballRight = ball.x + ball.radius; var ballTop = ball.y - ball.radius; var ballBottom = ball.y + ball.radius; return ballRight > keeperLeft && ballLeft < keeperRight && ballBottom > keeperTop && ballTop < keeperBottom; } // --- Helper: Reset ball position --- function resetBall() { ball.reset(1024, 2000); dragging = false; shotInProgress = false; } // --- Helper: End Game --- function endGame(win) { gameEnded = true; if (win) { LK.showYouWin(); } else { LK.showGameOver(); } } // --- Timer --- var timerInterval = LK.setInterval(function () { if (gameEnded) return; timeLeft--; if (timeLeft < 0) timeLeft = 0; timerTxt.setText('Süre: ' + timeLeft); if (timeLeft === 0) { endGame(false); LK.clearInterval(timerInterval); } }, 1000); // --- Drag & Shoot Mechanics --- game.down = function (x, y, obj) { if (gameEnded) return; // Only allow drag if ball is not moving and touch is on ball var dx = x - ball.x; var dy = y - ball.y; if (!ball.isMoving && dx * dx + dy * dy < ball.radius * ball.radius * 1.2) { dragging = true; dragStart.x = x; dragStart.y = y; dragBallStart.x = ball.x; dragBallStart.y = ball.y; } }; game.move = function (x, y, obj) { if (gameEnded) return; if (dragging && !ball.isMoving) { // Move ball with finger, but clamp to a region var nx = dragBallStart.x + (x - dragStart.x); var ny = dragBallStart.y + (y - dragStart.y); // Clamp to lower half of field if (ny > 2400) ny = 2400; if (ny < 1200) ny = 1200; if (nx < 200) nx = 200; if (nx > 1848) nx = 1848; ball.x = nx; ball.y = ny; } }; game.up = function (x, y, obj) { if (gameEnded) return; if (dragging && !ball.isMoving) { // Calculate velocity based on drag var dx = dragStart.x - x; var dy = dragStart.y - y; // Only shoot if drag is upwards and long enough if (dy > 80) { // Normalize and scale var power = Math.sqrt(dx * dx + dy * dy); var maxPower = 1200; if (power > maxPower) power = maxPower; var scale = 64 * (power / maxPower); // Increased from 32 to 64 for higher speed ball.vx = -dx / power * scale; ball.vy = -dy / power * scale; ball.isMoving = true; shotInProgress = true; } } dragging = false; }; // --- Main Game Update --- game.update = function () { if (gameEnded) return; // Ball update ball.update(); // Goalkeeper AI: track ball if shot in progress, else random idle if (shotInProgress && ball.isMoving) { // Predict where ball will cross keeper's y var t = (goalkeeper.y - ball.y) / ball.vy; var predictedX = ball.x + ball.vx * t; if (t > 0 && t < 60) { goalkeeper.moveTo(predictedX); } } else { // Idle: move to center slowly goalkeeper.moveTo(1024); } goalkeeper.update(); // Check for goal or save if (shotInProgress && ball.isMoving) { // Save // Kalecinin bazen topu kaçırması için rastgele bir şans ekle var keeperSaveChance = 0.35; // %35 ihtimalle kurtarır, %65 gol olur if (isSaved(ball, goalkeeper) && Math.random() < keeperSaveChance) { shotInProgress = false; // Flash keeper LK.effects.flashObject(goalkeeper, 0x00ffff, 400); // Ball bounces back ball.vy = Math.abs(ball.vy) * 0.5; ball.vx = ball.vx * 0.5; ball.isMoving = true; // After bounce, reset after short delay LK.setTimeout(function () { resetBall(); }, 700); } // Goal else if (isGoal(ball)) { shotInProgress = false; score++; scoreTxt.setText('Gol: ' + score); LK.effects.flashScreen(0x00ff00, 400); // Animate ball into net tween(ball, { y: goal.y - 80 }, { duration: 250, easing: tween.cubicOut, onFinish: function onFinish() { resetBall(); } }); // Win condition if (score >= maxGoals) { endGame(true); LK.clearInterval(timerInterval); } } // Yan duvarlara çarpınca top seksin, dışarı çıkmasın else if (ball.x - ball.radius < 0) { ball.x = ball.radius; ball.vx = -ball.vx * 0.7; // Damping for realism // Top köşeden kaleye yönlendirilsin if (ball.y < goal.y + goal.children[0].height / 2 + 40) { // Top üst köşede ise, kaleye doğru yönlendir ball.vy = -Math.abs(ball.vy) * 0.8; ball.vx = Math.abs(ball.vx) * 0.7; } } else if (ball.x + ball.radius > 2048) { ball.x = 2048 - ball.radius; ball.vx = -ball.vx * 0.7; if (ball.y < goal.y + goal.children[0].height / 2 + 40) { ball.vy = -Math.abs(ball.vy) * 0.8; ball.vx = -Math.abs(ball.vx) * 0.7; } } else if (ball.y < 0 || ball.y > 2732) { // Sadece üstten veya alttan dışarı çıkarsa resetle shotInProgress = false; LK.effects.flashScreen(0xff0000, 400); resetBall(); } } }; // --- Playfield layout notes --- // Goal: y = 200 // Goalkeeper: y = 310 // Ball: y = 2000 (start) // All elements centered horizontally // --- Music, sound, etc. are omitted as per guidelines ---
===================================================================
--- original.js
+++ change.js
@@ -245,9 +245,9 @@
// Normalize and scale
var power = Math.sqrt(dx * dx + dy * dy);
var maxPower = 1200;
if (power > maxPower) power = maxPower;
- var scale = 32 * (power / maxPower);
+ var scale = 64 * (power / maxPower); // Increased from 32 to 64 for higher speed
ball.vx = -dx / power * scale;
ball.vy = -dy / power * scale;
ball.isMoving = true;
shotInProgress = true;