User prompt
Karakterler seçtiğimiz takımın logosuna göre olsun
User prompt
Kaleye top yandan girince gol sayılmasın
User prompt
Kalelere direkler ekle ve top kaleye yandan girince gol olmasın.Sahaya çizgiler ekle.topu biraz daha büyült
User prompt
İkinci oyuncuyu düzelt çünkü hareket edince kayboluyor
User prompt
Biraz daha hızlı
User prompt
Karakterler biraz daha büyük olsun
Code edit (1 edits merged)
Please save this source code
User prompt
Futbol Pro: LaLiga vs Süper Lig
Initial prompt
Bana bir futbol oyunu yap.girişe iki seçenek koy.seçeneklerden biri iki kişi oyna,biride yapay zekayla oyna olsun.iki kişi oynaya bastığında oyunu iki kişi oynayabilelim,yapay zekayla oynaya bastığında yapay zekayla oynayabilelim.sonrasında takım seçelim.ama oradada iki seçenek olsun seçeneklerden biri LaLiga diğeri süperlig olsun.Süperlig takımları:Galatasaray,Fenerbahçe,Beşiktaş,Trabzonspor,Başakşehir olsun.LaLiga takımları;RealMadrid ve Barcelona olsun.kaleler orta boyutta olsun karakterler orta boyutta olsun saha büyük olsun.skorboard da seçtiğimiz takımlara göre olsun
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Ball = Container.expand(function () {
var self = Container.call(this);
var ballGraphics = self.attachAsset('ball', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityX = 0;
self.velocityY = 0;
self.friction = 0.96;
self.update = function () {
self.x += self.velocityX;
self.y += self.velocityY;
self.velocityX *= self.friction;
self.velocityY *= self.friction;
// Boundary checks
if (self.x < 30) {
self.x = 30;
self.velocityX = -self.velocityX * 0.7;
}
if (self.x > 2018) {
self.x = 2018;
self.velocityX = -self.velocityX * 0.7;
}
if (self.y < 30) {
self.y = 30;
self.velocityY = -self.velocityY * 0.7;
}
if (self.y > 2702) {
self.y = 2702;
self.velocityY = -self.velocityY * 0.7;
}
};
self.kick = function (forceX, forceY) {
self.velocityX += forceX;
self.velocityY += forceY;
LK.getSound('kick').play();
};
return self;
});
var MenuButton = Container.expand(function (text, color) {
var self = Container.call(this);
var bg = self.attachAsset('menuButton', {
anchorX: 0.5,
anchorY: 0.5
});
if (color) {
bg.tint = color;
}
var buttonText = new Text2(text, {
size: 40,
fill: 0xFFFFFF
});
buttonText.anchor.set(0.5, 0.5);
self.addChild(buttonText);
self.down = function (x, y, obj) {
tween(self, {
scaleX: 0.95,
scaleY: 0.95
}, {
duration: 100
});
};
self.up = function (x, y, obj) {
tween(self, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
if (self.onPress) {
self.onPress();
}
};
return self;
});
var Player = Container.expand(function (teamLogo, fallbackColor) {
var self = Container.call(this);
var playerGraphics;
if (teamLogo) {
playerGraphics = self.attachAsset(teamLogo, {
anchorX: 0.5,
anchorY: 0.5
});
} else {
playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
if (fallbackColor) {
playerGraphics.tint = fallbackColor;
}
}
self.isAI = false;
self.targetX = 0;
self.targetY = 0;
self.update = function () {
if (self.isAI && ball) {
// Simple AI behavior
var dx = ball.x - self.x;
var dy = ball.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 100) {
self.x += dx / distance * 4;
self.y += dy / distance * 4;
}
// AI kicks ball towards goal
if (distance < 80) {
var goalX = 1024;
var goalY = self.y < 1366 ? 2650 : 82;
var ballToGoalX = goalX - ball.x;
var ballToGoalY = goalY - ball.y;
ball.kick(ballToGoalX * 0.04, ballToGoalY * 0.04);
}
}
};
self.down = function (x, y, obj) {
if (!self.isAI) {
self.targetX = x;
self.targetY = y;
}
};
// Move method removed - now handled by global game event handlers
return self;
});
var TeamButton = Container.expand(function (teamName, color) {
var self = Container.call(this);
var bg = self.attachAsset('teamButton', {
anchorX: 0.5,
anchorY: 0.5
});
if (color) {
bg.tint = color;
}
var buttonText = new Text2(teamName, {
size: 32,
fill: 0xFFFFFF
});
buttonText.anchor.set(0.5, 0.5);
self.addChild(buttonText);
self.teamName = teamName;
self.teamColor = color;
self.down = function (x, y, obj) {
tween(self, {
scaleX: 0.95,
scaleY: 0.95
}, {
duration: 100
});
};
self.up = function (x, y, obj) {
tween(self, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
if (self.onPress) {
self.onPress();
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x004400
});
/****
* Game Code
****/
// Team logo assets
// Game state variables
var gameState = 'mainMenu'; // mainMenu, leagueSelect, teamSelect, playing
var gameMode = ''; // 'twoPlayer' or 'vsAI'
var selectedLeague = '';
var team1Name = '';
var team2Name = '';
var team1Color = 0xFF0000;
var team2Color = 0x0000FF;
var team1Logo = '';
var team2Logo = '';
var score1 = 0;
var score2 = 0;
// Game objects
var ball = null;
var players = [];
var field = null;
var goals = [];
var scoreboard = null;
// Team data
var superLigTeams = [{
name: 'Galatasaray',
color: 0xFFFF00,
logo: 'galatasaray'
}, {
name: 'Fenerbahçe',
color: 0x000080,
logo: 'fenerbahce'
}, {
name: 'Beşiktaş',
color: 0x000000,
logo: 'besiktas'
}, {
name: 'Trabzonspor',
color: 0x800000,
logo: 'trabzonspor'
}, {
name: 'Başakşehir',
color: 0xFF8000,
logo: 'basaksehir'
}];
var laLigaTeams = [{
name: 'Real Madrid',
color: 0xFFFFFF,
logo: 'realmadrid'
}, {
name: 'Barcelona',
color: 0x004A9F,
logo: 'barcelona'
}];
// UI elements
var menuContainer = new Container();
var leagueContainer = new Container();
var teamContainer = new Container();
function showMainMenu() {
gameState = 'mainMenu';
clearGame();
var title = new Text2('Futbol Pro', {
size: 80,
fill: 0xFFFFFF
});
title.anchor.set(0.5, 0.5);
title.x = 1024;
title.y = 800;
menuContainer.addChild(title);
var subtitle = new Text2('LaLiga vs Süper Lig', {
size: 50,
fill: 0xCCCCCC
});
subtitle.anchor.set(0.5, 0.5);
subtitle.x = 1024;
subtitle.y = 900;
menuContainer.addChild(subtitle);
var twoPlayerBtn = new MenuButton('İki Kişi Oyna', 0x0066CC);
twoPlayerBtn.x = 1024;
twoPlayerBtn.y = 1200;
twoPlayerBtn.onPress = function () {
gameMode = 'twoPlayer';
showLeagueSelect();
};
menuContainer.addChild(twoPlayerBtn);
var vsAIBtn = new MenuButton('Yapay Zeka ile Oyna', 0x009900);
vsAIBtn.x = 1024;
vsAIBtn.y = 1350;
vsAIBtn.onPress = function () {
gameMode = 'vsAI';
showLeagueSelect();
};
menuContainer.addChild(vsAIBtn);
game.addChild(menuContainer);
}
function showLeagueSelect() {
gameState = 'leagueSelect';
menuContainer.removeChildren();
var title = new Text2('Liga Seçin', {
size: 60,
fill: 0xFFFFFF
});
title.anchor.set(0.5, 0.5);
title.x = 1024;
title.y = 800;
leagueContainer.addChild(title);
var superLigBtn = new MenuButton('Süper Lig', 0xCC0000);
superLigBtn.x = 1024;
superLigBtn.y = 1100;
superLigBtn.onPress = function () {
selectedLeague = 'superlig';
showTeamSelect();
};
leagueContainer.addChild(superLigBtn);
var laLigaBtn = new MenuButton('LaLiga', 0x0066CC);
laLigaBtn.x = 1024;
laLigaBtn.y = 1250;
laLigaBtn.onPress = function () {
selectedLeague = 'laliga';
showTeamSelect();
};
leagueContainer.addChild(laLigaBtn);
game.addChild(leagueContainer);
}
function showTeamSelect() {
gameState = 'teamSelect';
leagueContainer.removeChildren();
var teams = selectedLeague === 'superlig' ? superLigTeams : laLigaTeams;
var selectedTeams = [];
var title = new Text2('Takım Seçin', {
size: 60,
fill: 0xFFFFFF
});
title.anchor.set(0.5, 0.5);
title.x = 1024;
title.y = 400;
teamContainer.addChild(title);
var startY = 600;
for (var i = 0; i < teams.length; i++) {
var teamBtn = new TeamButton(teams[i].name, teams[i].color);
teamBtn.x = 1024;
teamBtn.y = startY + i * 120;
teamBtn.onPress = function (team) {
return function () {
selectedTeams.push(team);
if (selectedTeams.length === 1) {
team1Name = team.name;
team1Color = team.color;
team1Logo = team.logo;
if (gameMode === 'vsAI') {
// Auto-select second team for AI
var aiTeam = teams[Math.floor(Math.random() * teams.length)];
team2Name = aiTeam.name + ' (AI)';
team2Color = aiTeam.color;
team2Logo = aiTeam.logo;
startGame();
} else {
title.setText('İkinci Takımı Seçin');
}
} else if (selectedTeams.length === 2) {
team2Name = team.name;
team2Color = team.color;
team2Logo = team.logo;
startGame();
}
};
}(teams[i]);
teamContainer.addChild(teamBtn);
}
game.addChild(teamContainer);
}
function startGame() {
gameState = 'playing';
teamContainer.removeChildren();
// Create field
field = game.attachAsset('field', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
});
// Create goals
var topGoal = game.attachAsset('goal', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 166
});
var bottomGoal = game.attachAsset('goal', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 2566
});
goals.push(topGoal, bottomGoal);
// Create goal posts for top goal
var topLeftPost = game.attachAsset('goalPost', {
anchorX: 0.5,
anchorY: 0.5,
x: 824,
y: 166
});
var topRightPost = game.attachAsset('goalPost', {
anchorX: 0.5,
anchorY: 0.5,
x: 1224,
y: 166
});
// Create goal posts for bottom goal
var bottomLeftPost = game.attachAsset('goalPost', {
anchorX: 0.5,
anchorY: 0.5,
x: 824,
y: 2566
});
var bottomRightPost = game.attachAsset('goalPost', {
anchorX: 0.5,
anchorY: 0.5,
x: 1224,
y: 2566
});
// Create center line
var centerLine = game.attachAsset('centerLine', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
});
// Create penalty areas
var topPenaltyArea = game.attachAsset('penaltyArea', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 316
});
topPenaltyArea.alpha = 0.3;
var bottomPenaltyArea = game.attachAsset('penaltyArea', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 2416
});
bottomPenaltyArea.alpha = 0.3;
// Create center circle
var centerCircle = game.attachAsset('centerCircle', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
});
centerCircle.alpha = 0.3;
// Create ball
ball = new Ball();
ball.x = 1024;
ball.y = 1366;
game.addChild(ball);
// Create players
var player1 = new Player(team1Logo, team1Color);
player1.x = 1024;
player1.y = 1800;
players.push(player1);
game.addChild(player1);
var player2 = new Player(team2Logo, team2Color);
player2.x = 1024;
player2.y = 900;
if (gameMode === 'vsAI') {
player2.isAI = true;
}
players.push(player2);
game.addChild(player2);
// Create scoreboard
createScoreboard();
score1 = 0;
score2 = 0;
}
function createScoreboard() {
var scoreText = new Text2(team1Name + ' 0 - 0 ' + team2Name, {
size: 40,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
scoreboard = scoreText;
updateScoreboard();
}
function updateScoreboard() {
if (scoreboard) {
scoreboard.setText(team1Name + ' ' + score1 + ' - ' + score2 + ' ' + team2Name);
}
}
function checkGoal() {
if (!ball) return;
// Initialize lastY if not set
if (ball.lastY === undefined) {
ball.lastY = ball.y;
return;
}
// Check top goal (team 1 scores) - ball must enter from front (from below), not sides
if (ball.y < 166 && ball.x > 824 && ball.x < 1224 && ball.y > 91) {
// Only count as goal if ball entered from below (lastY was greater than goal line)
if (ball.lastY >= 166) {
score1++;
LK.getSound('goal').play();
resetBallPosition();
updateScoreboard();
}
}
// Check bottom goal (team 2 scores) - ball must enter from front (from above), not sides
if (ball.y > 2566 && ball.x > 824 && ball.x < 1224 && ball.y < 2641) {
// Only count as goal if ball entered from above (lastY was less than goal line)
if (ball.lastY <= 2566) {
score2++;
LK.getSound('goal').play();
resetBallPosition();
updateScoreboard();
}
}
// Update lastY for next frame
ball.lastY = ball.y;
}
function resetBallPosition() {
if (ball) {
ball.x = 1024;
ball.y = 1366;
ball.velocityX = 0;
ball.velocityY = 0;
ball.lastY = 1366; // Reset lastY tracking
}
}
function clearGame() {
if (ball) {
ball.destroy();
ball = null;
}
for (var i = 0; i < players.length; i++) {
players[i].destroy();
}
players = [];
if (field) {
field.destroy();
field = null;
}
for (var i = 0; i < goals.length; i++) {
goals[i].destroy();
}
goals = [];
if (scoreboard) {
scoreboard.destroy();
scoreboard = null;
}
}
// Global variables for tracking player control
var activePlayer = null;
var player1Active = false;
var player2Active = false;
// Game event handlers
game.down = function (x, y, obj) {
if (gameState !== 'playing') return;
// Determine which player should be controlled based on touch position
if (players.length >= 2) {
var distToPlayer1 = Math.sqrt((x - players[0].x) * (x - players[0].x) + (y - players[0].y) * (y - players[0].y));
var distToPlayer2 = Math.sqrt((x - players[1].x) * (x - players[1].x) + (y - players[1].y) * (y - players[1].y));
if (gameMode === 'twoPlayer') {
// In two player mode, closest player gets controlled
if (distToPlayer1 < distToPlayer2) {
activePlayer = players[0];
player1Active = true;
player2Active = false;
} else {
activePlayer = players[1];
player1Active = false;
player2Active = true;
}
} else {
// In vs AI mode, only player 1 can be controlled
if (!players[0].isAI) {
activePlayer = players[0];
player1Active = true;
player2Active = false;
}
}
if (activePlayer && !activePlayer.isAI) {
activePlayer.targetX = x;
activePlayer.targetY = y;
}
}
};
game.move = function (x, y, obj) {
if (gameState !== 'playing' || !activePlayer || activePlayer.isAI) return;
activePlayer.x = x;
activePlayer.y = y;
// Kick ball if close
if (ball) {
var dx = ball.x - activePlayer.x;
var dy = ball.y - activePlayer.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance < 80) {
ball.kick(dx * 0.5, dy * 0.5);
}
}
};
game.up = function (x, y, obj) {
activePlayer = null;
player1Active = false;
player2Active = false;
};
game.update = function () {
if (gameState === 'playing') {
checkGoal();
}
};
// Initialize game
showMainMenu(); ===================================================================
--- original.js
+++ change.js
@@ -80,16 +80,24 @@
}
};
return self;
});
-var Player = Container.expand(function (color) {
+var Player = Container.expand(function (teamLogo, fallbackColor) {
var self = Container.call(this);
- var playerGraphics = self.attachAsset('player', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- if (color) {
- playerGraphics.tint = color;
+ var playerGraphics;
+ if (teamLogo) {
+ playerGraphics = self.attachAsset(teamLogo, {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ } else {
+ playerGraphics = self.attachAsset('player', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ if (fallbackColor) {
+ playerGraphics.tint = fallbackColor;
+ }
}
self.isAI = false;
self.targetX = 0;
self.targetY = 0;
@@ -170,16 +178,19 @@
/****
* Game Code
****/
+// Team logo assets
// Game state variables
var gameState = 'mainMenu'; // mainMenu, leagueSelect, teamSelect, playing
var gameMode = ''; // 'twoPlayer' or 'vsAI'
var selectedLeague = '';
var team1Name = '';
var team2Name = '';
var team1Color = 0xFF0000;
var team2Color = 0x0000FF;
+var team1Logo = '';
+var team2Logo = '';
var score1 = 0;
var score2 = 0;
// Game objects
var ball = null;
@@ -189,28 +200,35 @@
var scoreboard = null;
// Team data
var superLigTeams = [{
name: 'Galatasaray',
- color: 0xFFFF00
+ color: 0xFFFF00,
+ logo: 'galatasaray'
}, {
name: 'Fenerbahçe',
- color: 0x000080
+ color: 0x000080,
+ logo: 'fenerbahce'
}, {
name: 'Beşiktaş',
- color: 0x000000
+ color: 0x000000,
+ logo: 'besiktas'
}, {
name: 'Trabzonspor',
- color: 0x800000
+ color: 0x800000,
+ logo: 'trabzonspor'
}, {
name: 'Başakşehir',
- color: 0xFF8000
+ color: 0xFF8000,
+ logo: 'basaksehir'
}];
var laLigaTeams = [{
name: 'Real Madrid',
- color: 0xFFFFFF
+ color: 0xFFFFFF,
+ logo: 'realmadrid'
}, {
name: 'Barcelona',
- color: 0x004A9F
+ color: 0x004A9F,
+ logo: 'barcelona'
}];
// UI elements
var menuContainer = new Container();
var leagueContainer = new Container();
@@ -304,20 +322,23 @@
selectedTeams.push(team);
if (selectedTeams.length === 1) {
team1Name = team.name;
team1Color = team.color;
+ team1Logo = team.logo;
if (gameMode === 'vsAI') {
// Auto-select second team for AI
var aiTeam = teams[Math.floor(Math.random() * teams.length)];
team2Name = aiTeam.name + ' (AI)';
team2Color = aiTeam.color;
+ team2Logo = aiTeam.logo;
startGame();
} else {
title.setText('İkinci Takımı Seçin');
}
} else if (selectedTeams.length === 2) {
team2Name = team.name;
team2Color = team.color;
+ team2Logo = team.logo;
startGame();
}
};
}(teams[i]);
@@ -410,14 +431,14 @@
ball.x = 1024;
ball.y = 1366;
game.addChild(ball);
// Create players
- var player1 = new Player(team1Color);
+ var player1 = new Player(team1Logo, team1Color);
player1.x = 1024;
player1.y = 1800;
players.push(player1);
game.addChild(player1);
- var player2 = new Player(team2Color);
+ var player2 = new Player(team2Logo, team2Color);
player2.x = 1024;
player2.y = 900;
if (gameMode === 'vsAI') {
player2.isAI = true;