/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Club = Container.expand(function () {
var self = Container.call(this);
var cardGraphics = self.attachAsset('clubCard', {
anchorX: 0.5,
anchorY: 0.5
});
self.clubName = "";
self.league = "";
self.points = 0;
self.wins = 0;
self.draws = 0;
self.losses = 0;
self.goalsFor = 0;
self.goalsAgainst = 0;
self.players = [];
self.budget = 50000000;
self.isPlayerClub = false;
self.nameText = new Text2('', {
size: 24,
fill: 0xFFFFFF
});
self.nameText.anchor.set(0.5, 0.5);
self.nameText.x = 0;
self.nameText.y = -40;
self.addChild(self.nameText);
self.statsText = new Text2('', {
size: 16,
fill: 0xFFFFFF
});
self.statsText.anchor.set(0.5, 0.5);
self.statsText.x = 0;
self.statsText.y = 20;
self.addChild(self.statsText);
self.setClubData = function (name, league) {
self.clubName = name;
self.league = league;
self.nameText.setText(name);
self.updateStats();
};
self.updateStats = function () {
var text = "P: " + self.points + " W: " + self.wins + " D: " + self.draws + " L: " + self.losses;
self.statsText.setText(text);
};
self.addPoints = function (points) {
self.points += points;
if (points === 3) self.wins++;else if (points === 1) self.draws++;else self.losses++;
self.updateStats();
};
self.down = function (x, y, obj) {
if (!self.isPlayerClub && gameState === 'club_selection') {
selectClub(self);
}
};
return self;
});
var MatchSimulator = Container.expand(function () {
var self = Container.call(this);
var pitchGraphics = self.attachAsset('pitch', {
anchorX: 0.5,
anchorY: 0.5
});
self.homeTeam = null;
self.awayTeam = null;
self.homeScore = 0;
self.awayScore = 0;
self.isSimulating = false;
self.scoreText = new Text2('0 - 0', {
size: 48,
fill: 0xFFFFFF
});
self.scoreText.anchor.set(0.5, 0.5);
self.scoreText.x = 0;
self.scoreText.y = -500;
self.addChild(self.scoreText);
self.teamText = new Text2('', {
size: 32,
fill: 0xFFFFFF
});
self.teamText.anchor.set(0.5, 0.5);
self.teamText.x = 0;
self.teamText.y = -450;
self.addChild(self.teamText);
self.statusText = new Text2('', {
size: 24,
fill: 0xFFFF00
});
self.statusText.anchor.set(0.5, 0.5);
self.statusText.x = 0;
self.statusText.y = 400;
self.addChild(self.statusText);
self.setupMatch = function (homeTeam, awayTeam) {
self.homeTeam = homeTeam;
self.awayTeam = awayTeam;
self.homeScore = 0;
self.awayScore = 0;
self.teamText.setText(homeTeam.clubName + " vs " + awayTeam.clubName);
self.scoreText.setText("0 - 0");
self.statusText.setText("Match Starting...");
};
self.simulateMatch = function () {
if (self.isSimulating) return;
self.isSimulating = true;
LK.getSound('whistle').play();
var matchTimer = 0;
var matchDuration = 90;
var simulationTimer = LK.setInterval(function () {
matchTimer += 5;
self.statusText.setText("Minute " + matchTimer);
// Random goal chance
if (Math.random() < 0.15) {
var isHomeGoal = Math.random() < 0.5;
if (isHomeGoal) {
self.homeScore++;
self.homeTeam.goalsFor++;
self.awayTeam.goalsAgainst++;
} else {
self.awayScore++;
self.awayTeam.goalsFor++;
self.homeTeam.goalsAgainst++;
}
self.scoreText.setText(self.homeScore + " - " + self.awayScore);
LK.getSound('goal').play();
LK.effects.flashScreen(0x00ff00, 500);
}
if (matchTimer >= matchDuration) {
LK.clearInterval(simulationTimer);
self.finishMatch();
}
}, 200);
};
self.finishMatch = function () {
self.isSimulating = false;
self.statusText.setText("Full Time!");
// Award points
if (self.homeScore > self.awayScore) {
self.homeTeam.addPoints(3);
self.awayTeam.addPoints(0);
} else if (self.awayScore > self.homeScore) {
self.awayTeam.addPoints(3);
self.homeTeam.addPoints(0);
} else {
self.homeTeam.addPoints(1);
self.awayTeam.addPoints(1);
}
LK.getSound('whistle').play();
// Return to main menu after delay
LK.setTimeout(function () {
gameState = 'main_menu';
showMainMenu();
}, 2000);
};
self.down = function (x, y, obj) {
if (!self.isSimulating) {
self.simulateMatch();
}
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var cardGraphics = self.attachAsset('playerCard', {
anchorX: 0.5,
anchorY: 0.5
});
self.playerName = "";
self.position = "";
self.rating = 70;
self.age = 25;
self.value = 1000000;
self.nameText = new Text2('', {
size: 20,
fill: 0xFFFFFF
});
self.nameText.anchor.set(0.5, 0.5);
self.nameText.x = 0;
self.nameText.y = -30;
self.addChild(self.nameText);
self.detailsText = new Text2('', {
size: 14,
fill: 0xFFFFFF
});
self.detailsText.anchor.set(0.5, 0.5);
self.detailsText.x = 0;
self.detailsText.y = 10;
self.addChild(self.detailsText);
self.setPlayerData = function (name, position, rating, age, value) {
self.playerName = name;
self.position = position;
self.rating = rating;
self.age = age;
self.value = value;
self.nameText.setText(name);
self.detailsText.setText(position + " | " + rating + " | Age " + age);
};
return self;
});
var Tournament = Container.expand(function () {
var self = Container.call(this);
self.tournamentName = "";
self.participants = [];
self.currentRound = 0;
self.maxRounds = 4; // Round of 16, Quarter, Semi, Final
var badgeGraphics = self.attachAsset('tournamentBadge', {
anchorX: 0.5,
anchorY: 0.5
});
self.nameText = new Text2('', {
size: 20,
fill: 0x000000
});
self.nameText.anchor.set(0.5, 0.5);
self.nameText.x = 0;
self.nameText.y = 0;
self.addChild(self.nameText);
self.setupTournament = function (name, teams) {
self.tournamentName = name;
self.participants = teams.slice();
self.currentRound = 0;
self.nameText.setText(name);
};
self.down = function (x, y, obj) {
if (gameState === 'tournament_view') {
// Start tournament matches
currentTournament = self;
startTournamentMatch();
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1a1a2e
});
/****
* Game Code
****/
var gameState = 'league_selection';
var selectedLeague = null;
var playerClub = null;
var currentSeason = 1;
var currentMatchday = 1;
var maxMatchdays = 20;
// League data
var leagues = [{
name: "Premier League",
country: "England",
clubs: ["Manchester City", "Arsenal", "Liverpool", "Chelsea", "Newcastle", "Manchester United", "Tottenham", "Brighton", "Aston Villa", "West Ham"]
}, {
name: "La Liga",
country: "Spain",
clubs: ["Real Madrid", "Barcelona", "Atletico Madrid", "Real Sociedad", "Villarreal", "Real Betis", "Valencia", "Athletic Bilbao", "Sevilla", "Osasuna"]
}, {
name: "Serie A",
country: "Italy",
clubs: ["Napoli", "Inter Milan", "AC Milan", "Juventus", "Atalanta", "Roma", "Lazio", "Fiorentina", "Bologna", "Torino"]
}, {
name: "Bundesliga",
country: "Germany",
clubs: ["Bayern Munich", "Borussia Dortmund", "RB Leipzig", "Union Berlin", "Freiburg", "Bayer Leverkusen", "Eintracht Frankfurt", "Wolfsburg", "Mainz", "Hoffenheim"]
}, {
name: "Ligue 1",
country: "France",
clubs: ["PSG", "Lens", "Marseille", "Monaco", "Rennes", "Lille", "Lyon", "Nice", "Clermont", "Toulouse"]
}, {
name: "MLS",
country: "USA",
clubs: ["LAFC", "Philadelphia Union", "CF Montreal", "New York City FC", "Austin FC", "Real Salt Lake", "Nashville SC", "Orlando City", "Atlanta United", "Portland Timbers"]
}];
var clubs = [];
var tournaments = [];
var currentTournament = null;
// UI Elements
var titleText = new Text2('Global Football Manager Championship', {
size: 48,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0);
titleText.x = 1024;
titleText.y = 200;
LK.gui.center.addChild(titleText);
var statusText = new Text2('Select a League', {
size: 32,
fill: 0xFFFFFF
});
statusText.anchor.set(0.5, 0);
statusText.x = 1024;
statusText.y = 300;
LK.gui.center.addChild(statusText);
var seasonText = new Text2('Season 1', {
size: 24,
fill: 0xFFFFFF
});
seasonText.anchor.set(1, 0);
LK.gui.topRight.addChild(seasonText);
// Initialize leagues display
function showLeagueSelection() {
gameState = 'league_selection';
statusText.setText('Select a League');
// Clear existing clubs
for (var i = clubs.length - 1; i >= 0; i--) {
clubs[i].destroy();
clubs.splice(i, 1);
}
// Create league selection buttons
for (var i = 0; i < leagues.length; i++) {
var league = leagues[i];
var leagueButton = game.addChild(LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5
}));
leagueButton.x = 400 + i % 3 * 400;
leagueButton.y = 600 + Math.floor(i / 3) * 150;
leagueButton.leagueData = league;
var buttonText = new Text2(league.name, {
size: 18,
fill: 0xFFFFFF
});
buttonText.anchor.set(0.5, 0.5);
leagueButton.addChild(buttonText);
leagueButton.down = function (x, y, obj) {
selectedLeague = obj.leagueData;
showClubSelection();
};
clubs.push(leagueButton);
}
}
function showClubSelection() {
gameState = 'club_selection';
if (selectedLeague && selectedLeague.name) {
statusText.setText('Choose Your Club - ' + selectedLeague.name);
} else {
statusText.setText('Choose Your Club');
}
// Clear existing displays
for (var i = clubs.length - 1; i >= 0; i--) {
clubs[i].destroy();
clubs.splice(i, 1);
}
// Create clubs for selected league
if (selectedLeague && selectedLeague.clubs) {
for (var i = 0; i < selectedLeague.clubs.length; i++) {
var club = game.addChild(new Club());
club.setClubData(selectedLeague.clubs[i], selectedLeague.name);
club.x = 300 + i % 4 * 350;
club.y = 500 + Math.floor(i / 4) * 250;
clubs.push(club);
}
}
}
function selectClub(selectedClub) {
playerClub = selectedClub;
playerClub.isPlayerClub = true;
// Generate random stats for all clubs
for (var i = 0; i < clubs.length; i++) {
clubs[i].points = Math.floor(Math.random() * 30);
clubs[i].wins = Math.floor(clubs[i].points / 3);
clubs[i].draws = Math.max(0, clubs[i].points - clubs[i].wins * 3);
clubs[i].losses = Math.floor(Math.random() * 10);
clubs[i].goalsFor = Math.floor(Math.random() * 30) + 10;
clubs[i].goalsAgainst = Math.floor(Math.random() * 25) + 5;
clubs[i].updateStats();
}
showMainMenu();
}
function showMainMenu() {
gameState = 'main_menu';
statusText.setText('Club: ' + playerClub.clubName + ' | Matchday ' + currentMatchday + '/' + maxMatchdays);
// Clear previous displays
for (var i = clubs.length - 1; i >= 0; i--) {
clubs[i].destroy();
clubs.splice(i, 1);
}
// Recreate all clubs for the selected league
if (selectedLeague && selectedLeague.clubs) {
for (var i = 0; i < selectedLeague.clubs.length; i++) {
var club = game.addChild(new Club());
club.setClubData(selectedLeague.clubs[i], selectedLeague.name);
// Set the player's club
if (selectedLeague.clubs[i] === playerClub.clubName) {
club.isPlayerClub = true;
club.points = playerClub.points;
club.wins = playerClub.wins;
club.draws = playerClub.draws;
club.losses = playerClub.losses;
club.goalsFor = playerClub.goalsFor;
club.goalsAgainst = playerClub.goalsAgainst;
playerClub = club;
} else {
// Generate random stats for AI clubs
club.points = Math.floor(Math.random() * 30);
club.wins = Math.floor(club.points / 3);
club.draws = Math.max(0, club.points - club.wins * 3);
club.losses = Math.floor(Math.random() * 10);
club.goalsFor = Math.floor(Math.random() * 30) + 10;
club.goalsAgainst = Math.floor(Math.random() * 25) + 5;
}
club.updateStats();
// Position clubs off-screen (they're not meant to be visible in main menu)
club.x = -1000;
club.y = -1000;
clubs.push(club);
}
}
// Create main menu buttons
var playMatchButton = game.addChild(LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5
}));
playMatchButton.x = 500;
playMatchButton.y = 800;
var playMatchText = new Text2('Play Next Match', {
size: 20,
fill: 0xFFFFFF
});
playMatchText.anchor.set(0.5, 0.5);
playMatchButton.addChild(playMatchText);
playMatchButton.down = function (x, y, obj) {
startLeagueMatch();
};
var tournamentsButton = game.addChild(LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5
}));
tournamentsButton.x = 800;
tournamentsButton.y = 800;
var tournamentsText = new Text2('Tournaments', {
size: 20,
fill: 0xFFFFFF
});
tournamentsText.anchor.set(0.5, 0.5);
tournamentsButton.addChild(tournamentsText);
tournamentsButton.down = function (x, y, obj) {
showTournaments();
};
var leagueTableButton = game.addChild(LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5
}));
leagueTableButton.x = 1100;
leagueTableButton.y = 800;
var leagueTableText = new Text2('League Table', {
size: 20,
fill: 0xFFFFFF
});
leagueTableText.anchor.set(0.5, 0.5);
leagueTableButton.addChild(leagueTableText);
leagueTableButton.down = function (x, y, obj) {
showLeagueTable();
};
clubs.push(playMatchButton);
clubs.push(tournamentsButton);
clubs.push(leagueTableButton);
}
function startLeagueMatch() {
// Find random opponent
var availableOpponents = clubs.filter(function (club) {
return !club.isPlayerClub;
});
if (availableOpponents.length === 0) return;
var opponent = availableOpponents[Math.floor(Math.random() * availableOpponents.length)];
// Clear UI
for (var i = clubs.length - 1; i >= 0; i--) {
if (!clubs[i].isPlayerClub) {
clubs[i].destroy();
clubs.splice(i, 1);
}
}
// Start match
var matchSim = game.addChild(new MatchSimulator());
matchSim.x = 1024;
matchSim.y = 1366;
matchSim.setupMatch(playerClub, opponent);
currentMatchday++;
if (currentMatchday > maxMatchdays) {
currentMatchday = 1;
currentSeason++;
seasonText.setText('Season ' + currentSeason);
}
gameState = 'match';
}
function showTournaments() {
gameState = 'tournament_view';
statusText.setText('International Tournaments');
// Clear previous displays
for (var i = clubs.length - 1; i >= 0; i--) {
if (!clubs[i].isPlayerClub) {
clubs[i].destroy();
clubs.splice(i, 1);
}
}
// Create tournaments
var tournamentNames = ["Champions League", "Europa League", "Conference League", "Club World Cup"];
for (var i = 0; i < tournamentNames.length; i++) {
var tournament = game.addChild(new Tournament());
tournament.setupTournament(tournamentNames[i], clubs);
tournament.x = 400 + i % 2 * 600;
tournament.y = 700 + Math.floor(i / 2) * 200;
tournaments.push(tournament);
}
var backButton = game.addChild(LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5
}));
backButton.x = 1024;
backButton.y = 1200;
var backText = new Text2('Back to Main Menu', {
size: 20,
fill: 0xFFFFFF
});
backText.anchor.set(0.5, 0.5);
backButton.addChild(backText);
backButton.down = function (x, y, obj) {
// Clear tournaments
for (var i = tournaments.length - 1; i >= 0; i--) {
tournaments[i].destroy();
tournaments.splice(i, 1);
}
backButton.destroy();
showMainMenu();
};
}
function startTournamentMatch() {
if (!currentTournament || currentTournament.participants.length < 2) return;
var opponent = currentTournament.participants[Math.floor(Math.random() * currentTournament.participants.length)];
// Clear UI
for (var i = tournaments.length - 1; i >= 0; i--) {
tournaments[i].destroy();
tournaments.splice(i, 1);
}
// Start tournament match
var matchSim = game.addChild(new MatchSimulator());
matchSim.x = 1024;
matchSim.y = 1366;
matchSim.setupMatch(playerClub, opponent);
gameState = 'tournament_match';
}
function showLeagueTable() {
gameState = 'league_table';
statusText.setText('League Table - ' + selectedLeague.name);
// Sort clubs by points
var sortedClubs = clubs.filter(function (club) {
return club.clubName; // Only clubs, not buttons
}).sort(function (a, b) {
return b.points - a.points;
});
// Clear previous displays
for (var i = clubs.length - 1; i >= 0; i--) {
if (!clubs[i].isPlayerClub && !clubs[i].clubName) {
clubs[i].destroy();
clubs.splice(i, 1);
}
}
// Display league table
for (var i = 0; i < Math.min(sortedClubs.length, 8); i++) {
var club = sortedClubs[i];
var tableEntry = game.addChild(LK.getAsset('matchResult', {
anchorX: 0.5,
anchorY: 0.5
}));
tableEntry.x = 1024;
tableEntry.y = 500 + i * 120;
var entryText = new Text2(i + 1 + ". " + club.clubName + " - " + club.points + " pts", {
size: 22,
fill: 0xFFFFFF
});
entryText.anchor.set(0.5, 0.5);
tableEntry.addChild(entryText);
clubs.push(tableEntry);
}
var backButton = game.addChild(LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5
}));
backButton.x = 1024;
backButton.y = 1500;
var backText = new Text2('Back to Main Menu', {
size: 20,
fill: 0xFFFFFF
});
backText.anchor.set(0.5, 0.5);
backButton.addChild(backText);
backButton.down = function (x, y, obj) {
showMainMenu();
};
clubs.push(backButton);
}
// Initialize game
showLeagueSelection();
game.update = function () {
// Update score display
if (playerClub) {
LK.setScore(playerClub.points);
}
}; /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Club = Container.expand(function () {
var self = Container.call(this);
var cardGraphics = self.attachAsset('clubCard', {
anchorX: 0.5,
anchorY: 0.5
});
self.clubName = "";
self.league = "";
self.points = 0;
self.wins = 0;
self.draws = 0;
self.losses = 0;
self.goalsFor = 0;
self.goalsAgainst = 0;
self.players = [];
self.budget = 50000000;
self.isPlayerClub = false;
self.nameText = new Text2('', {
size: 24,
fill: 0xFFFFFF
});
self.nameText.anchor.set(0.5, 0.5);
self.nameText.x = 0;
self.nameText.y = -40;
self.addChild(self.nameText);
self.statsText = new Text2('', {
size: 16,
fill: 0xFFFFFF
});
self.statsText.anchor.set(0.5, 0.5);
self.statsText.x = 0;
self.statsText.y = 20;
self.addChild(self.statsText);
self.setClubData = function (name, league) {
self.clubName = name;
self.league = league;
self.nameText.setText(name);
self.updateStats();
};
self.updateStats = function () {
var text = "P: " + self.points + " W: " + self.wins + " D: " + self.draws + " L: " + self.losses;
self.statsText.setText(text);
};
self.addPoints = function (points) {
self.points += points;
if (points === 3) self.wins++;else if (points === 1) self.draws++;else self.losses++;
self.updateStats();
};
self.down = function (x, y, obj) {
if (!self.isPlayerClub && gameState === 'club_selection') {
selectClub(self);
}
};
return self;
});
var MatchSimulator = Container.expand(function () {
var self = Container.call(this);
var pitchGraphics = self.attachAsset('pitch', {
anchorX: 0.5,
anchorY: 0.5
});
self.homeTeam = null;
self.awayTeam = null;
self.homeScore = 0;
self.awayScore = 0;
self.isSimulating = false;
self.scoreText = new Text2('0 - 0', {
size: 48,
fill: 0xFFFFFF
});
self.scoreText.anchor.set(0.5, 0.5);
self.scoreText.x = 0;
self.scoreText.y = -500;
self.addChild(self.scoreText);
self.teamText = new Text2('', {
size: 32,
fill: 0xFFFFFF
});
self.teamText.anchor.set(0.5, 0.5);
self.teamText.x = 0;
self.teamText.y = -450;
self.addChild(self.teamText);
self.statusText = new Text2('', {
size: 24,
fill: 0xFFFF00
});
self.statusText.anchor.set(0.5, 0.5);
self.statusText.x = 0;
self.statusText.y = 400;
self.addChild(self.statusText);
self.setupMatch = function (homeTeam, awayTeam) {
self.homeTeam = homeTeam;
self.awayTeam = awayTeam;
self.homeScore = 0;
self.awayScore = 0;
self.teamText.setText(homeTeam.clubName + " vs " + awayTeam.clubName);
self.scoreText.setText("0 - 0");
self.statusText.setText("Match Starting...");
};
self.simulateMatch = function () {
if (self.isSimulating) return;
self.isSimulating = true;
LK.getSound('whistle').play();
var matchTimer = 0;
var matchDuration = 90;
var simulationTimer = LK.setInterval(function () {
matchTimer += 5;
self.statusText.setText("Minute " + matchTimer);
// Random goal chance
if (Math.random() < 0.15) {
var isHomeGoal = Math.random() < 0.5;
if (isHomeGoal) {
self.homeScore++;
self.homeTeam.goalsFor++;
self.awayTeam.goalsAgainst++;
} else {
self.awayScore++;
self.awayTeam.goalsFor++;
self.homeTeam.goalsAgainst++;
}
self.scoreText.setText(self.homeScore + " - " + self.awayScore);
LK.getSound('goal').play();
LK.effects.flashScreen(0x00ff00, 500);
}
if (matchTimer >= matchDuration) {
LK.clearInterval(simulationTimer);
self.finishMatch();
}
}, 200);
};
self.finishMatch = function () {
self.isSimulating = false;
self.statusText.setText("Full Time!");
// Award points
if (self.homeScore > self.awayScore) {
self.homeTeam.addPoints(3);
self.awayTeam.addPoints(0);
} else if (self.awayScore > self.homeScore) {
self.awayTeam.addPoints(3);
self.homeTeam.addPoints(0);
} else {
self.homeTeam.addPoints(1);
self.awayTeam.addPoints(1);
}
LK.getSound('whistle').play();
// Return to main menu after delay
LK.setTimeout(function () {
gameState = 'main_menu';
showMainMenu();
}, 2000);
};
self.down = function (x, y, obj) {
if (!self.isSimulating) {
self.simulateMatch();
}
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var cardGraphics = self.attachAsset('playerCard', {
anchorX: 0.5,
anchorY: 0.5
});
self.playerName = "";
self.position = "";
self.rating = 70;
self.age = 25;
self.value = 1000000;
self.nameText = new Text2('', {
size: 20,
fill: 0xFFFFFF
});
self.nameText.anchor.set(0.5, 0.5);
self.nameText.x = 0;
self.nameText.y = -30;
self.addChild(self.nameText);
self.detailsText = new Text2('', {
size: 14,
fill: 0xFFFFFF
});
self.detailsText.anchor.set(0.5, 0.5);
self.detailsText.x = 0;
self.detailsText.y = 10;
self.addChild(self.detailsText);
self.setPlayerData = function (name, position, rating, age, value) {
self.playerName = name;
self.position = position;
self.rating = rating;
self.age = age;
self.value = value;
self.nameText.setText(name);
self.detailsText.setText(position + " | " + rating + " | Age " + age);
};
return self;
});
var Tournament = Container.expand(function () {
var self = Container.call(this);
self.tournamentName = "";
self.participants = [];
self.currentRound = 0;
self.maxRounds = 4; // Round of 16, Quarter, Semi, Final
var badgeGraphics = self.attachAsset('tournamentBadge', {
anchorX: 0.5,
anchorY: 0.5
});
self.nameText = new Text2('', {
size: 20,
fill: 0x000000
});
self.nameText.anchor.set(0.5, 0.5);
self.nameText.x = 0;
self.nameText.y = 0;
self.addChild(self.nameText);
self.setupTournament = function (name, teams) {
self.tournamentName = name;
self.participants = teams.slice();
self.currentRound = 0;
self.nameText.setText(name);
};
self.down = function (x, y, obj) {
if (gameState === 'tournament_view') {
// Start tournament matches
currentTournament = self;
startTournamentMatch();
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1a1a2e
});
/****
* Game Code
****/
var gameState = 'league_selection';
var selectedLeague = null;
var playerClub = null;
var currentSeason = 1;
var currentMatchday = 1;
var maxMatchdays = 20;
// League data
var leagues = [{
name: "Premier League",
country: "England",
clubs: ["Manchester City", "Arsenal", "Liverpool", "Chelsea", "Newcastle", "Manchester United", "Tottenham", "Brighton", "Aston Villa", "West Ham"]
}, {
name: "La Liga",
country: "Spain",
clubs: ["Real Madrid", "Barcelona", "Atletico Madrid", "Real Sociedad", "Villarreal", "Real Betis", "Valencia", "Athletic Bilbao", "Sevilla", "Osasuna"]
}, {
name: "Serie A",
country: "Italy",
clubs: ["Napoli", "Inter Milan", "AC Milan", "Juventus", "Atalanta", "Roma", "Lazio", "Fiorentina", "Bologna", "Torino"]
}, {
name: "Bundesliga",
country: "Germany",
clubs: ["Bayern Munich", "Borussia Dortmund", "RB Leipzig", "Union Berlin", "Freiburg", "Bayer Leverkusen", "Eintracht Frankfurt", "Wolfsburg", "Mainz", "Hoffenheim"]
}, {
name: "Ligue 1",
country: "France",
clubs: ["PSG", "Lens", "Marseille", "Monaco", "Rennes", "Lille", "Lyon", "Nice", "Clermont", "Toulouse"]
}, {
name: "MLS",
country: "USA",
clubs: ["LAFC", "Philadelphia Union", "CF Montreal", "New York City FC", "Austin FC", "Real Salt Lake", "Nashville SC", "Orlando City", "Atlanta United", "Portland Timbers"]
}];
var clubs = [];
var tournaments = [];
var currentTournament = null;
// UI Elements
var titleText = new Text2('Global Football Manager Championship', {
size: 48,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0);
titleText.x = 1024;
titleText.y = 200;
LK.gui.center.addChild(titleText);
var statusText = new Text2('Select a League', {
size: 32,
fill: 0xFFFFFF
});
statusText.anchor.set(0.5, 0);
statusText.x = 1024;
statusText.y = 300;
LK.gui.center.addChild(statusText);
var seasonText = new Text2('Season 1', {
size: 24,
fill: 0xFFFFFF
});
seasonText.anchor.set(1, 0);
LK.gui.topRight.addChild(seasonText);
// Initialize leagues display
function showLeagueSelection() {
gameState = 'league_selection';
statusText.setText('Select a League');
// Clear existing clubs
for (var i = clubs.length - 1; i >= 0; i--) {
clubs[i].destroy();
clubs.splice(i, 1);
}
// Create league selection buttons
for (var i = 0; i < leagues.length; i++) {
var league = leagues[i];
var leagueButton = game.addChild(LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5
}));
leagueButton.x = 400 + i % 3 * 400;
leagueButton.y = 600 + Math.floor(i / 3) * 150;
leagueButton.leagueData = league;
var buttonText = new Text2(league.name, {
size: 18,
fill: 0xFFFFFF
});
buttonText.anchor.set(0.5, 0.5);
leagueButton.addChild(buttonText);
leagueButton.down = function (x, y, obj) {
selectedLeague = obj.leagueData;
showClubSelection();
};
clubs.push(leagueButton);
}
}
function showClubSelection() {
gameState = 'club_selection';
if (selectedLeague && selectedLeague.name) {
statusText.setText('Choose Your Club - ' + selectedLeague.name);
} else {
statusText.setText('Choose Your Club');
}
// Clear existing displays
for (var i = clubs.length - 1; i >= 0; i--) {
clubs[i].destroy();
clubs.splice(i, 1);
}
// Create clubs for selected league
if (selectedLeague && selectedLeague.clubs) {
for (var i = 0; i < selectedLeague.clubs.length; i++) {
var club = game.addChild(new Club());
club.setClubData(selectedLeague.clubs[i], selectedLeague.name);
club.x = 300 + i % 4 * 350;
club.y = 500 + Math.floor(i / 4) * 250;
clubs.push(club);
}
}
}
function selectClub(selectedClub) {
playerClub = selectedClub;
playerClub.isPlayerClub = true;
// Generate random stats for all clubs
for (var i = 0; i < clubs.length; i++) {
clubs[i].points = Math.floor(Math.random() * 30);
clubs[i].wins = Math.floor(clubs[i].points / 3);
clubs[i].draws = Math.max(0, clubs[i].points - clubs[i].wins * 3);
clubs[i].losses = Math.floor(Math.random() * 10);
clubs[i].goalsFor = Math.floor(Math.random() * 30) + 10;
clubs[i].goalsAgainst = Math.floor(Math.random() * 25) + 5;
clubs[i].updateStats();
}
showMainMenu();
}
function showMainMenu() {
gameState = 'main_menu';
statusText.setText('Club: ' + playerClub.clubName + ' | Matchday ' + currentMatchday + '/' + maxMatchdays);
// Clear previous displays
for (var i = clubs.length - 1; i >= 0; i--) {
clubs[i].destroy();
clubs.splice(i, 1);
}
// Recreate all clubs for the selected league
if (selectedLeague && selectedLeague.clubs) {
for (var i = 0; i < selectedLeague.clubs.length; i++) {
var club = game.addChild(new Club());
club.setClubData(selectedLeague.clubs[i], selectedLeague.name);
// Set the player's club
if (selectedLeague.clubs[i] === playerClub.clubName) {
club.isPlayerClub = true;
club.points = playerClub.points;
club.wins = playerClub.wins;
club.draws = playerClub.draws;
club.losses = playerClub.losses;
club.goalsFor = playerClub.goalsFor;
club.goalsAgainst = playerClub.goalsAgainst;
playerClub = club;
} else {
// Generate random stats for AI clubs
club.points = Math.floor(Math.random() * 30);
club.wins = Math.floor(club.points / 3);
club.draws = Math.max(0, club.points - club.wins * 3);
club.losses = Math.floor(Math.random() * 10);
club.goalsFor = Math.floor(Math.random() * 30) + 10;
club.goalsAgainst = Math.floor(Math.random() * 25) + 5;
}
club.updateStats();
// Position clubs off-screen (they're not meant to be visible in main menu)
club.x = -1000;
club.y = -1000;
clubs.push(club);
}
}
// Create main menu buttons
var playMatchButton = game.addChild(LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5
}));
playMatchButton.x = 500;
playMatchButton.y = 800;
var playMatchText = new Text2('Play Next Match', {
size: 20,
fill: 0xFFFFFF
});
playMatchText.anchor.set(0.5, 0.5);
playMatchButton.addChild(playMatchText);
playMatchButton.down = function (x, y, obj) {
startLeagueMatch();
};
var tournamentsButton = game.addChild(LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5
}));
tournamentsButton.x = 800;
tournamentsButton.y = 800;
var tournamentsText = new Text2('Tournaments', {
size: 20,
fill: 0xFFFFFF
});
tournamentsText.anchor.set(0.5, 0.5);
tournamentsButton.addChild(tournamentsText);
tournamentsButton.down = function (x, y, obj) {
showTournaments();
};
var leagueTableButton = game.addChild(LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5
}));
leagueTableButton.x = 1100;
leagueTableButton.y = 800;
var leagueTableText = new Text2('League Table', {
size: 20,
fill: 0xFFFFFF
});
leagueTableText.anchor.set(0.5, 0.5);
leagueTableButton.addChild(leagueTableText);
leagueTableButton.down = function (x, y, obj) {
showLeagueTable();
};
clubs.push(playMatchButton);
clubs.push(tournamentsButton);
clubs.push(leagueTableButton);
}
function startLeagueMatch() {
// Find random opponent
var availableOpponents = clubs.filter(function (club) {
return !club.isPlayerClub;
});
if (availableOpponents.length === 0) return;
var opponent = availableOpponents[Math.floor(Math.random() * availableOpponents.length)];
// Clear UI
for (var i = clubs.length - 1; i >= 0; i--) {
if (!clubs[i].isPlayerClub) {
clubs[i].destroy();
clubs.splice(i, 1);
}
}
// Start match
var matchSim = game.addChild(new MatchSimulator());
matchSim.x = 1024;
matchSim.y = 1366;
matchSim.setupMatch(playerClub, opponent);
currentMatchday++;
if (currentMatchday > maxMatchdays) {
currentMatchday = 1;
currentSeason++;
seasonText.setText('Season ' + currentSeason);
}
gameState = 'match';
}
function showTournaments() {
gameState = 'tournament_view';
statusText.setText('International Tournaments');
// Clear previous displays
for (var i = clubs.length - 1; i >= 0; i--) {
if (!clubs[i].isPlayerClub) {
clubs[i].destroy();
clubs.splice(i, 1);
}
}
// Create tournaments
var tournamentNames = ["Champions League", "Europa League", "Conference League", "Club World Cup"];
for (var i = 0; i < tournamentNames.length; i++) {
var tournament = game.addChild(new Tournament());
tournament.setupTournament(tournamentNames[i], clubs);
tournament.x = 400 + i % 2 * 600;
tournament.y = 700 + Math.floor(i / 2) * 200;
tournaments.push(tournament);
}
var backButton = game.addChild(LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5
}));
backButton.x = 1024;
backButton.y = 1200;
var backText = new Text2('Back to Main Menu', {
size: 20,
fill: 0xFFFFFF
});
backText.anchor.set(0.5, 0.5);
backButton.addChild(backText);
backButton.down = function (x, y, obj) {
// Clear tournaments
for (var i = tournaments.length - 1; i >= 0; i--) {
tournaments[i].destroy();
tournaments.splice(i, 1);
}
backButton.destroy();
showMainMenu();
};
}
function startTournamentMatch() {
if (!currentTournament || currentTournament.participants.length < 2) return;
var opponent = currentTournament.participants[Math.floor(Math.random() * currentTournament.participants.length)];
// Clear UI
for (var i = tournaments.length - 1; i >= 0; i--) {
tournaments[i].destroy();
tournaments.splice(i, 1);
}
// Start tournament match
var matchSim = game.addChild(new MatchSimulator());
matchSim.x = 1024;
matchSim.y = 1366;
matchSim.setupMatch(playerClub, opponent);
gameState = 'tournament_match';
}
function showLeagueTable() {
gameState = 'league_table';
statusText.setText('League Table - ' + selectedLeague.name);
// Sort clubs by points
var sortedClubs = clubs.filter(function (club) {
return club.clubName; // Only clubs, not buttons
}).sort(function (a, b) {
return b.points - a.points;
});
// Clear previous displays
for (var i = clubs.length - 1; i >= 0; i--) {
if (!clubs[i].isPlayerClub && !clubs[i].clubName) {
clubs[i].destroy();
clubs.splice(i, 1);
}
}
// Display league table
for (var i = 0; i < Math.min(sortedClubs.length, 8); i++) {
var club = sortedClubs[i];
var tableEntry = game.addChild(LK.getAsset('matchResult', {
anchorX: 0.5,
anchorY: 0.5
}));
tableEntry.x = 1024;
tableEntry.y = 500 + i * 120;
var entryText = new Text2(i + 1 + ". " + club.clubName + " - " + club.points + " pts", {
size: 22,
fill: 0xFFFFFF
});
entryText.anchor.set(0.5, 0.5);
tableEntry.addChild(entryText);
clubs.push(tableEntry);
}
var backButton = game.addChild(LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5
}));
backButton.x = 1024;
backButton.y = 1500;
var backText = new Text2('Back to Main Menu', {
size: 20,
fill: 0xFFFFFF
});
backText.anchor.set(0.5, 0.5);
backButton.addChild(backText);
backButton.down = function (x, y, obj) {
showMainMenu();
};
clubs.push(backButton);
}
// Initialize game
showLeagueSelection();
game.update = function () {
// Update score display
if (playerClub) {
LK.setScore(playerClub.points);
}
};