User prompt
Make other team slower and faster My teammates
User prompt
More speed. Make there 3 times faster
User prompt
More faster
User prompt
Make My teammates faster
User prompt
İf a bot get the ball he runs to the other teams goal
User prompt
Make other team can come every where of the field
User prompt
Make buttons hold
User prompt
Take up buttons
User prompt
A little bit left move buttons
User prompt
Take buttons some left
User prompt
Re add move buttons but Make in right and take throw button to left
User prompt
Replace buttons with throw button
User prompt
Make buttons bigger and replace with throw button
User prompt
Make buttons for move
User prompt
İf ball follow the Player Make it throwable
User prompt
Player cant Kick the ball
User prompt
Make if Player have the ball and press button Player kicks the ball and Make throw button bigger
User prompt
İ drop the ball Make it undropable
User prompt
Make ı cant drop the ball
User prompt
İ drop the ball every time
User prompt
İ cant see the button
User prompt
I keep the ball. Make a button for throw the ball
User prompt
Player is not stop the ball but if another Player touchs him he takes the ball
User prompt
Other team cant come over the other part of the field
User prompt
Make immunty for everyone and 2 seconds
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Ball = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('ball', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityX = 0;
self.velocityY = 0;
self.friction = 0.95;
self.update = function () {
self.x += self.velocityX;
self.y += self.velocityY;
self.velocityX *= self.friction;
self.velocityY *= self.friction;
// Keep ball on field
if (self.x < 100) {
self.x = 100;
self.velocityX = Math.abs(self.velocityX);
}
if (self.x > 1948) {
self.x = 1948;
self.velocityX = -Math.abs(self.velocityX);
}
if (self.y < 200) {
self.y = 200;
self.velocityY = Math.abs(self.velocityY);
}
if (self.y > 2500) {
self.y = 2500;
self.velocityY = -Math.abs(self.velocityY);
}
};
self.kick = function (targetX, targetY, power) {
var dx = targetX - self.x;
var dy = targetY - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 0) {
self.velocityX = dx / distance * power;
self.velocityY = dy / distance * power;
}
LK.getSound('kick').play();
};
return self;
});
var Opponent = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('opponent', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 2;
self.team = 'opponent';
self.targetX = 0;
self.targetY = 0;
self.update = function () {
var dx = self.targetX - self.x;
var dy = self.targetY - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 5) {
self.x += dx / distance * self.speed;
self.y += dy / distance * self.speed;
}
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.isSelected = false;
self.team = 'player';
self.originalColor = 0x0066cc;
self.select = function () {
self.isSelected = true;
graphics.tint = 0xffff00;
};
self.deselect = function () {
self.isSelected = false;
graphics.tint = self.originalColor;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x228b22
});
/****
* Game Code
****/
// Game field setup
var field = game.addChild(LK.getAsset('field', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
}));
var centerLine = game.addChild(LK.getAsset('centerLine', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
}));
var topGoal = game.addChild(LK.getAsset('goal', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 150,
alpha: 1,
// visible goal
width: 600,
// make hitbox much wider
height: 60 // make hitbox taller
}));
var bottomGoal = game.addChild(LK.getAsset('goal', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 2580,
alpha: 1,
// visible goal
width: 600,
// make hitbox much wider
height: 60 // make hitbox taller
}));
// Game state
var players = [];
var opponents = [];
var selectedPlayer = null;
var isDragging = false;
var dragStartX = 0;
var dragStartY = 0;
var playerScore = 0;
var opponentScore = 0;
var gameTime = 120; // 2 minutes in seconds
var gameStarted = false;
// Ball possession and immunity
var ballHolder = null; // The player or opponent currently holding the ball
var lastBallHolder = null;
var globalImmunityUntil = 0; // Timestamp until which everyone is immune
var IMMUNITY_DURATION = 2000; // ms
// Create ball
var ball = game.addChild(new Ball());
ball.x = 1024;
ball.y = 1366;
// Create player team (bottom half)
for (var i = 0; i < 5; i++) {
var player = game.addChild(new Player());
player.x = 400 + i * 300;
player.y = 1800 + i % 2 * 200;
player._id = "player" + i;
players.push(player);
}
// Create opponent team (top half)
for (var i = 0; i < 5; i++) {
var opponent = game.addChild(new Opponent());
opponent.x = 400 + i * 300;
opponent.y = 900 + i % 2 * 200;
opponent.targetX = opponent.x;
opponent.targetY = opponent.y;
opponent._id = "opponent" + i;
opponents.push(opponent);
}
// UI elements
var scoreText = new Text2('Player: 0 - Opponent: 0', {
size: 60,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
// Only the throw button is used for controls now
var sizeControl = game.addChild(LK.getAsset('ball', {
anchorX: 0.5,
anchorY: 0.5,
x: 1624,
y: 2532,
alpha: 0.5,
scaleX: 2,
scaleY: 2
}));
var timeText = new Text2('2:00', {
size: 50,
fill: 0xFFFFFF
});
timeText.anchor.set(1, 0);
LK.gui.topRight.addChild(timeText);
var instructionText = new Text2('Control any blue player! Tap near a player to select them, then tap where to move. Non-selected players are AI bots. Tap big ball icon to make everything bigger!', {
size: 40,
fill: 0xFFFFFF
});
instructionText.anchor.set(0.5, 1);
LK.gui.bottom.addChild(instructionText);
// --- Move Buttons (Right Side) ---
var moveBtnSize = 180;
var moveBtnAlpha = 0.7;
var moveBtnOffset = 60;
// Up Button
var upBtn = new Text2('▲', {
size: moveBtnSize,
fill: 0xFFFF00,
font: "Impact, Arial Black, Tahoma"
});
upBtn.anchor.set(0.5, 0.5);
upBtn.alpha = moveBtnAlpha;
upBtn.interactive = true;
upBtn.buttonMode = true;
LK.gui.bottomRight.addChild(upBtn);
// Down Button
var downBtn = new Text2('▼', {
size: moveBtnSize,
fill: 0xFFFF00,
font: "Impact, Arial Black, Tahoma"
});
downBtn.anchor.set(0.5, 0.5);
downBtn.alpha = moveBtnAlpha;
downBtn.interactive = true;
downBtn.buttonMode = true;
LK.gui.bottomRight.addChild(downBtn);
// Left Button
var leftBtn = new Text2('◀', {
size: moveBtnSize,
fill: 0xFFFF00,
font: "Impact, Arial Black, Tahoma"
});
leftBtn.anchor.set(0.5, 0.5);
leftBtn.alpha = moveBtnAlpha;
leftBtn.interactive = true;
leftBtn.buttonMode = true;
LK.gui.bottomRight.addChild(leftBtn);
// Right Button
var rightBtn = new Text2('▶', {
size: moveBtnSize,
fill: 0xFFFF00,
font: "Impact, Arial Black, Tahoma"
});
rightBtn.anchor.set(0.5, 0.5);
rightBtn.alpha = moveBtnAlpha;
rightBtn.interactive = true;
rightBtn.buttonMode = true;
LK.gui.bottomRight.addChild(rightBtn);
// Position move buttons relative to each other (bottom right corner)
LK.setTimeout(function () {
// Use LK.gui.bottomRight's width/height for layout
// Move the move buttons a little bit further left by increasing the offset
var leftwardOffset = 320; // Amount to move left (in px) - increased for "a little bit left"
var baseX = LK.gui.bottomRight.width - moveBtnSize - moveBtnOffset - leftwardOffset;
var baseY = LK.gui.bottomRight.height - moveBtnSize - moveBtnOffset;
upBtn.x = baseX + moveBtnSize;
upBtn.y = baseY - moveBtnSize * 0.7;
downBtn.x = baseX + moveBtnSize;
downBtn.y = baseY + moveBtnSize * 0.7;
leftBtn.x = baseX;
leftBtn.y = baseY;
rightBtn.x = baseX + moveBtnSize * 2;
rightBtn.y = baseY;
}, 0);
// --- Throw Button (Left Side) ---
var throwButton = new Text2('THROW', {
size: 160,
fill: 0xFFFF00,
font: "Impact, Arial Black, Tahoma"
});
throwButton.anchor.set(0, 1);
throwButton.interactive = true;
throwButton.buttonMode = true;
LK.gui.bottomLeft.addChild(throwButton);
// Handle throw button tap
throwButton.down = function (x, y, obj) {
// Only allow throw if player is holding the ball
if (ballHolder && ballHolder.team === 'player') {
// Throw the ball towards the top goal (opponent's goal)
ballHolder = null; // Release the ball
// Give a strong upward kick towards the center of the top goal
ball.kick(1024, 150, 15);
}
};
// Move button handlers
upBtn.down = function () {
moveSelectedPlayer(0, -120);
};
downBtn.down = function () {
moveSelectedPlayer(0, 120);
};
leftBtn.down = function () {
moveSelectedPlayer(-120, 0);
};
rightBtn.down = function () {
moveSelectedPlayer(120, 0);
};
// Game timer
var gameTimer = LK.setInterval(function () {
if (gameStarted && gameTime > 0) {
gameTime--;
var minutes = Math.floor(gameTime / 60);
var seconds = gameTime % 60;
timeText.setText(minutes + ':' + (seconds < 10 ? '0' : '') + seconds);
if (gameTime <= 0) {
// Game over
if (playerScore > opponentScore) {
LK.showYouWin();
} else {
LK.showGameOver();
}
LK.clearInterval(gameTimer);
}
}
}, 1000);
// Start game after short delay
LK.setTimeout(function () {
gameStarted = true;
}, 1000);
function updateScore() {
scoreText.setText('Player: ' + playerScore + ' - Opponent: ' + opponentScore);
}
function findClosestPlayer(x, y) {
var closestPlayer = null;
var minDistance = Infinity;
// Check all players to find the closest one
for (var i = 0; i < players.length; i++) {
var player = players[i];
var dx = player.x - x;
var dy = player.y - y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance < 150 && distance < minDistance) {
minDistance = distance;
closestPlayer = player;
}
}
return closestPlayer;
}
function deselectAllPlayers() {
for (var i = 0; i < players.length; i++) {
players[i].deselect();
}
selectedPlayer = null;
}
function checkGoal() {
// Use intersects for goal detection, only trigger on the frame the ball enters the goal
if (typeof ball.lastWasInTopGoal === "undefined") ball.lastWasInTopGoal = false;
if (typeof ball.lastWasInBottomGoal === "undefined") ball.lastWasInBottomGoal = false;
var nowInTopGoal = ball.intersects(topGoal);
var nowInBottomGoal = ball.intersects(bottomGoal);
// Top goal (opponent's goal)
if (!ball.lastWasInTopGoal && nowInTopGoal) {
playerScore++;
updateScore();
LK.getSound('goal').play();
resetBallPosition();
ball.lastWasInTopGoal = nowInTopGoal;
ball.lastWasInBottomGoal = nowInBottomGoal;
return true;
}
// Bottom goal (player's goal)
if (!ball.lastWasInBottomGoal && nowInBottomGoal) {
opponentScore++;
updateScore();
LK.getSound('goal').play();
resetBallPosition();
ball.lastWasInTopGoal = nowInTopGoal;
ball.lastWasInBottomGoal = nowInBottomGoal;
return true;
}
ball.lastWasInTopGoal = nowInTopGoal;
ball.lastWasInBottomGoal = nowInBottomGoal;
return false;
}
function resetBallPosition() {
ball.x = 1024;
ball.y = 1366;
ball.velocityX = 0;
ball.velocityY = 0;
}
function updateOpponentAI() {
// Simple AI: move towards ball if it's in their half or close to center
var closestOpponent = opponents[0];
var minDistance = Infinity;
for (var i = 0; i < opponents.length; i++) {
var dx = opponents[i].x - ball.x;
var dy = opponents[i].y - ball.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance < minDistance) {
minDistance = distance;
closestOpponent = opponents[i];
}
}
// Move closest opponent towards ball if ball is in their territory or near center
if (ball.y < 1500) {
closestOpponent.targetX = ball.x;
closestOpponent.targetY = Math.max(200, ball.y);
} else {
// Move to defensive position if ball is far away
closestOpponent.targetX = 1024;
closestOpponent.targetY = 800;
}
// Other opponents spread out in their half
for (var i = 0; i < opponents.length; i++) {
if (opponents[i] !== closestOpponent) {
opponents[i].targetX = 400 + i * 300;
opponents[i].targetY = 600 + i % 2 * 300;
}
}
// If opponent touches ball, kick towards player goal
if (minDistance < 50) {
ball.kick(1024, 2580, 10);
}
}
function updatePlayerAI() {
// AI for non-selected players only
for (var i = 0; i < players.length; i++) {
var player = players[i];
// Skip the currently selected player
if (player === selectedPlayer) continue;
var dx = ball.x - player.x;
var dy = ball.y - player.y;
var distance = Math.sqrt(dx * dx + dy * dy);
// More aggressive AI - move towards ball if it's close or in attacking position
if (distance < 400 || ball.y > 1200 && distance < 600) {
var moveSpeed = 2.5;
if (distance > 10) {
player.x += dx / distance * moveSpeed;
player.y += dy / distance * moveSpeed;
}
// Kick ball towards opponent goal if close enough
if (distance < 60) {
ball.kick(1024, 150, 12);
}
} else {
// Move to better positioning - spread out more
var targetX = 300 + i * 350;
var targetY = 1800 + i % 2 * 300;
var tdx = targetX - player.x;
var tdy = targetY - player.y;
var tdist = Math.sqrt(tdx * tdx + tdy * tdy);
if (tdist > 10) {
player.x += tdx / tdist * 2;
player.y += tdy / tdist * 2;
}
}
}
}
// Movement control zones
var controlZoneSize = 200;
var leftZone = {
x: 100,
y: 2532,
width: controlZoneSize,
height: controlZoneSize
};
var rightZone = {
x: 1748,
y: 2532,
width: controlZoneSize,
height: controlZoneSize
};
var upZone = {
x: 924,
y: 2432,
width: controlZoneSize,
height: controlZoneSize
};
var downZone = {
x: 924,
y: 2632,
width: controlZoneSize,
height: controlZoneSize
};
var sizeUpZone = {
x: 1524,
y: 2432,
width: controlZoneSize,
height: controlZoneSize
};
function isInZone(x, y, zone) {
return x >= zone.x && x <= zone.x + zone.width && y >= zone.y && y <= zone.y + zone.width;
}
function moveSelectedPlayer(dx, dy) {
if (!selectedPlayer) return;
var newX = selectedPlayer.x + dx;
var newY = selectedPlayer.y + dy;
// Keep within field bounds
newX = Math.max(100, Math.min(1948, newX));
newY = Math.max(200, Math.min(2500, newY)); // Allow movement to entire field
tween(selectedPlayer, {
x: newX,
y: newY
}, {
duration: 200,
easing: tween.easeOut
});
}
function makeBigger() {
// Make ball bigger
tween(ball, {
scaleX: 1.5,
scaleY: 1.5
}, {
duration: 500,
easing: tween.easeOut
});
// Make all players bigger
for (var i = 0; i < players.length; i++) {
tween(players[i], {
scaleX: 1.3,
scaleY: 1.3
}, {
duration: 500,
easing: tween.easeOut
});
}
// Make all opponents bigger
for (var i = 0; i < opponents.length; i++) {
tween(opponents[i], {
scaleX: 1.3,
scaleY: 1.3
}, {
duration: 500,
easing: tween.easeOut
});
}
}
game.down = function (x, y, obj) {
if (!gameStarted) return;
// Check size up zone first
if (isInZone(x, y, sizeUpZone)) {
makeBigger();
return;
}
// If a player is selected, move them to the tapped location
if (selectedPlayer) {
// Allow movement anywhere on the field
var targetX = Math.max(100, Math.min(1948, x));
var targetY = Math.max(200, Math.min(2500, y)); // Allow movement to entire field
tween(selectedPlayer, {
x: targetX,
y: targetY
}, {
duration: 400,
easing: tween.easeOut
});
// Player kick is disabled
} else {
// Find and select closest player
var clickedPlayer = findClosestPlayer(x, y);
if (clickedPlayer) {
deselectAllPlayers();
clickedPlayer.select();
selectedPlayer = clickedPlayer;
}
}
};
game.move = function (x, y, obj) {
// Move function simplified - main control is now tap-to-move in down event
};
game.up = function (x, y, obj) {
// Up function simplified - main control is now tap-to-move
};
game.update = function () {
if (!gameStarted) return;
// Track lastY for goal detection
if (typeof ball.lastY === "undefined") ball.lastY = ball.y;
var prevBallY = ball.y;
ball.update();
ball.lastY = prevBallY;
// --- Ball possession and immunity logic ---
var now = Date.now();
var newHolder = null;
// If no one is holding the ball, allow anyone to take it by touching the ball
if (!ballHolder && now > globalImmunityUntil) {
// Check if any player touches the ball and can take it
for (var i = 0; i < players.length; i++) {
var player = players[i];
var dx = ball.x - player.x;
var dy = ball.y - player.y;
var dist = Math.sqrt(dx * dx + dy * dy);
if (dist < 50) {
newHolder = player;
break;
}
}
// If no player, check if any opponent can take the ball
if (!newHolder) {
for (var i = 0; i < opponents.length; i++) {
var opponent = opponents[i];
var dx = ball.x - opponent.x;
var dy = ball.y - opponent.y;
var dist = Math.sqrt(dx * dx + dy * dy);
if (dist < 50) {
newHolder = opponent;
break;
}
}
}
} else if (ballHolder && now > globalImmunityUntil) {
// If someone is holding the ball, check if another player (not the holder) touches the holder to steal the ball
// Check for player-to-player steal
if (ballHolder.team === 'player') {
for (var i = 0; i < players.length; i++) {
var otherPlayer = players[i];
if (otherPlayer !== ballHolder) {
var dx = ballHolder.x - otherPlayer.x;
var dy = ballHolder.y - otherPlayer.y;
var dist = Math.sqrt(dx * dx + dy * dy);
if (dist < 50) {
newHolder = otherPlayer;
break;
}
}
}
}
// Check for opponent-to-opponent steal
if (!newHolder && ballHolder.team === 'opponent') {
for (var i = 0; i < opponents.length; i++) {
var otherOpponent = opponents[i];
if (otherOpponent !== ballHolder) {
var dx = ballHolder.x - otherOpponent.x;
var dy = ballHolder.y - otherOpponent.y;
var dist = Math.sqrt(dx * dx + dy * dy);
if (dist < 50) {
newHolder = otherOpponent;
break;
}
}
}
}
// Check for opponent stealing from player
if (!newHolder && ballHolder.team === 'player') {
for (var i = 0; i < opponents.length; i++) {
var opponent = opponents[i];
var dx = ballHolder.x - opponent.x;
var dy = ballHolder.y - opponent.y;
var dist = Math.sqrt(dx * dx + dy * dy);
if (dist < 50) {
newHolder = opponent;
break;
}
}
}
// Check for player stealing from opponent
if (!newHolder && ballHolder.team === 'opponent') {
for (var i = 0; i < players.length; i++) {
var player = players[i];
var dx = ballHolder.x - player.x;
var dy = ballHolder.y - player.y;
var dist = Math.sqrt(dx * dx + dy * dy);
if (dist < 50) {
newHolder = player;
break;
}
}
}
}
// If someone new takes the ball
if (newHolder && newHolder !== ballHolder) {
// Set global immunity for everyone for 2 seconds
globalImmunityUntil = now + IMMUNITY_DURATION;
ballHolder = newHolder;
// Move ball to holder's position
ball.x = ballHolder.x;
ball.y = ballHolder.y;
ball.velocityX = 0;
ball.velocityY = 0;
// Player keeps the ball after gaining possession (do not drop)
}
// If someone is holding the ball, keep ball on them
if (ballHolder) {
ball.x = ballHolder.x;
ball.y = ballHolder.y;
}
// --- End ball possession and immunity logic ---
// Update opponents
for (var i = 0; i < opponents.length; i++) {
opponents[i].update();
}
// Update AI
if (LK.ticks % 30 === 0) {
// Update AI every half second
updateOpponentAI();
updatePlayerAI();
}
// Check for goals
checkGoal();
// Keep players within field bounds
for (var i = 0; i < players.length; i++) {
var player = players[i];
if (player.y < 200) {
player.y = 200;
}
if (player.y > 2500) {
player.y = 2500;
}
}
// Keep opponents on their side - enforce boundary more strictly
for (var i = 0; i < opponents.length; i++) {
var opponent = opponents[i];
// Prevent opponent from crossing center line
if (opponent.y > 1366) {
opponent.y = 1366;
}
if (opponent.targetY > 1366) {
opponent.targetY = 1366;
}
// Keep opponents within field bounds
if (opponent.x < 100) {
opponent.x = 100;
}
if (opponent.x > 1948) {
opponent.x = 1948;
}
if (opponent.y < 200) {
opponent.y = 200;
}
}
}; ===================================================================
--- original.js
+++ change.js
@@ -254,10 +254,10 @@
LK.gui.bottomRight.addChild(rightBtn);
// Position move buttons relative to each other (bottom right corner)
LK.setTimeout(function () {
// Use LK.gui.bottomRight's width/height for layout
- // Move the move buttons further left by increasing the offset
- var leftwardOffset = 220; // Amount to move left (in px)
+ // Move the move buttons a little bit further left by increasing the offset
+ var leftwardOffset = 320; // Amount to move left (in px) - increased for "a little bit left"
var baseX = LK.gui.bottomRight.width - moveBtnSize - moveBtnOffset - leftwardOffset;
var baseY = LK.gui.bottomRight.height - moveBtnSize - moveBtnOffset;
upBtn.x = baseX + moveBtnSize;
upBtn.y = baseY - moveBtnSize * 0.7;