/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Ball = Container.expand(function () { var self = Container.call(this); var ballGraphics = self.attachAsset('ball', { anchorX: 0.5, anchorY: 0.5 }); self.velocityX = 0; self.velocityY = 0; self.gravity = 0.3; self.isMoving = false; self.startX = 0; self.startY = 0; self.reset = function () { self.x = self.startX; self.y = self.startY; self.velocityX = 0; self.velocityY = 0; self.isMoving = false; ballGraphics.alpha = 1; }; self.shoot = function (powerX, powerY) { self.velocityX = powerX * 0.8; self.velocityY = powerY * 0.8; self.isMoving = true; LK.getSound('kick').play(); }; self.update = function () { if (self.isMoving) { self.x += self.velocityX; self.y += self.velocityY; self.velocityY += self.gravity; // Ball physics - slow down over time self.velocityX *= 0.99; } }; return self; }); var Goalkeeper = Container.expand(function () { var self = Container.call(this); var keeperGraphics = self.attachAsset('goalkeeper', { anchorX: 0.5, anchorY: 1 }); self.homeX = 0; self.homeY = 0; self.targetX = 0; self.speed = 3; self.reactionTime = 0; self.isReacting = false; self.setHome = function (x, y) { self.homeX = x; self.homeY = y; self.x = x; self.y = y; self.targetX = x; }; self.reactToBall = function (ballX, ballY) { if (!self.isReacting && self.reactionTime <= 0) { self.isReacting = true; self.reactionTime = 30; // Reaction delay // Predict where ball will be if (ballX < self.homeX - 50) { self.targetX = self.homeX - 150; } else if (ballX > self.homeX + 50) { self.targetX = self.homeX + 150; } } }; self.returnHome = function () { self.targetX = self.homeX; self.isReacting = false; self.reactionTime = 60; // Cooldown before next reaction }; self.update = function () { if (self.reactionTime > 0) { self.reactionTime--; } // Move towards target var dx = self.targetX - self.x; if (Math.abs(dx) > self.speed) { self.x += dx > 0 ? self.speed : -self.speed; } else { self.x = self.targetX; } }; return self; }); var TargetZone = Container.expand(function () { var self = Container.call(this); var zoneGraphics = self.attachAsset('targetZone', { anchorX: 0.5, anchorY: 0.5 }); zoneGraphics.alpha = 0.3; self.points = 1; self.isActive = false; self.activate = function () { self.isActive = true; zoneGraphics.alpha = 0.6; tween(zoneGraphics, { alpha: 0.3 }, { duration: 1000 }); }; self.setPoints = function (points) { self.points = points; if (points > 1) { zoneGraphics.tint = 0xffd700; // Gold for high value zones } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x2E8B57 }); /**** * Game Code ****/ // Game dimensions and positioning var gameWidth = 2048; var gameHeight = 2732; var goalWidth = 600; var goalHeight = 400; var goalX = gameWidth / 2; var goalY = gameHeight * 0.3; // Game state var currentLevel = 1; var streak = 0; var isAiming = false; var isShooting = false; var shotsTaken = 0; var maxShots = 10; // Create goal structure var goalBackground = game.addChild(LK.getAsset('goalBackground', { anchorX: 0.5, anchorY: 0.5, x: goalX, y: goalY })); var leftPost = game.addChild(LK.getAsset('goalPost', { anchorX: 0.5, anchorY: 0.5, x: goalX - goalWidth / 2, y: goalY })); var rightPost = game.addChild(LK.getAsset('goalPost', { anchorX: 0.5, anchorY: 0.5, x: goalX + goalWidth / 2, y: goalY })); var crossbar = game.addChild(LK.getAsset('goalCrossbar', { anchorX: 0.5, anchorY: 0.5, x: goalX, y: goalY - goalHeight / 2 })); // Create ball var ball = game.addChild(new Ball()); ball.startX = gameWidth / 2; ball.startY = gameHeight * 0.8; ball.reset(); // Create goalkeeper var goalkeeper = game.addChild(new Goalkeeper()); goalkeeper.setHome(goalX, goalY + goalHeight / 2 - 20); // Create target zones var targetZones = []; var zonePositions = [{ x: goalX - 200, y: goalY - 100, points: 3 }, // Top left corner { x: goalX + 200, y: goalY - 100, points: 3 }, // Top right corner { x: goalX - 200, y: goalY + 100, points: 2 }, // Bottom left { x: goalX + 200, y: goalY + 100, points: 2 }, // Bottom right { x: goalX, y: goalY, points: 1 } // Center ]; for (var i = 0; i < zonePositions.length; i++) { var zone = game.addChild(new TargetZone()); zone.x = zonePositions[i].x; zone.y = zonePositions[i].y; zone.setPoints(zonePositions[i].points); targetZones.push(zone); } // Aim line for visualization var aimLine = game.addChild(LK.getAsset('aimLine', { anchorX: 0.5, anchorY: 0, alpha: 0 })); // UI Elements var scoreTxt = new Text2('Score: 0', { size: 80, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); var shotsTxt = new Text2('Shots: 10', { size: 60, fill: 0xFFFFFF }); shotsTxt.anchor.set(1, 0); LK.gui.topRight.addChild(shotsTxt); var levelTxt = new Text2('Level: 1', { size: 60, fill: 0xFFFFFF }); levelTxt.anchor.set(0, 0); LK.gui.topLeft.addChild(levelTxt); // Game variables var dragStartX = 0; var dragStartY = 0; var isDragging = false; function resetShot() { ball.reset(); goalkeeper.returnHome(); isShooting = false; isAiming = false; aimLine.alpha = 0; // Activate random target zone var randomZone = targetZones[Math.floor(Math.random() * targetZones.length)]; randomZone.activate(); } function checkGoal() { // Check if ball is in goal area if (ball.x > goalX - goalWidth / 2 && ball.x < goalX + goalWidth / 2 && ball.y > goalY - goalHeight / 2 && ball.y < goalY + goalHeight / 2) { // Check which target zone was hit for (var i = 0; i < targetZones.length; i++) { var zone = targetZones[i]; if (zone.isActive && ball.intersects(zone)) { LK.setScore(LK.getScore() + zone.points); scoreTxt.setText('Score: ' + LK.getScore()); streak++; LK.getSound('goal').play(); LK.effects.flashScreen(0x00ff00, 500); LK.setTimeout(function () { nextShot(); }, 1000); return true; } } // Goal but missed target zone LK.setScore(LK.getScore() + 1); scoreTxt.setText('Score: ' + LK.getScore()); streak++; LK.getSound('goal').play(); LK.setTimeout(function () { nextShot(); }, 1000); return true; } // Check if goalkeeper saved if (ball.intersects(goalkeeper)) { streak = 0; LK.getSound('save').play(); LK.effects.flashObject(goalkeeper, 0x00ff00, 500); LK.setTimeout(function () { nextShot(); }, 1000); return true; } return false; } function nextShot() { shotsTaken++; shotsTxt.setText('Shots: ' + (maxShots - shotsTaken)); if (shotsTaken >= maxShots) { if (LK.getScore() >= currentLevel * 15) { currentLevel++; levelTxt.setText('Level: ' + currentLevel); shotsTaken = 0; // Increase difficulty goalkeeper.speed = Math.min(goalkeeper.speed + 0.5, 8); } else { LK.showGameOver(); return; } } resetShot(); } // Touch/Mouse controls game.down = function (x, y, obj) { if (!isShooting && !isAiming) { isAiming = true; isDragging = true; dragStartX = x; dragStartY = y; aimLine.x = ball.x; aimLine.y = ball.y; aimLine.alpha = 0.7; } }; game.move = function (x, y, obj) { if (isDragging && isAiming) { var dx = x - dragStartX; var dy = y - dragStartY; var distance = Math.sqrt(dx * dx + dy * dy); var maxDistance = 300; if (distance > maxDistance) { dx = dx / distance * maxDistance; dy = dy / distance * maxDistance; } // Update aim line aimLine.rotation = Math.atan2(dy, dx) + Math.PI / 2; aimLine.height = Math.min(distance, maxDistance); } }; game.up = function (x, y, obj) { if (isDragging && isAiming) { isDragging = false; isAiming = false; isShooting = true; aimLine.alpha = 0; var dx = x - dragStartX; var dy = y - dragStartY; var distance = Math.sqrt(dx * dx + dy * dy); var power = Math.min(distance / 10, 20); ball.shoot(dx / 10, dy / 10); goalkeeper.reactToBall(ball.x + dx, ball.y + dy); } }; // Game update loop game.update = function () { if (isShooting && ball.isMoving) { // Check if ball went out of bounds if (ball.y < goalY - goalHeight / 2 - 100 || ball.x < 0 || ball.x > gameWidth || ball.y > gameHeight) { ball.isMoving = false; isShooting = false; streak = 0; LK.setTimeout(function () { nextShot(); }, 500); return; } // Check for goal or save if (checkGoal()) { ball.isMoving = false; isShooting = false; return; } } }; // Initialize first shot resetShot();
===================================================================
--- original.js
+++ change.js
@@ -266,9 +266,9 @@
scoreTxt.setText('Score: ' + LK.getScore());
streak++;
LK.getSound('goal').play();
LK.effects.flashScreen(0x00ff00, 500);
- setTimeout(function () {
+ LK.setTimeout(function () {
nextShot();
}, 1000);
return true;
}
@@ -277,9 +277,9 @@
LK.setScore(LK.getScore() + 1);
scoreTxt.setText('Score: ' + LK.getScore());
streak++;
LK.getSound('goal').play();
- setTimeout(function () {
+ LK.setTimeout(function () {
nextShot();
}, 1000);
return true;
}
@@ -287,9 +287,9 @@
if (ball.intersects(goalkeeper)) {
streak = 0;
LK.getSound('save').play();
LK.effects.flashObject(goalkeeper, 0x00ff00, 500);
- setTimeout(function () {
+ LK.setTimeout(function () {
nextShot();
}, 1000);
return true;
}
@@ -354,19 +354,23 @@
}
};
// Game update loop
game.update = function () {
- if (isShooting) {
+ if (isShooting && ball.isMoving) {
// Check if ball went out of bounds
if (ball.y < goalY - goalHeight / 2 - 100 || ball.x < 0 || ball.x > gameWidth || ball.y > gameHeight) {
+ ball.isMoving = false;
+ isShooting = false;
streak = 0;
- setTimeout(function () {
+ LK.setTimeout(function () {
nextShot();
}, 500);
return;
}
// Check for goal or save
if (checkGoal()) {
+ ball.isMoving = false;
+ isShooting = false;
return;
}
}
};
ball. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
courtuis. In-Game asset. High contrast. No shadows. goalkeeper . full body . facing forward
kalp. In-Game asset. 2d. High contrast. No shadows
full body ronnaldo. In-Game asset. 2d. High contrast. No shadows. top olmasın. turned away. no ball