User prompt
Make a scoreboard for the goal count
User prompt
Add 2 mutual soccer goal
Code edit (1 edits merged)
Please save this source code
User prompt
Do it same game again
User prompt
Football Flick: Pass & Shoot
User prompt
Make a football game with shot and pass buttons and add a joystick
Initial prompt
Make a football game
/**** * 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 () { 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; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ // Joystick // --- UI: Joystick and Buttons --- 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 --- 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; // --- 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: simple forward pass ball.vx = 0; ball.vy = -40; footballer.hasBall = false; canPass = false; LK.setTimeout(function () { canPass = true; }, 400); } }; shootBtn.down = function (x, y, obj) { if (footballer.hasBall && canShoot) { // Shoot: strong forward shot ball.vx = 0; ball.vy = -80; footballer.hasBall = false; canShoot = false; LK.setTimeout(function () { canShoot = true; }, 800); } }; // --- GAME MOVE HANDLER --- game.move = function (x, y, obj) { // 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 follows footballer if in possession if (footballer.hasBall) { ball.x = footballer.x; ball.y = footballer.y - footballer.radius - ball.radius - 10; ball.vx = 0; ball.vy = 0; } else { ball.update(); // 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; } } };
===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,200 @@
-/****
+/****
+* 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 () {
+ 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;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
backgroundColor: 0x000000
-});
\ No newline at end of file
+});
+
+/****
+* Game Code
+****/
+// Joystick
+// --- UI: Joystick and Buttons ---
+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 ---
+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;
+// --- 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: simple forward pass
+ ball.vx = 0;
+ ball.vy = -40;
+ footballer.hasBall = false;
+ canPass = false;
+ LK.setTimeout(function () {
+ canPass = true;
+ }, 400);
+ }
+};
+shootBtn.down = function (x, y, obj) {
+ if (footballer.hasBall && canShoot) {
+ // Shoot: strong forward shot
+ ball.vx = 0;
+ ball.vy = -80;
+ footballer.hasBall = false;
+ canShoot = false;
+ LK.setTimeout(function () {
+ canShoot = true;
+ }, 800);
+ }
+};
+// --- GAME MOVE HANDLER ---
+game.move = function (x, y, obj) {
+ // 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 follows footballer if in possession
+ if (footballer.hasBall) {
+ ball.x = footballer.x;
+ ball.y = footballer.y - footballer.radius - ball.radius - 10;
+ ball.vx = 0;
+ ball.vy = 0;
+ } else {
+ ball.update();
+ // 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;
+ }
+ }
+};
\ No newline at end of file
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