User prompt
oyunu tam ekran yap
User prompt
top köşeye gidince maç otomatik yeniden başlasın,
User prompt
top köşelere gidince ortaya gelsin otomatik
User prompt
iki kalenin resimleri farklı olsun
User prompt
kalecilerin resimleri farklı olsun
User prompt
bot takımı kendi kalesine değil benim kaleme gol atmaya çalışsın
User prompt
6 ya 6 değil 1 e 1 olsun
User prompt
rakip takımın resmi farklı olsun
User prompt
oynanış daha gerçekci olsun ve kolay olsun kaleciler topu kurtarsın bizim takımı komple ben yönetim
User prompt
kalelere kaleci koy birer tane
User prompt
bir takımı biz kontrol edelim karşı takım topu bizim kaleye atmaya çalışsın
User prompt
dikeylemesine yap telefon için kalelerin yeri yatay değil dikey yerde olsun
User prompt
tema saha olsun
Code edit (1 edits merged)
Please save this source code
User prompt
6v6 Futbol Arenası
Initial prompt
futbol oyunu yap 6 ya 6 olsun 2 kale taç ve korner olsun
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// Ball class
var Ball = Container.expand(function () {
var self = Container.call(this);
// Attach ball asset (ellipse, white)
var ballAsset = self.attachAsset('ball', {
anchorX: 0.5,
anchorY: 0.5
});
// Ball properties
self.radius = ballAsset.width / 2;
self.vx = 0;
self.vy = 0;
self.friction = 0.98; // Ball slows down over time
// Update method (called every tick)
self.update = function () {
self.x += self.vx;
self.y += self.vy;
self.vx *= self.friction;
self.vy *= self.friction;
// Clamp speed to zero if very small
if (Math.abs(self.vx) < 0.1) self.vx = 0;
if (Math.abs(self.vy) < 0.1) self.vy = 0;
};
return self;
});
// Goal class
var Goal = Container.expand(function () {
var self = Container.call(this);
// Attach goal asset (rectangle)
var goalAsset = self.attachAsset('goal', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = goalAsset.width;
self.height = goalAsset.height;
return self;
});
// Player class
var Player = Container.expand(function () {
var self = Container.call(this);
// Attach player asset (circle, color depends on team)
var playerAsset = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.radius = playerAsset.width / 2;
self.team = 0; // 0: left, 1: right
self.index = 0; // 0-5
self.isUser = false; // Only one player is user-controlled
// For AI: target position
self.targetX = self.x;
self.targetY = self.y;
// For user drag
self.isDragging = false;
// Update method
self.update = function () {
if (!self.isUser) {
// Simple AI: move toward ball
var dx = ball.x - self.x;
var dy = ball.y - self.y;
var dist = Math.sqrt(dx * dx + dy * dy);
if (dist > 80) {
self.x += dx / dist * 6;
self.y += dy / dist * 6;
}
}
// Clamp inside field (vertical orientation)
if (self.x < field.left + self.radius) self.x = field.left + self.radius;
if (self.x > field.right - self.radius) self.x = field.right - self.radius;
if (self.y < field.top + self.radius) self.y = field.top + self.radius;
if (self.y > field.bottom - self.radius) self.y = field.bottom - self.radius;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1a8f3c // Football field green
});
/****
* Game Code
****/
// Tween plugin for animations (not used in MVP but included for future use)
// Field dimensions (centered, vertical orientation)
var field = {
width: 1300,
height: 2000,
left: (2048 - 1300) / 2,
right: (2048 + 1300) / 2,
top: (2732 - 2000) / 2,
bottom: (2732 + 2000) / 2
};
// Draw field (rectangle, lines, center circle, etc.)
var fieldAsset = LK.getAsset('field', {
width: field.width,
height: field.height,
color: 0x2e7d32,
// More realistic football field green
shape: 'box',
x: field.left,
y: field.top
});
game.addChild(fieldAsset);
// Center line (horizontal now)
var centerLine = LK.getAsset('centerLine', {
width: 10,
height: field.height,
color: 0xffffff,
shape: 'box',
x: 2048 / 2 - 5,
y: field.top
});
game.addChild(centerLine);
// Penalty areas (top and bottom)
var penaltyWidth = 900;
var penaltyHeight = 300;
var topPenalty = LK.getAsset('penaltyAreaLeft', {
width: penaltyWidth,
height: penaltyHeight,
color: 0xffffff,
shape: 'box',
x: 2048 / 2 - penaltyWidth / 2,
y: field.top - 5
});
topPenalty.alpha = 0.12;
game.addChild(topPenalty);
var bottomPenalty = LK.getAsset('penaltyAreaRight', {
width: penaltyWidth,
height: penaltyHeight,
color: 0xffffff,
shape: 'box',
x: 2048 / 2 - penaltyWidth / 2,
y: field.bottom - penaltyHeight + 5
});
bottomPenalty.alpha = 0.12;
game.addChild(bottomPenalty);
// Goal areas (top and bottom)
var goalAreaWidth = 500;
var goalAreaHeight = 180;
var topGoalArea = LK.getAsset('goalAreaLeft', {
width: goalAreaWidth,
height: goalAreaHeight,
color: 0xffffff,
shape: 'box',
x: 2048 / 2 - goalAreaWidth / 2,
y: field.top - 5
});
topGoalArea.alpha = 0.18;
game.addChild(topGoalArea);
var bottomGoalArea = LK.getAsset('goalAreaRight', {
width: goalAreaWidth,
height: goalAreaHeight,
color: 0xffffff,
shape: 'box',
x: 2048 / 2 - goalAreaWidth / 2,
y: field.bottom - goalAreaHeight + 5
});
bottomGoalArea.alpha = 0.18;
game.addChild(bottomGoalArea);
// Penalty spots
var penaltySpotRadius = 18;
var topPenaltySpot = LK.getAsset('penaltySpotLeft', {
width: penaltySpotRadius * 2,
height: penaltySpotRadius * 2,
color: 0xffffff,
shape: 'ellipse',
x: 2048 / 2 - penaltySpotRadius,
y: field.top + 120
});
topPenaltySpot.alpha = 0.7;
game.addChild(topPenaltySpot);
var bottomPenaltySpot = LK.getAsset('penaltySpotRight', {
width: penaltySpotRadius * 2,
height: penaltySpotRadius * 2,
color: 0xffffff,
shape: 'ellipse',
x: 2048 / 2 - penaltySpotRadius,
y: field.bottom - 120 - penaltySpotRadius * 2
});
bottomPenaltySpot.alpha = 0.7;
game.addChild(bottomPenaltySpot);
// Center circle
var centerCircle = LK.getAsset('centerCircle', {
width: 320,
height: 320,
color: 0xffffff,
shape: 'ellipse',
x: 2048 / 2 - 160,
y: 2732 / 2 - 160
});
centerCircle.alpha = 0.25;
game.addChild(centerCircle);
// Center spot
var centerSpot = LK.getAsset('centerSpot', {
width: 24,
height: 24,
color: 0xffffff,
shape: 'ellipse',
x: 2048 / 2 - 12,
y: 2732 / 2 - 12
});
centerSpot.alpha = 0.7;
game.addChild(centerSpot);
// Corner arcs (for visual, not used in logic)
for (var i = 0; i < 4; i++) {
var cx = i < 2 ? field.left : field.right;
var cy = i % 2 === 0 ? field.top : field.bottom;
var cornerArc = LK.getAsset('cornerArc' + i, {
width: 60,
height: 60,
color: 0xffffff,
shape: 'ellipse',
x: cx - 30,
y: cy - 30
});
cornerArc.alpha = 0.15;
game.addChild(cornerArc);
}
// Goals (top and bottom)
var goalWidth = 400;
var goalHeight = 120;
var topGoal = new Goal();
var bottomGoal = new Goal();
topGoal.x = 2048 / 2;
topGoal.y = field.top - 20 + goalHeight / 2;
bottomGoal.x = 2048 / 2;
bottomGoal.y = field.bottom + 20 - goalHeight / 2;
topGoal.width = goalWidth;
topGoal.height = goalHeight;
bottomGoal.width = goalWidth;
bottomGoal.height = goalHeight;
game.addChild(topGoal);
game.addChild(bottomGoal);
// Ball
var ball = new Ball();
ball.x = 2048 / 2;
ball.y = 2732 / 2;
var ballAsset = ball.children[0];
ballAsset.width = 60;
ballAsset.height = 60;
ball.radius = 30;
ballAsset.color = 0xffffff;
game.addChild(ball);
// Teams
var teamA = [];
var teamB = [];
var playerRadius = 60;
var playerColors = [0x1e90ff, 0xff3333]; // Blue, Red
// Place teamA (top, blue)
for (var i = 0; i < 6; i++) {
var p = new Player();
var asset = p.children[0];
asset.width = playerRadius * 2;
asset.height = playerRadius * 2;
asset.color = playerColors[0];
p.radius = playerRadius;
p.team = 0;
p.index = i;
// Arrange in 2-2-2 formation (top half)
var row = Math.floor(i / 2);
var col = i % 2;
p.x = field.left + (col + 1) * (field.width / 3);
p.y = field.top + 300 + row * 150;
if (i === 0) {
p.isUser = true; // Only first player is user-controlled
}
teamA.push(p);
game.addChild(p);
}
// Place teamB (bottom, red)
for (var i = 0; i < 6; i++) {
var p = new Player();
var asset = p.children[0];
asset.width = playerRadius * 2;
asset.height = playerRadius * 2;
asset.color = playerColors[1];
p.radius = playerRadius;
p.team = 1;
p.index = i;
// Arrange in 2-2-2 formation (bottom half)
var row = Math.floor(i / 2);
var col = i % 2;
p.x = field.left + (col + 1) * (field.width / 3);
p.y = field.bottom - 300 - row * 150;
teamB.push(p);
game.addChild(p);
}
// Score
var scoreA = 0;
var scoreB = 0;
var scoreTxt = new Text2('0 - 0', {
size: 120,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Game state
var lastTouch = {
x: 0,
y: 0
};
var draggingPlayer = null;
var throwInActive = false;
var throwInTeam = 0;
var throwInPos = {
x: 0,
y: 0
};
var cornerActive = false;
var cornerTeam = 0;
var cornerPos = {
x: 0,
y: 0
};
var lastTeamTouched = 0; // 0: teamA, 1: teamB
// Helper: check collision between two circles
function circlesCollide(ax, ay, ar, bx, by, br) {
var dx = ax - bx;
var dy = ay - by;
var dist = Math.sqrt(dx * dx + dy * dy);
return dist < ar + br;
}
// Helper: check if ball is in goal
function isGoal(ball, goal) {
return ball.y > goal.y - goal.height / 2 && ball.y < goal.y + goal.height / 2 && ball.x > goal.x - goal.width / 2 && ball.x < goal.x + goal.width / 2;
}
// Helper: reset positions after goal
function resetPositions() {
// Ball to center
ball.x = 2048 / 2;
ball.y = 2732 / 2;
ball.vx = 0;
ball.vy = 0;
// TeamA (top)
for (var i = 0; i < 6; i++) {
var p = teamA[i];
var row = Math.floor(i / 2);
var col = i % 2;
p.x = field.left + (col + 1) * (field.width / 3);
p.y = field.top + 300 + row * 150;
}
// TeamB (bottom)
for (var i = 0; i < 6; i++) {
var p = teamB[i];
var row = Math.floor(i / 2);
var col = i % 2;
p.x = field.left + (col + 1) * (field.width / 3);
p.y = field.bottom - 300 - row * 150;
}
}
// Helper: check if ball is out for throw-in or corner
function checkOutOfBounds() {
// Top/bottom (taç)
if (ball.y < field.top) {
throwInActive = true;
throwInTeam = 1; // Bottom team gets throw-in
throwInPos.y = field.top + ball.radius + 10;
throwInPos.x = Math.max(field.left + ball.radius + 10, Math.min(ball.x, field.right - ball.radius - 10));
ball.vx = 0;
ball.vy = 0;
ball.y = throwInPos.y;
ball.x = throwInPos.x;
} else if (ball.y > field.bottom) {
throwInActive = true;
throwInTeam = 0; // Top team gets throw-in
throwInPos.y = field.bottom - ball.radius - 10;
throwInPos.x = Math.max(field.left + ball.radius + 10, Math.min(ball.x, field.right - ball.radius - 10));
ball.vx = 0;
ball.vy = 0;
ball.y = throwInPos.y;
ball.x = throwInPos.x;
}
// Left/right (korner veya aut)
else if (ball.x < field.left) {
// If ball is between goal posts, it's a goal
if (ball.y > topGoal.y - topGoal.height / 2 && ball.y < topGoal.y + topGoal.height / 2) {
// Top goal
scoreB++;
scoreTxt.setText(scoreA + " - " + scoreB);
resetPositions();
return;
}
// Otherwise, corner or goal kick
if (ball.y < field.top + 200) {
// Top left corner
cornerActive = true;
cornerTeam = 1; // Bottom team gets corner
cornerPos.x = field.left + 30;
cornerPos.y = field.top + 30;
} else if (ball.y > field.bottom - 200) {
// Bottom left corner
cornerActive = true;
cornerTeam = 0; // Top team gets corner
cornerPos.x = field.left + 30;
cornerPos.y = field.bottom - 30;
} else {
// Goal kick (not implemented, treat as throw-in for now)
throwInActive = true;
throwInTeam = lastTeamTouched === 0 ? 1 : 0;
throwInPos.y = Math.max(field.top + ball.radius + 10, Math.min(ball.y, field.bottom - ball.radius - 10));
throwInPos.x = field.left + ball.radius + 10;
}
ball.vx = 0;
ball.vy = 0;
if (cornerActive) {
ball.x = cornerPos.x;
ball.y = cornerPos.y;
} else {
ball.x = throwInPos.x;
ball.y = throwInPos.y;
}
} else if (ball.x > field.right) {
// If ball is between goal posts, it's a goal
if (ball.y > bottomGoal.y - bottomGoal.height / 2 && ball.y < bottomGoal.y + bottomGoal.height / 2) {
// Bottom goal
scoreA++;
scoreTxt.setText(scoreA + " - " + scoreB);
resetPositions();
return;
}
// Otherwise, corner or goal kick
if (ball.y < field.top + 200) {
// Top right corner
cornerActive = true;
cornerTeam = 1; // Bottom team gets corner
cornerPos.x = field.right - 30;
cornerPos.y = field.top + 30;
} else if (ball.y > field.bottom - 200) {
// Bottom right corner
cornerActive = true;
cornerTeam = 0; // Top team gets corner
cornerPos.x = field.right - 30;
cornerPos.y = field.bottom - 30;
} else {
// Goal kick (not implemented, treat as throw-in for now)
throwInActive = true;
throwInTeam = lastTeamTouched === 0 ? 1 : 0;
throwInPos.y = Math.max(field.top + ball.radius + 10, Math.min(ball.y, field.bottom - ball.radius - 10));
throwInPos.x = field.right - ball.radius - 10;
}
ball.vx = 0;
ball.vy = 0;
if (cornerActive) {
ball.x = cornerPos.x;
ball.y = cornerPos.y;
} else {
ball.x = throwInPos.x;
ball.y = throwInPos.y;
}
}
}
// Touch/drag logic for user player
game.down = function (x, y, obj) {
// Only allow drag if not in throw-in/corner
if (throwInActive || cornerActive) return;
// Check if user player is touched
var userPlayer = teamA[0];
var dx = x - userPlayer.x;
var dy = y - userPlayer.y;
if (dx * dx + dy * dy < userPlayer.radius * userPlayer.radius) {
draggingPlayer = userPlayer;
draggingPlayer.isDragging = true;
lastTouch.x = x;
lastTouch.y = y;
}
};
game.move = function (x, y, obj) {
if (draggingPlayer && draggingPlayer.isDragging) {
// Move player with finger, clamp inside field (vertical)
draggingPlayer.x = Math.max(field.left + draggingPlayer.radius, Math.min(x, field.right - draggingPlayer.radius));
draggingPlayer.y = Math.max(field.top + draggingPlayer.radius, Math.min(y, field.bottom - draggingPlayer.radius));
lastTouch.x = x;
lastTouch.y = y;
}
};
game.up = function (x, y, obj) {
if (draggingPlayer && draggingPlayer.isDragging) {
// On release, if close to ball, kick it
var dx = ball.x - draggingPlayer.x;
var dy = ball.y - draggingPlayer.y;
var dist = Math.sqrt(dx * dx + dy * dy);
if (dist < draggingPlayer.radius + ball.radius + 10) {
// Kick direction: from player to ball, magnitude based on drag
var kickVx = (ball.x - lastTouch.x) * 0.3;
var kickVy = (ball.y - lastTouch.y) * 0.3;
ball.vx += kickVx;
ball.vy += kickVy;
lastTeamTouched = 0;
}
draggingPlayer.isDragging = false;
draggingPlayer = null;
}
// Throw-in/corner logic
if (throwInActive) {
// Only allow throw-in by correct team
if (throwInTeam === 0) {
// Left team
var dx = x - ball.x;
var dy = y - ball.y;
var dist = Math.sqrt(dx * dx + dy * dy);
if (dist > 30) {
ball.vx = dx * 0.15;
ball.vy = dy * 0.15;
throwInActive = false;
}
}
if (throwInTeam === 1) {
// Right team
var dx = x - ball.x;
var dy = y - ball.y;
var dist = Math.sqrt(dx * dx + dy * dy);
if (dist > 30) {
ball.vx = dx * 0.15;
ball.vy = dy * 0.15;
throwInActive = false;
}
}
}
if (cornerActive) {
// Only allow corner by correct team
if (cornerTeam === 0) {
// Left team
var dx = x - ball.x;
var dy = y - ball.y;
var dist = Math.sqrt(dx * dx + dy * dy);
if (dist > 30) {
ball.vx = dx * 0.15;
ball.vy = dy * 0.15;
cornerActive = false;
}
}
if (cornerTeam === 1) {
// Right team
var dx = x - ball.x;
var dy = y - ball.y;
var dist = Math.sqrt(dx * dx + dy * dy);
if (dist > 30) {
ball.vx = dx * 0.15;
ball.vy = dy * 0.15;
cornerActive = false;
}
}
}
};
// Main game update
game.update = function () {
// Update all players
for (var i = 0; i < 6; i++) {
teamA[i].update();
teamB[i].update();
}
// Update ball
ball.update();
// Ball-player collision
for (var i = 0; i < 6; i++) {
var p = teamA[i];
var dx = ball.x - p.x;
var dy = ball.y - p.y;
var dist = Math.sqrt(dx * dx + dy * dy);
if (dist < ball.radius + p.radius) {
// Push ball away
var overlap = ball.radius + p.radius - dist + 1;
var nx = dx / dist;
var ny = dy / dist;
ball.x += nx * overlap;
ball.y += ny * overlap;
// Ball velocity
ball.vx += nx * 2;
ball.vy += ny * 2;
lastTeamTouched = 0;
}
var p2 = teamB[i];
dx = ball.x - p2.x;
dy = ball.y - p2.y;
dist = Math.sqrt(dx * dx + dy * dy);
if (dist < ball.radius + p2.radius) {
var overlap = ball.radius + p2.radius - dist + 1;
var nx = dx / dist;
var ny = dy / dist;
ball.x += nx * overlap;
ball.y += ny * overlap;
ball.vx += nx * 2;
ball.vy += ny * 2;
lastTeamTouched = 1;
}
}
// Ball-wall collision (field boundaries)
if (ball.x < field.left + ball.radius) {
ball.x = field.left + ball.radius;
ball.vx = -ball.vx * 0.7;
}
if (ball.x > field.right - ball.radius) {
ball.x = field.right - ball.radius;
ball.vx = -ball.vx * 0.7;
}
if (ball.y < field.top + ball.radius) {
ball.y = field.top + ball.radius;
ball.vy = -ball.vy * 0.7;
}
if (ball.y > field.bottom - ball.radius) {
ball.y = field.bottom - ball.radius;
ball.vy = -ball.vy * 0.7;
}
// Check for goals
if (isGoal(ball, topGoal)) {
scoreB++;
scoreTxt.setText(scoreA + " - " + scoreB);
resetPositions();
return;
}
if (isGoal(ball, bottomGoal)) {
scoreA++;
scoreTxt.setText(scoreA + " - " + scoreB);
resetPositions();
return;
}
// Check for throw-in/corner
if (!throwInActive && !cornerActive) {
checkOutOfBounds();
}
// Win condition (first to 5)
if (scoreA >= 5) {
LK.showYouWin();
}
if (scoreB >= 5) {
LK.showGameOver();
}
}; ===================================================================
--- original.js
+++ change.js
@@ -71,9 +71,9 @@
self.x += dx / dist * 6;
self.y += dy / dist * 6;
}
}
- // Clamp inside field
+ // Clamp inside field (vertical orientation)
if (self.x < field.left + self.radius) self.x = field.left + self.radius;
if (self.x > field.right - self.radius) self.x = field.right - self.radius;
if (self.y < field.top + self.radius) self.y = field.top + self.radius;
if (self.y > field.bottom - self.radius) self.y = field.bottom - self.radius;
@@ -91,16 +91,16 @@
/****
* Game Code
****/
// Tween plugin for animations (not used in MVP but included for future use)
-// Field dimensions (centered)
+// Field dimensions (centered, vertical orientation)
var field = {
- width: 1700,
- height: 2500,
- left: (2048 - 1700) / 2,
- right: (2048 + 1700) / 2,
- top: (2732 - 2500) / 2,
- bottom: (2732 + 2500) / 2
+ width: 1300,
+ height: 2000,
+ left: (2048 - 1300) / 2,
+ right: (2048 + 1300) / 2,
+ top: (2732 - 2000) / 2,
+ bottom: (2732 + 2000) / 2
};
// Draw field (rectangle, lines, center circle, etc.)
var fieldAsset = LK.getAsset('field', {
width: field.width,
@@ -111,86 +111,86 @@
x: field.left,
y: field.top
});
game.addChild(fieldAsset);
-// Center line
+// Center line (horizontal now)
var centerLine = LK.getAsset('centerLine', {
- width: field.width,
- height: 10,
+ width: 10,
+ height: field.height,
color: 0xffffff,
shape: 'box',
- x: field.left,
- y: field.top + field.height / 2 - 5
+ x: 2048 / 2 - 5,
+ y: field.top
});
game.addChild(centerLine);
-// Penalty areas (left and right)
-var penaltyWidth = 500;
-var penaltyHeight = 1100;
-var leftPenalty = LK.getAsset('penaltyAreaLeft', {
+// Penalty areas (top and bottom)
+var penaltyWidth = 900;
+var penaltyHeight = 300;
+var topPenalty = LK.getAsset('penaltyAreaLeft', {
width: penaltyWidth,
height: penaltyHeight,
color: 0xffffff,
shape: 'box',
- x: field.left - 5,
- y: 2732 / 2 - penaltyHeight / 2
+ x: 2048 / 2 - penaltyWidth / 2,
+ y: field.top - 5
});
-leftPenalty.alpha = 0.12;
-game.addChild(leftPenalty);
-var rightPenalty = LK.getAsset('penaltyAreaRight', {
+topPenalty.alpha = 0.12;
+game.addChild(topPenalty);
+var bottomPenalty = LK.getAsset('penaltyAreaRight', {
width: penaltyWidth,
height: penaltyHeight,
color: 0xffffff,
shape: 'box',
- x: field.right - penaltyWidth + 5,
- y: 2732 / 2 - penaltyHeight / 2
+ x: 2048 / 2 - penaltyWidth / 2,
+ y: field.bottom - penaltyHeight + 5
});
-rightPenalty.alpha = 0.12;
-game.addChild(rightPenalty);
-// Goal areas (left and right)
-var goalAreaWidth = 250;
-var goalAreaHeight = 500;
-var leftGoalArea = LK.getAsset('goalAreaLeft', {
+bottomPenalty.alpha = 0.12;
+game.addChild(bottomPenalty);
+// Goal areas (top and bottom)
+var goalAreaWidth = 500;
+var goalAreaHeight = 180;
+var topGoalArea = LK.getAsset('goalAreaLeft', {
width: goalAreaWidth,
height: goalAreaHeight,
color: 0xffffff,
shape: 'box',
- x: field.left - 5,
- y: 2732 / 2 - goalAreaHeight / 2
+ x: 2048 / 2 - goalAreaWidth / 2,
+ y: field.top - 5
});
-leftGoalArea.alpha = 0.18;
-game.addChild(leftGoalArea);
-var rightGoalArea = LK.getAsset('goalAreaRight', {
+topGoalArea.alpha = 0.18;
+game.addChild(topGoalArea);
+var bottomGoalArea = LK.getAsset('goalAreaRight', {
width: goalAreaWidth,
height: goalAreaHeight,
color: 0xffffff,
shape: 'box',
- x: field.right - goalAreaWidth + 5,
- y: 2732 / 2 - goalAreaHeight / 2
+ x: 2048 / 2 - goalAreaWidth / 2,
+ y: field.bottom - goalAreaHeight + 5
});
-rightGoalArea.alpha = 0.18;
-game.addChild(rightGoalArea);
+bottomGoalArea.alpha = 0.18;
+game.addChild(bottomGoalArea);
// Penalty spots
var penaltySpotRadius = 18;
-var leftPenaltySpot = LK.getAsset('penaltySpotLeft', {
+var topPenaltySpot = LK.getAsset('penaltySpotLeft', {
width: penaltySpotRadius * 2,
height: penaltySpotRadius * 2,
color: 0xffffff,
shape: 'ellipse',
- x: field.left + 120,
- y: 2732 / 2 - penaltySpotRadius
+ x: 2048 / 2 - penaltySpotRadius,
+ y: field.top + 120
});
-leftPenaltySpot.alpha = 0.7;
-game.addChild(leftPenaltySpot);
-var rightPenaltySpot = LK.getAsset('penaltySpotRight', {
+topPenaltySpot.alpha = 0.7;
+game.addChild(topPenaltySpot);
+var bottomPenaltySpot = LK.getAsset('penaltySpotRight', {
width: penaltySpotRadius * 2,
height: penaltySpotRadius * 2,
color: 0xffffff,
shape: 'ellipse',
- x: field.right - 120 - penaltySpotRadius * 2,
- y: 2732 / 2 - penaltySpotRadius
+ x: 2048 / 2 - penaltySpotRadius,
+ y: field.bottom - 120 - penaltySpotRadius * 2
});
-rightPenaltySpot.alpha = 0.7;
-game.addChild(rightPenaltySpot);
+bottomPenaltySpot.alpha = 0.7;
+game.addChild(bottomPenaltySpot);
// Center circle
var centerCircle = LK.getAsset('centerCircle', {
width: 320,
height: 320,
@@ -213,10 +213,10 @@
centerSpot.alpha = 0.7;
game.addChild(centerSpot);
// Corner arcs (for visual, not used in logic)
for (var i = 0; i < 4; i++) {
- var cx = i % 2 === 0 ? field.left : field.right;
- var cy = i < 2 ? field.top : field.bottom;
+ var cx = i < 2 ? field.left : field.right;
+ var cy = i % 2 === 0 ? field.top : field.bottom;
var cornerArc = LK.getAsset('cornerArc' + i, {
width: 60,
height: 60,
color: 0xffffff,
@@ -226,23 +226,23 @@
});
cornerArc.alpha = 0.15;
game.addChild(cornerArc);
}
-// Goals
+// Goals (top and bottom)
var goalWidth = 400;
var goalHeight = 120;
-var leftGoal = new Goal();
-var rightGoal = new Goal();
-leftGoal.x = field.left - 20 + goalWidth / 2;
-leftGoal.y = 2732 / 2;
-rightGoal.x = field.right + 20 - goalWidth / 2;
-rightGoal.y = 2732 / 2;
-leftGoal.width = goalWidth;
-leftGoal.height = goalHeight;
-rightGoal.width = goalWidth;
-rightGoal.height = goalHeight;
-game.addChild(leftGoal);
-game.addChild(rightGoal);
+var topGoal = new Goal();
+var bottomGoal = new Goal();
+topGoal.x = 2048 / 2;
+topGoal.y = field.top - 20 + goalHeight / 2;
+bottomGoal.x = 2048 / 2;
+bottomGoal.y = field.bottom + 20 - goalHeight / 2;
+topGoal.width = goalWidth;
+topGoal.height = goalHeight;
+bottomGoal.width = goalWidth;
+bottomGoal.height = goalHeight;
+game.addChild(topGoal);
+game.addChild(bottomGoal);
// Ball
var ball = new Ball();
ball.x = 2048 / 2;
ball.y = 2732 / 2;
@@ -256,9 +256,9 @@
var teamA = [];
var teamB = [];
var playerRadius = 60;
var playerColors = [0x1e90ff, 0xff3333]; // Blue, Red
-// Place teamA (left, blue)
+// Place teamA (top, blue)
for (var i = 0; i < 6; i++) {
var p = new Player();
var asset = p.children[0];
asset.width = playerRadius * 2;
@@ -266,20 +266,20 @@
asset.color = playerColors[0];
p.radius = playerRadius;
p.team = 0;
p.index = i;
- // Arrange in 2-2-2 formation
+ // Arrange in 2-2-2 formation (top half)
var row = Math.floor(i / 2);
var col = i % 2;
- p.x = field.left + 300 + row * 150;
- p.y = field.top + field.height / 6 + col * (field.height / 3) + (row - 1) * 100;
+ p.x = field.left + (col + 1) * (field.width / 3);
+ p.y = field.top + 300 + row * 150;
if (i === 0) {
p.isUser = true; // Only first player is user-controlled
}
teamA.push(p);
game.addChild(p);
}
-// Place teamB (right, red)
+// Place teamB (bottom, red)
for (var i = 0; i < 6; i++) {
var p = new Player();
var asset = p.children[0];
asset.width = playerRadius * 2;
@@ -287,13 +287,13 @@
asset.color = playerColors[1];
p.radius = playerRadius;
p.team = 1;
p.index = i;
- // Arrange in 2-2-2 formation
+ // Arrange in 2-2-2 formation (bottom half)
var row = Math.floor(i / 2);
var col = i % 2;
- p.x = field.right - 300 - row * 150;
- p.y = field.top + field.height / 6 + col * (field.height / 3) + (row - 1) * 100;
+ p.x = field.left + (col + 1) * (field.width / 3);
+ p.y = field.bottom - 300 - row * 150;
teamB.push(p);
game.addChild(p);
}
// Score
@@ -332,85 +332,85 @@
return dist < ar + br;
}
// Helper: check if ball is in goal
function isGoal(ball, goal) {
- return ball.x > goal.x - goal.width / 2 && ball.x < goal.x + goal.width / 2 && ball.y > goal.y - goal.height / 2 && ball.y < goal.y + goal.height / 2;
+ return ball.y > goal.y - goal.height / 2 && ball.y < goal.y + goal.height / 2 && ball.x > goal.x - goal.width / 2 && ball.x < goal.x + goal.width / 2;
}
// Helper: reset positions after goal
function resetPositions() {
// Ball to center
ball.x = 2048 / 2;
ball.y = 2732 / 2;
ball.vx = 0;
ball.vy = 0;
- // TeamA
+ // TeamA (top)
for (var i = 0; i < 6; i++) {
var p = teamA[i];
var row = Math.floor(i / 2);
var col = i % 2;
- p.x = field.left + 300 + row * 150;
- p.y = field.top + field.height / 6 + col * (field.height / 3) + (row - 1) * 100;
+ p.x = field.left + (col + 1) * (field.width / 3);
+ p.y = field.top + 300 + row * 150;
}
- // TeamB
+ // TeamB (bottom)
for (var i = 0; i < 6; i++) {
var p = teamB[i];
var row = Math.floor(i / 2);
var col = i % 2;
- p.x = field.right - 300 - row * 150;
- p.y = field.top + field.height / 6 + col * (field.height / 3) + (row - 1) * 100;
+ p.x = field.left + (col + 1) * (field.width / 3);
+ p.y = field.bottom - 300 - row * 150;
}
}
// Helper: check if ball is out for throw-in or corner
function checkOutOfBounds() {
- // Left/right (taç)
- if (ball.x < field.left) {
+ // Top/bottom (taç)
+ if (ball.y < field.top) {
throwInActive = true;
- throwInTeam = 1; // Right team gets throw-in
- throwInPos.x = field.left + ball.radius + 10;
- throwInPos.y = Math.max(field.top + ball.radius + 10, Math.min(ball.y, field.bottom - ball.radius - 10));
+ throwInTeam = 1; // Bottom team gets throw-in
+ throwInPos.y = field.top + ball.radius + 10;
+ throwInPos.x = Math.max(field.left + ball.radius + 10, Math.min(ball.x, field.right - ball.radius - 10));
ball.vx = 0;
ball.vy = 0;
- ball.x = throwInPos.x;
ball.y = throwInPos.y;
- } else if (ball.x > field.right) {
+ ball.x = throwInPos.x;
+ } else if (ball.y > field.bottom) {
throwInActive = true;
- throwInTeam = 0; // Left team gets throw-in
- throwInPos.x = field.right - ball.radius - 10;
- throwInPos.y = Math.max(field.top + ball.radius + 10, Math.min(ball.y, field.bottom - ball.radius - 10));
+ throwInTeam = 0; // Top team gets throw-in
+ throwInPos.y = field.bottom - ball.radius - 10;
+ throwInPos.x = Math.max(field.left + ball.radius + 10, Math.min(ball.x, field.right - ball.radius - 10));
ball.vx = 0;
ball.vy = 0;
- ball.x = throwInPos.x;
ball.y = throwInPos.y;
+ ball.x = throwInPos.x;
}
- // Top/bottom (korner veya aut)
- else if (ball.y < field.top) {
+ // Left/right (korner veya aut)
+ else if (ball.x < field.left) {
// If ball is between goal posts, it's a goal
- if (ball.x > leftGoal.x - leftGoal.width / 2 && ball.x < leftGoal.x + leftGoal.width / 2) {
- // Left goal
+ if (ball.y > topGoal.y - topGoal.height / 2 && ball.y < topGoal.y + topGoal.height / 2) {
+ // Top goal
scoreB++;
scoreTxt.setText(scoreA + " - " + scoreB);
resetPositions();
return;
}
// Otherwise, corner or goal kick
- if (ball.x < field.left + 200) {
- // Left corner
+ if (ball.y < field.top + 200) {
+ // Top left corner
cornerActive = true;
- cornerTeam = 1; // Right team gets corner
+ cornerTeam = 1; // Bottom team gets corner
cornerPos.x = field.left + 30;
cornerPos.y = field.top + 30;
- } else if (ball.x > field.right - 200) {
- // Right corner
+ } else if (ball.y > field.bottom - 200) {
+ // Bottom left corner
cornerActive = true;
- cornerTeam = 0; // Left team gets corner
- cornerPos.x = field.right - 30;
- cornerPos.y = field.top + 30;
+ cornerTeam = 0; // Top team gets corner
+ cornerPos.x = field.left + 30;
+ cornerPos.y = field.bottom - 30;
} else {
// Goal kick (not implemented, treat as throw-in for now)
throwInActive = true;
throwInTeam = lastTeamTouched === 0 ? 1 : 0;
- throwInPos.x = Math.max(field.left + ball.radius + 10, Math.min(ball.x, field.right - ball.radius - 10));
- throwInPos.y = field.top + ball.radius + 10;
+ throwInPos.y = Math.max(field.top + ball.radius + 10, Math.min(ball.y, field.bottom - ball.radius - 10));
+ throwInPos.x = field.left + ball.radius + 10;
}
ball.vx = 0;
ball.vy = 0;
if (cornerActive) {
@@ -419,36 +419,36 @@
} else {
ball.x = throwInPos.x;
ball.y = throwInPos.y;
}
- } else if (ball.y > field.bottom) {
+ } else if (ball.x > field.right) {
// If ball is between goal posts, it's a goal
- if (ball.x > rightGoal.x - rightGoal.width / 2 && ball.x < rightGoal.x + rightGoal.width / 2) {
- // Right goal
+ if (ball.y > bottomGoal.y - bottomGoal.height / 2 && ball.y < bottomGoal.y + bottomGoal.height / 2) {
+ // Bottom goal
scoreA++;
scoreTxt.setText(scoreA + " - " + scoreB);
resetPositions();
return;
}
// Otherwise, corner or goal kick
- if (ball.x < field.left + 200) {
- // Left corner
+ if (ball.y < field.top + 200) {
+ // Top right corner
cornerActive = true;
- cornerTeam = 1; // Right team gets corner
- cornerPos.x = field.left + 30;
- cornerPos.y = field.bottom - 30;
- } else if (ball.x > field.right - 200) {
- // Right corner
+ cornerTeam = 1; // Bottom team gets corner
+ cornerPos.x = field.right - 30;
+ cornerPos.y = field.top + 30;
+ } else if (ball.y > field.bottom - 200) {
+ // Bottom right corner
cornerActive = true;
- cornerTeam = 0; // Left team gets corner
+ cornerTeam = 0; // Top team gets corner
cornerPos.x = field.right - 30;
cornerPos.y = field.bottom - 30;
} else {
// Goal kick (not implemented, treat as throw-in for now)
throwInActive = true;
throwInTeam = lastTeamTouched === 0 ? 1 : 0;
- throwInPos.x = Math.max(field.left + ball.radius + 10, Math.min(ball.x, field.right - ball.radius - 10));
- throwInPos.y = field.bottom - ball.radius - 10;
+ throwInPos.y = Math.max(field.top + ball.radius + 10, Math.min(ball.y, field.bottom - ball.radius - 10));
+ throwInPos.x = field.right - ball.radius - 10;
}
ball.vx = 0;
ball.vy = 0;
if (cornerActive) {
@@ -476,9 +476,9 @@
}
};
game.move = function (x, y, obj) {
if (draggingPlayer && draggingPlayer.isDragging) {
- // Move player with finger, clamp inside field
+ // Move player with finger, clamp inside field (vertical)
draggingPlayer.x = Math.max(field.left + draggingPlayer.radius, Math.min(x, field.right - draggingPlayer.radius));
draggingPlayer.y = Math.max(field.top + draggingPlayer.radius, Math.min(y, field.bottom - draggingPlayer.radius));
lastTouch.x = x;
lastTouch.y = y;
@@ -612,15 +612,15 @@
ball.y = field.bottom - ball.radius;
ball.vy = -ball.vy * 0.7;
}
// Check for goals
- if (isGoal(ball, leftGoal)) {
+ if (isGoal(ball, topGoal)) {
scoreB++;
scoreTxt.setText(scoreA + " - " + scoreB);
resetPositions();
return;
}
- if (isGoal(ball, rightGoal)) {
+ if (isGoal(ball, bottomGoal)) {
scoreA++;
scoreTxt.setText(scoreA + " - " + scoreB);
resetPositions();
return;