User prompt
Red teams control the ai
User prompt
When player touch ball ball start moving and 2 players can move
User prompt
Player can touch ball
User prompt
Player move is normally and can be touch ball but players cant go other Side
User prompt
Make player can move
User prompt
Make goal like real life
User prompt
Make field blue
User prompt
Make field color blue
User prompt
Make 2 teams left color is blue,right color is red
User prompt
Restart
User prompt
Reset all
User prompt
Do medium goal
User prompt
Make a goal
User prompt
Make a goal white
User prompt
Not 1 side do 2 side
User prompt
Make a goal color white and slim
User prompt
Remove in front of goal
User prompt
Gets line is slım and get a futsal ball
User prompt
Make a real futsal court
User prompt
Do futsal court
User prompt
Make Me game look like haxball
Code edit (1 edits merged)
Please save this source code
User prompt
Mini Haxball Arena
Initial prompt
Make Me game look like haxball
/**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x1976d2 // Blue field background }); /**** * Game Code ****/ // Enable dragging for the blue player var draggingPlayer = null; // Convert global (event) coordinates to local game coordinates function toGameCoords(x, y) { // LK events provide coordinates in game space already return { x: x, y: y }; } // Handle touch/mouse down: start dragging if on player game.down = function (x, y, obj) { // Check if the down event is on the blue player var dx = x - player.x; var dy = y - player.y; var r = player.width / 2; if (dx * dx + dy * dy <= r * r) { draggingPlayer = player; } // No-op: Remove red player drag logic, opponent is now AI controlled }; // Handle touch/mouse move: move player if dragging game.move = function (x, y, obj) { if (draggingPlayer) { // Blue player (left side) - only blue player can be dragged if (draggingPlayer === player) { var minX = field.x - field.width / 2 + player.width / 2; var maxX = field.x; // Center line is the max for left player var minY = field.y - field.height / 2 + player.height / 2; var maxY = field.y + field.height / 2 - player.height / 2; draggingPlayer.x = Math.max(minX, Math.min(maxX - player.width / 2, x)); draggingPlayer.y = Math.max(minY, Math.min(maxY, y)); } } // Remove red player drag logic: opponent is now AI controlled }; // Handle touch/mouse up: stop dragging game.up = function (x, y, obj) { draggingPlayer = null; }; ; ; // Track last intersection state between player and ball var lastPlayerBallIntersecting = false; // Update loop to check for player touching ball game.update = function () { // --- AI for red opponent --- if (typeof opponent.aiTargetX === "undefined") { opponent.aiTargetX = opponent.x; opponent.aiTargetY = opponent.y; } // Simple AI: move toward the ball, but stay on right half var aiSpeed = 18; var minX2 = field.x; // Center line is the min for right player var maxX2 = field.x + field.width / 2 - opponent.width / 2; var minY2 = field.y - field.height / 2 + opponent.height / 2; var maxY2 = field.y + field.height / 2 - opponent.height / 2; // Target: follow ball, but clamp to right half opponent.aiTargetX = Math.max(minX2 + opponent.width / 2, Math.min(maxX2, ball.x)); opponent.aiTargetY = Math.max(minY2, Math.min(maxY2, ball.y)); // Move opponent toward target var odx = opponent.aiTargetX - opponent.x; var ody = opponent.aiTargetY - opponent.y; var odist = Math.sqrt(odx * odx + ody * ody) || 1; if (odist > 1) { opponent.x += odx / odist * Math.min(aiSpeed, odist); opponent.y += ody / odist * Math.min(aiSpeed, odist); } // Check if player is touching the ball (collision/intersection) var isIntersecting = player.intersects(ball); // Detect the exact moment player starts touching the ball if (!lastPlayerBallIntersecting && isIntersecting) { // Calculate direction from player to ball var dx = ball.x - player.x; var dy = ball.y - player.y; var dist = Math.sqrt(dx * dx + dy * dy) || 1; // Give the ball a velocity away from the player ball.vx = dx / dist * 30; ball.vy = dy / dist * 30; LK.effects.flashObject(ball, 0x1976d2, 200); } // AI: Red player can also kick the ball if touching if (opponent.intersects(ball)) { var dxr = ball.x - opponent.x; var dyr = ball.y - opponent.y; var distr = Math.sqrt(dxr * dxr + dyr * dyr) || 1; // Give the ball a velocity away from the red player ball.vx = dxr / distr * 30; ball.vy = dyr / distr * 30; LK.effects.flashObject(ball, 0xd32f2f, 200); } // Move the ball if it has velocity if (typeof ball.vx === "number" && typeof ball.vy === "number") { ball.x += ball.vx; ball.y += ball.vy; // Friction ball.vx *= 0.96; ball.vy *= 0.96; // Clamp to field bounds var minBallX = field.x - field.width / 2 + ball.width / 2; var maxBallX = field.x + field.width / 2 - ball.width / 2; var minBallY = field.y - field.height / 2 + ball.height / 2; var maxBallY = field.y + field.height / 2 - ball.height / 2; if (ball.x < minBallX) { ball.x = minBallX; ball.vx *= -0.5; } if (ball.x > maxBallX) { ball.x = maxBallX; ball.vx *= -0.5; } if (ball.y < minBallY) { ball.y = minBallY; ball.vy *= -0.5; } if (ball.y > maxBallY) { ball.y = maxBallY; ball.vy *= -0.5; } // Stop if very slow if (Math.abs(ball.vx) < 0.2) ball.vx = 0; if (Math.abs(ball.vy) < 0.2) ball.vy = 0; } // Update last intersection state lastPlayerBallIntersecting = isIntersecting; }; // Futsal ball (white) // Center circle (white, ellipse) // Center line (white, box) // Main field (futsal green) // Goal area (penalty box, white) // Goal (yellow, box) // Player (blue, ellipse) var field = LK.getAsset('field', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2 }); game.addChild(field); // Draw center line var centerLine = LK.getAsset('centerLine', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2 }); game.addChild(centerLine); // Draw center circle var centerCircle = LK.getAsset('centerCircle', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2 }); game.addChild(centerCircle); // Draw left goal (real-life: tall, slim, at field edge, centered vertically) var leftGoal = LK.getAsset('goal', { anchorX: 0.5, // center anchor for easier placement anchorY: 0.5, width: 40, // slim width height: 400, // tall height x: (2048 - 1900) / 2 + 20, // flush with left field edge y: 2732 / 2 }); game.addChild(leftGoal); // Draw right goal (real-life: tall, slim, at field edge, centered vertically) var rightGoal = LK.getAsset('goal', { anchorX: 0.5, anchorY: 0.5, width: 40, height: 400, x: (2048 + 1900) / 2 - 20, // flush with right field edge y: 2732 / 2 }); game.addChild(rightGoal); // Draw ball at center var ball = LK.getAsset('ball', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2 }); game.addChild(ball); // Draw player at left side (blue) var player = LK.getAsset('playerBlue', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2 - 500, y: 2732 / 2 }); game.addChild(player); // Draw opponent at right side (red) var opponent = LK.getAsset('playerRed', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2 + 500, y: 2732 / 2 }); game.addChild(opponent); ;
===================================================================
--- original.js
+++ change.js
@@ -26,38 +26,24 @@
var r = player.width / 2;
if (dx * dx + dy * dy <= r * r) {
draggingPlayer = player;
}
- // Check if the down event is on the red opponent
- var dx2 = x - opponent.x;
- var dy2 = y - opponent.y;
- var r2 = opponent.width / 2;
- if (dx2 * dx2 + dy2 * dy2 <= r2 * r2) {
- draggingPlayer = opponent;
- }
+ // No-op: Remove red player drag logic, opponent is now AI controlled
};
// Handle touch/mouse move: move player if dragging
game.move = function (x, y, obj) {
if (draggingPlayer) {
- // Blue player (left side)
+ // Blue player (left side) - only blue player can be dragged
if (draggingPlayer === player) {
var minX = field.x - field.width / 2 + player.width / 2;
var maxX = field.x; // Center line is the max for left player
var minY = field.y - field.height / 2 + player.height / 2;
var maxY = field.y + field.height / 2 - player.height / 2;
draggingPlayer.x = Math.max(minX, Math.min(maxX - player.width / 2, x));
draggingPlayer.y = Math.max(minY, Math.min(maxY, y));
}
- // Red opponent (right side)
- if (draggingPlayer === opponent) {
- var minX2 = field.x; // Center line is the min for right player
- var maxX2 = field.x + field.width / 2 - opponent.width / 2;
- var minY2 = field.y - field.height / 2 + opponent.height / 2;
- var maxY2 = field.y + field.height / 2 - opponent.height / 2;
- draggingPlayer.x = Math.max(minX2 + opponent.width / 2, Math.min(maxX2, x));
- draggingPlayer.y = Math.max(minY2, Math.min(maxY2, y));
- }
}
+ // Remove red player drag logic: opponent is now AI controlled
};
// Handle touch/mouse up: stop dragging
game.up = function (x, y, obj) {
draggingPlayer = null;
@@ -67,8 +53,30 @@
// Track last intersection state between player and ball
var lastPlayerBallIntersecting = false;
// Update loop to check for player touching ball
game.update = function () {
+ // --- AI for red opponent ---
+ if (typeof opponent.aiTargetX === "undefined") {
+ opponent.aiTargetX = opponent.x;
+ opponent.aiTargetY = opponent.y;
+ }
+ // Simple AI: move toward the ball, but stay on right half
+ var aiSpeed = 18;
+ var minX2 = field.x; // Center line is the min for right player
+ var maxX2 = field.x + field.width / 2 - opponent.width / 2;
+ var minY2 = field.y - field.height / 2 + opponent.height / 2;
+ var maxY2 = field.y + field.height / 2 - opponent.height / 2;
+ // Target: follow ball, but clamp to right half
+ opponent.aiTargetX = Math.max(minX2 + opponent.width / 2, Math.min(maxX2, ball.x));
+ opponent.aiTargetY = Math.max(minY2, Math.min(maxY2, ball.y));
+ // Move opponent toward target
+ var odx = opponent.aiTargetX - opponent.x;
+ var ody = opponent.aiTargetY - opponent.y;
+ var odist = Math.sqrt(odx * odx + ody * ody) || 1;
+ if (odist > 1) {
+ opponent.x += odx / odist * Math.min(aiSpeed, odist);
+ opponent.y += ody / odist * Math.min(aiSpeed, odist);
+ }
// Check if player is touching the ball (collision/intersection)
var isIntersecting = player.intersects(ball);
// Detect the exact moment player starts touching the ball
if (!lastPlayerBallIntersecting && isIntersecting) {
@@ -80,8 +88,18 @@
ball.vx = dx / dist * 30;
ball.vy = dy / dist * 30;
LK.effects.flashObject(ball, 0x1976d2, 200);
}
+ // AI: Red player can also kick the ball if touching
+ if (opponent.intersects(ball)) {
+ var dxr = ball.x - opponent.x;
+ var dyr = ball.y - opponent.y;
+ var distr = Math.sqrt(dxr * dxr + dyr * dyr) || 1;
+ // Give the ball a velocity away from the red player
+ ball.vx = dxr / distr * 30;
+ ball.vy = dyr / distr * 30;
+ LK.effects.flashObject(ball, 0xd32f2f, 200);
+ }
// Move the ball if it has velocity
if (typeof ball.vx === "number" && typeof ball.vy === "number") {
ball.x += ball.vx;
ball.y += ball.vy;