User prompt
Make a group scoreboard and goals text
User prompt
Add and show 1 point to scoreboard when ball touches either goal net
User prompt
Do scoreboard a asset
User prompt
When ball touch score goal add 1 point on the scoreboard
User prompt
Show goal count on the scoreboard
User prompt
Add 1 point on the scoreboard when ball touch goal net
User prompt
Add 1 point the right on the scoreboard when ball touch the up side goal
User prompt
If the joystick on the down move the ball down side
User prompt
Count the goal count when ball touches up net on the map add 1 point on the right scoreboard
User prompt
Count the goal amount and add 1 point left side of the scoreboard
User prompt
Count the goal amount
User prompt
Allow the ball can go down of the footballer
User prompt
Make the footballer can shot the downside of the map
User prompt
Make a football map
User prompt
Add 1 point only when ball touch the net without footballer
User prompt
Footballer can shot and pass down side of the map
User prompt
Fix the bug
User prompt
Please fix the bug: 'ReferenceError: obj is not defined' in or related to this line: 'if (obj && obj.event && obj.event.type === "down") {' Line Number: 287
User prompt
Add 1 point the right scoreboard when only touch the ball without the footballer
User prompt
Make the footballer with the ball can move down
User prompt
Make the ball move down
User prompt
When the ball touches the goal add 1 point for the right scoreboard
User prompt
Make the ball move right and left
User prompt
Make the ball seperate from footballer
User prompt
If the ball touches the soccer goal add scoreboard 1 goal count
/**** * Classes ****/ // Ball class var Ball = Container.expand(function () { var self = Container.call(this); var gfx = self.attachAsset('ball', { anchorX: 0.5, anchorY: 0.5 }); self.radius = gfx.width * 0.5; self.vx = 0; self.vy = 0; self.update = function () { // Ball moves down by default if (self.vy === 0) { self.vy = 8; } self.x += self.vx; self.y += self.vy; // Friction self.vx *= 0.96; self.vy *= 0.96; // Clamp to field if (self.x < 100 + self.radius) { self.x = 100 + self.radius; } if (self.x > 2048 - 100 - self.radius) { self.x = 2048 - 100 - self.radius; } if (self.y < 200 + self.radius) { self.y = 200 + self.radius; } if (self.y > 2732 - 200 - self.radius) { self.y = 2732 - 200 - self.radius; } }; return self; }); // --- UI: Joystick and Buttons --- // Joystick // --- FOOTBALL GAME MAIN OBJECTS --- // Footballer class var Footballer = Container.expand(function () { var self = Container.call(this); var gfx = self.attachAsset('footballer', { anchorX: 0.5, anchorY: 0.5 }); self.radius = gfx.width * 0.5; self.hasBall = true; self.update = function () {}; return self; }); // Soccer Goal class var SoccerGoal = Container.expand(function () { var self = Container.call(this); // width: 400px, height: 40px, color: white, box var gfx = self.attachAsset('centerCircle', { width: 400, height: 40, color: 0xffffff, anchorX: 0.5, anchorY: 0.5 }); self.width = 400; self.height = 40; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ // Draw green field background // --- FOOTBALL FIELD MAP --- var fieldBg = LK.getAsset('centerCircle', { width: 2048 - 200, height: 2732 - 400, color: 0x2e8b57, anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2 }); game.addChildAt(fieldBg, 0); // Draw center line var centerLine = LK.getAsset('centerCircle', { width: 2048 - 200, height: 16, color: 0xffffff, anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2 }); game.addChild(centerLine); // Draw center circle var centerCircle = LK.getAsset('centerCircle', { width: 400, height: 400, color: 0xffffff, anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2 }); centerCircle.alpha = 0.25; game.addChild(centerCircle); // Draw penalty boxes (top and bottom) var penaltyBoxTop = LK.getAsset('centerCircle', { width: 800, height: 180, color: 0xffffff, anchorX: 0.5, anchorY: 0, x: 2048 / 2, y: 120 }); penaltyBoxTop.alpha = 0.18; game.addChild(penaltyBoxTop); var penaltyBoxBottom = LK.getAsset('centerCircle', { width: 800, height: 180, color: 0xffffff, anchorX: 0.5, anchorY: 1, x: 2048 / 2, y: 2732 - 120 }); penaltyBoxBottom.alpha = 0.18; game.addChild(penaltyBoxBottom); // --- UI: Joystick and Buttons --- // Joystick var joystick = LK.gui.bottomLeft.addChild(LK.getAsset('joystick_base', { anchorX: 0.5, anchorY: 0.5, x: 220, y: -220, scaleX: 2, scaleY: 2 })); var joystickKnob = LK.gui.bottomLeft.addChild(LK.getAsset('joystick_knob', { anchorX: 0.5, anchorY: 0.5, x: 220, y: -220, scaleX: 1.2, scaleY: 1.2 })); var joystickActive = false; var joystickStart = { x: 0, y: 0 }; var joystickDir = { x: 0, y: 0 }; // Pass Button var passBtn = LK.gui.bottomRight.addChild(LK.getAsset('pass_btn', { anchorX: 0.5, anchorY: 0.5, x: -220, y: -320, scaleX: 2, scaleY: 2 })); // Shoot Button var shootBtn = LK.gui.bottomRight.addChild(LK.getAsset('shoot_btn', { anchorX: 0.5, anchorY: 0.5, x: -220, y: -120, scaleX: 2, scaleY: 2 })); // --- GAME OBJECTS --- // Left Goal (bottom) var leftGoal = new SoccerGoal(); leftGoal.x = 2048 / 2; leftGoal.y = 2732 - 120; game.addChild(leftGoal); // Right Goal (top) var rightGoal = new SoccerGoal(); rightGoal.x = 2048 / 2; rightGoal.y = 120; game.addChild(rightGoal); var footballer = new Footballer(); footballer.x = 2048 / 2; footballer.y = 2732 - 500; game.addChild(footballer); var ball = new Ball(); ball.x = footballer.x; ball.y = footballer.y - footballer.radius - 40; game.addChild(ball); // --- GAME STATE --- var canShoot = true; var canPass = true; // --- SCOREBOARD --- var leftScore = 0; var rightScore = 0; var scoreTxt = new Text2('0 : 0', { size: 120, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); function updateScoreboard() { scoreTxt.setText(leftScore + " : " + rightScore); } updateScoreboard(); // --- JOYSTICK EVENTS --- joystickKnob.down = function (x, y, obj) { joystickActive = true; joystickStart.x = x; joystickStart.y = y; }; joystickKnob.up = function (x, y, obj) { joystickActive = false; joystickKnob.x = joystick.x; joystickKnob.y = joystick.y; joystickDir.x = 0; joystickDir.y = 0; }; joystickKnob.move = function (x, y, obj) { if (!joystickActive) { return; } var dx = x - joystick.x; var dy = y - joystick.y; var dist = Math.sqrt(dx * dx + dy * dy); var maxDist = 120; if (dist > maxDist) { dx = dx * maxDist / dist; dy = dy * maxDist / dist; } joystickKnob.x = joystick.x + dx; joystickKnob.y = joystick.y + dy; joystickDir.x = dx / maxDist; joystickDir.y = dy / maxDist; }; // --- BUTTON EVENTS --- passBtn.down = function (x, y, obj) { if (footballer.hasBall && canPass) { // Pass: direction depends on joystick var passSpeed = 40; var dirY = joystickDir.y; // If joystick is pushed down, pass down, else pass up if (dirY > 0.5) { ball.vx = 0; ball.vy = passSpeed; } else { ball.vx = 0; ball.vy = -passSpeed; } footballer.hasBall = false; canPass = false; LK.setTimeout(function () { canPass = true; }, 400); } }; shootBtn.down = function (x, y, obj) { if (footballer.hasBall && canShoot) { // Shoot: direction depends on joystick var shootSpeed = 80; var dirY = joystickDir.y; // If joystick is pushed down, shoot down, else shoot up if (dirY > 0.5) { ball.vx = 0; ball.vy = shootSpeed; } else if (dirY < -0.5) { ball.vx = 0; ball.vy = -shootSpeed; } else { // If joystick is not pushed up or down, shoot forward (up by default) ball.vx = 0; ball.vy = -shootSpeed; } footballer.hasBall = false; canShoot = false; LK.setTimeout(function () { canShoot = true; }, 800); } }; // --- GAME MOVE HANDLER --- game.move = function (x, y, obj) { // Track last move position for touch detection game.lastMoveX = x; game.lastMoveY = y; // Forward joystick events if (joystickActive) { joystickKnob.move(x, y, obj); } }; // --- GAME UPDATE --- game.update = function () { // Move footballer with joystick if (joystickDir.x !== 0 || joystickDir.y !== 0) { var speed = 18; footballer.x += joystickDir.x * speed; footballer.y += joystickDir.y * speed; // Clamp to field if (footballer.x < 100 + footballer.radius) { footballer.x = 100 + footballer.radius; } if (footballer.x > 2048 - 100 - footballer.radius) { footballer.x = 2048 - 100 - footballer.radius; } if (footballer.y < 200 + footballer.radius) { footballer.y = 200 + footballer.radius; } if (footballer.y > 2732 - 200 - footballer.radius) { footballer.y = 2732 - 200 - footballer.radius; } } // Ball always moves independently // If footballer does NOT have the ball, ball moves by its own update if (!footballer.hasBall) { ball.update(); } else { // If footballer has the ball, allow left/right and up/down movement of the ball with joystick // Ball can move in front of or below the footballer, depending on joystick direction var offsetX = joystickDir.x * 80; // max 80px left/right var offsetY; if (joystickDir.y > 0.5) { // If joystick is pushed down, let the ball go below the footballer offsetY = -(footballer.radius + 40 + joystickDir.y * 80); ball.x = footballer.x + offsetX; ball.y = footballer.y - offsetY; } else { // Default: ball in front of footballer, allow up/down movement offsetY = footballer.radius + 40 - joystickDir.y * 80; ball.x = footballer.x + offsetX; ball.y = footballer.y - offsetY; } // Ball velocity is zero while attached ball.vx = 0; ball.vy = 0; } // Regain possession if close var dx = footballer.x - ball.x; var dy = footballer.y - ball.y; var dist = Math.sqrt(dx * dx + dy * dy); if (dist < footballer.radius + ball.radius + 20 && !footballer.hasBall) { footballer.hasBall = true; } else if (dist < footballer.radius + ball.radius + 20 && footballer.hasBall === false) { // This block is for clarity, but will never be reached since hasBall is set above. } // --- BALL TOUCH DETECTION (not by footballer) --- if (ball.lastWasTouched === undefined) ball.lastWasTouched = false; var isTouched = false; // Defensive: ignore, as we don't get here from a down event if (!footballer.hasBall) { // Check if the ball is being touched (by a finger, not by footballer) // We use LK.gui or game.move events for touch, but since we don't have a direct event, let's check if the ball is under the last move position // We'll use the last known move position if available if (typeof game.lastMoveX !== "undefined" && typeof game.lastMoveY !== "undefined") { var bx = ball.x, by = ball.y, br = ball.radius; var mx = game.lastMoveX, my = game.lastMoveY; var distTouch = Math.sqrt((bx - mx) * (bx - mx) + (by - my) * (by - my)); if (distTouch < br) { isTouched = true; } } } if (!ball.lastWasTouched && isTouched) { // Only add point if footballer does NOT have the ball rightScore += 1; updateScoreboard(); } ball.lastWasTouched = isTouched; // --- GOAL DETECTION --- // Ball enters rightGoal (top) ONLY if footballer does NOT have the ball if (ball.lastY !== undefined && ball.lastY > rightGoal.y && ball.y <= rightGoal.y && Math.abs(ball.x - rightGoal.x) < rightGoal.width * 0.5 && footballer.hasBall === false) { rightScore += 1; updateScoreboard(); // Reset ball and footballer footballer.x = 2048 / 2; footballer.y = 2732 - 500; ball.x = footballer.x; ball.y = footballer.y - footballer.radius - 40; footballer.hasBall = true; ball.vx = 0; ball.vy = 0; } // Add 1 point to right scoreboard when ball touches the up side goal (top edge) if (ball.lastY !== undefined && ball.lastY >= 200 + ball.radius && ball.y < 200 + ball.radius && Math.abs(ball.x - rightGoal.x) < rightGoal.width * 0.5 && footballer.hasBall === false) { rightScore += 1; updateScoreboard(); // Reset ball and footballer footballer.x = 2048 / 2; footballer.y = 2732 - 500; ball.x = footballer.x; ball.y = footballer.y - footballer.radius - 40; footballer.hasBall = true; ball.vx = 0; ball.vy = 0; } // Ball enters leftGoal (bottom) ONLY if footballer does NOT have the ball if (ball.lastY !== undefined && ball.lastY < leftGoal.y && ball.y >= leftGoal.y && Math.abs(ball.x - leftGoal.x) < leftGoal.width * 0.5 && footballer.hasBall === false) { leftScore += 1; // Add 1 point to left side of scoreboard updateScoreboard(); // Reset ball and footballer footballer.x = 2048 / 2; footballer.y = 2732 - 500; ball.x = footballer.x; ball.y = footballer.y - footballer.radius - 40; footballer.hasBall = true; ball.vx = 0; ball.vy = 0; } ball.lastY = ball.y; };
===================================================================
--- original.js
+++ change.js
@@ -394,8 +394,21 @@
footballer.hasBall = true;
ball.vx = 0;
ball.vy = 0;
}
+ // Add 1 point to right scoreboard when ball touches the up side goal (top edge)
+ if (ball.lastY !== undefined && ball.lastY >= 200 + ball.radius && ball.y < 200 + ball.radius && Math.abs(ball.x - rightGoal.x) < rightGoal.width * 0.5 && footballer.hasBall === false) {
+ rightScore += 1;
+ updateScoreboard();
+ // Reset ball and footballer
+ footballer.x = 2048 / 2;
+ footballer.y = 2732 - 500;
+ ball.x = footballer.x;
+ ball.y = footballer.y - footballer.radius - 40;
+ footballer.hasBall = true;
+ ball.vx = 0;
+ ball.vy = 0;
+ }
// Ball enters leftGoal (bottom) ONLY if footballer does NOT have the ball
if (ball.lastY !== undefined && ball.lastY < leftGoal.y && ball.y >= leftGoal.y && Math.abs(ball.x - leftGoal.x) < leftGoal.width * 0.5 && footballer.hasBall === false) {
leftScore += 1; // Add 1 point to left side of scoreboard
updateScoreboard();
Football ball. In-Game asset. 2d. High contrast. No shadows
Cristiano ronaldo. In-Game asset. 2d. High contrast. No shadows
Button with says shoot. In-Game asset. 2d. High contrast. No shadows
A button that says pass. In-Game asset. 2d. High contrast. No shadows
Circle. In-Game asset. 2d. High contrast. No shadows
Little circle. In-Game asset. 2d. High contrast. No shadows