User prompt
Make a immunty for the Player when he takse the ball
User prompt
İf a Player get ball other players cant get it
User prompt
Other players cant take the ball
User prompt
If Player touch the ball. He take it and if another Player touchs him the Player gets ball and gire immunity for 2 seconds
User prompt
I cant Goal. Make hitbox bigger team goal
User prompt
The goal is invisible now
User prompt
Make a hitbox for Goal and if ball go to Goal Make a point for team
User prompt
İ cant goal
User prompt
İ cant Goal and my teammates ara not moving and the other tema is cant come our side
User prompt
İ cant play any Player. İ can select first but after i cant swich
User prompt
Make a single Player to move and Make the other players a bot
User prompt
İ cant go the other part of the map and i cant throw ball at the back
User prompt
I must drag for move but i dont want it. İ want touch for moving and i cant go the opponents land
User prompt
Playing is so hard. Make easier controls and Make bal bigger
User prompt
We must touch the move
User prompt
Make a controller for move and make bigger bal and players ↪💡 Consider importing and using the following plugins: @upit/tween.v1
Code edit (1 edits merged)
Please save this source code
User prompt
Pocket Football Manager
Initial prompt
A football game
/****
* 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
}));
var bottomGoal = game.addChild(LK.getAsset('goal', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 2580
}));
// 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;
// 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;
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;
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);
// Control zone visual indicators
var leftControl = game.addChild(LK.getAsset('player', {
anchorX: 0.5,
anchorY: 0.5,
x: 200,
y: 2632,
alpha: 0.3
}));
var rightControl = game.addChild(LK.getAsset('player', {
anchorX: 0.5,
anchorY: 0.5,
x: 1848,
y: 2632,
alpha: 0.3
}));
var upControl = game.addChild(LK.getAsset('player', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 2532,
alpha: 0.3
}));
var downControl = game.addChild(LK.getAsset('player', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 2732,
alpha: 0.3
}));
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('Tap to select a player, then tap where you want them to move (only in your half). Tap big ball icon to make everything bigger!', {
size: 40,
fill: 0xFFFFFF
});
instructionText.anchor.set(0.5, 1);
LK.gui.bottom.addChild(instructionText);
// 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 closest = null;
var minDistance = Infinity;
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 < minDistance && distance < 150) {
minDistance = distance;
closest = player;
}
}
return closest;
}
function deselectAllPlayers() {
for (var i = 0; i < players.length; i++) {
players[i].deselect();
}
selectedPlayer = null;
}
function checkGoal() {
// Check top goal (opponent's goal)
if (ball.x > 924 && ball.x < 1124 && ball.y < 170) {
playerScore++;
updateScore();
LK.getSound('goal').play();
resetBallPosition();
return true;
}
// Check bottom goal (player's goal)
if (ball.x > 924 && ball.x < 1124 && ball.y > 2560) {
opponentScore++;
updateScore();
LK.getSound('goal').play();
resetBallPosition();
return true;
}
return false;
}
function resetBallPosition() {
ball.x = 1024;
ball.y = 1366;
ball.velocityX = 0;
ball.velocityY = 0;
}
function updateOpponentAI() {
// Simple AI: move towards ball
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
closestOpponent.targetX = ball.x;
closestOpponent.targetY = ball.y;
// Other opponents spread out
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, 8);
}
}
// 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(1366, Math.min(2500, newY)); // Keep on player side
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) {
// Restrict movement to player's half (bottom half)
var targetX = Math.max(100, Math.min(1948, x));
var targetY = Math.max(1366, Math.min(2500, y)); // Keep on player side only
tween(selectedPlayer, {
x: targetX,
y: targetY
}, {
duration: 400,
easing: tween.easeOut
});
// Check if player can kick ball
var ballDx = ball.x - selectedPlayer.x;
var ballDy = ball.y - selectedPlayer.y;
var ballDistance = Math.sqrt(ballDx * ballDx + ballDy * ballDy);
if (ballDistance < 100) {
// Auto-kick ball towards goal
ball.kick(1024, 150, 12);
}
} 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;
// Update ball
ball.update();
// 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();
}
// Check for goals
checkGoal();
// Keep players on their side
for (var i = 0; i < players.length; i++) {
var player = players[i];
if (player.y < 1366) {
player.y = 1366;
}
}
// Keep opponents on their side
for (var i = 0; i < opponents.length; i++) {
var opponent = opponents[i];
if (opponent.y > 1366) {
opponent.y = 1366;
}
}
}; ===================================================================
--- original.js
+++ change.js
@@ -208,9 +208,9 @@
fill: 0xFFFFFF
});
timeText.anchor.set(1, 0);
LK.gui.topRight.addChild(timeText);
-var instructionText = new Text2('Tap a player, then tap where you want them to go. Tap big ball icon to make everything bigger!', {
+var instructionText = new Text2('Tap to select a player, then tap where you want them to move (only in your half). Tap big ball icon to make everything bigger!', {
size: 40,
fill: 0xFFFFFF
});
instructionText.anchor.set(0.5, 1);
@@ -400,17 +400,13 @@
if (isInZone(x, y, sizeUpZone)) {
makeBigger();
return;
}
- // Find and select closest player
- var clickedPlayer = findClosestPlayer(x, y);
- if (clickedPlayer) {
- deselectAllPlayers();
- clickedPlayer.select();
- selectedPlayer = clickedPlayer;
- // Immediately move player to tapped location
+ // If a player is selected, move them to the tapped location
+ if (selectedPlayer) {
+ // Restrict movement to player's half (bottom half)
var targetX = Math.max(100, Math.min(1948, x));
- var targetY = Math.max(1366, Math.min(2500, y)); // Keep on player side
+ var targetY = Math.max(1366, Math.min(2500, y)); // Keep on player side only
tween(selectedPlayer, {
x: targetX,
y: targetY
}, {
@@ -424,8 +420,16 @@
if (ballDistance < 100) {
// Auto-kick ball towards goal
ball.kick(1024, 150, 12);
}
+ } 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