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('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);
// 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() {
// Check top goal (opponent's goal) - ball must be past the goal line
if (ball.x > 924 && ball.x < 1124 && ball.y < 150) {
playerScore++;
updateScore();
LK.getSound('goal').play();
resetBallPosition();
return true;
}
// Check bottom goal (player's goal) - ball must be past the goal line
if (ball.x > 924 && ball.x < 1124 && ball.y > 2580) {
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 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
});
// 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) {
// Kick ball towards the tapped location
ball.kick(targetX, targetY, 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();
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];
if (opponent.y > 1366) {
opponent.y = 1366;
// Reset target if trying to go past center
if (opponent.targetY > 1366) {
opponent.targetY = 1200;
}
}
// 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
@@ -262,18 +262,18 @@
}
selectedPlayer = null;
}
function checkGoal() {
- // Check top goal (opponent's goal)
- if (ball.x > 924 && ball.x < 1124 && ball.y < 170) {
+ // Check top goal (opponent's goal) - ball must be past the goal line
+ if (ball.x > 924 && ball.x < 1124 && ball.y < 150) {
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) {
+ // Check bottom goal (player's goal) - ball must be past the goal line
+ if (ball.x > 924 && ball.x < 1124 && ball.y > 2580) {
opponentScore++;
updateScore();
LK.getSound('goal').play();
resetBallPosition();
@@ -287,9 +287,9 @@
ball.velocityX = 0;
ball.velocityY = 0;
}
function updateOpponentAI() {
- // Simple AI: move towards ball
+ // 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;
@@ -299,21 +299,27 @@
minDistance = distance;
closestOpponent = opponents[i];
}
}
- // Move closest opponent towards ball
- closestOpponent.targetX = ball.x;
- closestOpponent.targetY = ball.y;
- // Other opponents spread out
+ // 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, 8);
+ ball.kick(1024, 2580, 10);
}
}
function updatePlayerAI() {
// AI for non-selected players only
@@ -323,29 +329,29 @@
if (player === selectedPlayer) continue;
var dx = ball.x - player.x;
var dy = ball.y - player.y;
var distance = Math.sqrt(dx * dx + dy * dy);
- // Move towards ball if it's in player's half and close enough
- if (ball.y > 1366 && distance < 300) {
- var moveSpeed = 2;
+ // 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, 10);
+ ball.kick(1024, 150, 12);
}
} else {
- // Move to defensive position
- var targetX = 400 + i * 300;
- var targetY = 2000 + i % 2 * 200;
+ // 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 * 1.5;
- player.y += tdy / tdist * 1.5;
+ player.x += tdx / tdist * 2;
+ player.y += tdy / tdist * 2;
}
}
}
}
@@ -497,12 +503,26 @@
if (player.y > 2500) {
player.y = 2500;
}
}
- // Keep opponents on their side
+ // Keep opponents on their side - enforce boundary more strictly
for (var i = 0; i < opponents.length; i++) {
var opponent = opponents[i];
if (opponent.y > 1366) {
opponent.y = 1366;
+ // Reset target if trying to go past center
+ if (opponent.targetY > 1366) {
+ opponent.targetY = 1200;
+ }
}
+ // 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;
+ }
}
};
\ No newline at end of file