/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Club class var Club = Container.expand(function () { var self = Container.call(this); var clubArt = self.attachAsset('club', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () {}; return self; }); // Player class var Player = Container.expand(function () { var self = Container.call(this); var playerArt = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () {}; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x0a1a2f }); /**** * Game Code ****/ // --- Data --- // Shapes for player, club, and trophy var positions = [{ key: 'GK', name: 'Goalkeeper' }, { key: 'DEF', name: 'Defender' }, { key: 'MID', name: 'Midfielder' }, { key: 'FWD', name: 'Forward' }]; var clubs = ["Galatasaray", "Fenerbahçe", "Beşiktaş", "Trabzonspor", "Başakşehir", "Bursaspor", "Inter Miami", "Al Nassr", "Real Madrid", "Barcelona", "Manchester United", "Liverpool", "Chelsea", "Bayern Münih", "Juventus", "PSG", "Ajax", "Porto", "Celtic", "Inter", "Zenit", "Club Brugge", "Anderlecht", "Monaco", "Roma", "Milan"]; var trophies = ["Süper Lig", "Türkiye Kupası", "Şampiyonlar Ligi", "UEFA Avrupa Ligi", "La Liga", "Premier Lig", "Bundesliga", "Serie A", "Ligue 1", "Eredivisie"]; // --- State --- var state = "choose_position"; // choose_position, season, transfer, summary var playerPosition = null; var playerPositionName = ""; var playerAge = 18; var playerClub = ""; var playerStats = []; // [{age, club, goals, assists, trophies:[]}] var playerTrophies = []; var playerTotalGoals = 0; var playerTotalAssists = 0; var playerTotalTrophies = 0; var currentSeasonStats = null; var transferOffers = []; var selectedTransfer = null; // --- UI Elements --- var mainContainer = new Container(); game.addChild(mainContainer); var infoText = new Text2("", { size: 90, fill: "#fff" }); infoText.anchor.set(0.5, 0); infoText.y = 0; LK.gui.top.addChild(infoText); var seasonText = new Text2("", { size: 70, fill: "#fff" }); seasonText.anchor.set(0.5, 0); seasonText.y = infoText.height + 10; LK.gui.top.addChild(seasonText); var clubNode = null; var playerNode = null; var trophyNodes = []; var statText = null; var transferButtons = []; var nextButton = null; var summaryText = null; // --- Helper Functions --- function randomInt(min, max) { return min + Math.floor(Math.random() * (max - min + 1)); } function randomPick(arr) { return arr[randomInt(0, arr.length - 1)]; } function clearMainContainer() { while (mainContainer.children.length) { mainContainer.removeChild(mainContainer.children[0]); } } function clearTransferButtons() { for (var i = 0; i < transferButtons.length; i++) { mainContainer.removeChild(transferButtons[i]); } transferButtons = []; } function clearTrophyNodes() { for (var i = 0; i < trophyNodes.length; i++) { mainContainer.removeChild(trophyNodes[i]); } trophyNodes = []; } function showInfo(msg) { // If text is too wide, split into multiple lines infoText.setText(msg); var maxWidth = 2048 - 200; if (infoText.width > maxWidth) { // Try to split by space var words = msg.split(" "); var lines = []; var current = ""; for (var i = 0; i < words.length; i++) { var test = current.length > 0 ? current + " " + words[i] : words[i]; infoText.setText(test); if (infoText.width > maxWidth && current.length > 0) { lines.push(current); current = words[i]; } else { current = test; } } if (current.length > 0) { lines.push(current); } infoText.setText(lines.join("\n")); } } function showSeasonText(msg) { // If text is too wide, split into multiple lines seasonText.setText(msg); var maxWidth = 2048 - 200; if (seasonText.width > maxWidth) { var words = msg.split(" "); var lines = []; var current = ""; for (var i = 0; i < words.length; i++) { var test = current.length > 0 ? current + " " + words[i] : words[i]; seasonText.setText(test); if (seasonText.width > maxWidth && current.length > 0) { lines.push(current); current = words[i]; } else { current = test; } } if (current.length > 0) { lines.push(current); } seasonText.setText(lines.join("\n")); } } function showNextButton(label, cb) { if (nextButton) { mainContainer.removeChild(nextButton); } nextButton = new Text2(label, { size: 80, fill: 0x00FF99 }); nextButton.anchor.set(0.5, 0.5); nextButton.x = 2048 / 2; nextButton.y = 2732 - 300; nextButton.interactive = true; nextButton.buttonMode = true; nextButton.down = function (x, y, obj) { cb(); }; mainContainer.addChild(nextButton); } function hideNextButton() { if (nextButton) { mainContainer.removeChild(nextButton); nextButton = null; } } function showStatText(msg) { if (statText) { mainContainer.removeChild(statText); } statText = new Text2(msg, { size: 70, fill: "#fff" }); statText.anchor.set(0.5, 0.5); statText.x = 2048 / 2; statText.y = 2732 / 2 + 320; mainContainer.addChild(statText); } function hideStatText() { if (statText) { mainContainer.removeChild(statText); statText = null; } } function showSummaryText(msg) { if (summaryText) { mainContainer.removeChild(summaryText); } summaryText = new Text2(msg, { size: 80, fill: "#fff" }); summaryText.anchor.set(0.5, 0.5); summaryText.x = 2048 / 2; summaryText.y = 2732 / 2 + 400; mainContainer.addChild(summaryText); } function hideSummaryText() { if (summaryText) { mainContainer.removeChild(summaryText); summaryText = null; } } // --- Game Flow Functions --- function startChoosePosition() { state = "choose_position"; clearMainContainer(); clearTrophyNodes(); hideStatText(); hideSummaryText(); showInfo("Choose Your Position!"); showSeasonText(""); // Show position buttons var btns = []; for (var i = 0; i < positions.length; i++) { var pos = positions[i]; var btn = new Text2(pos.name, { size: 90, fill: 0x1E90FF }); btn.anchor.set(0.5, 0.5); btn.x = 2048 / 2; btn.y = 800 + i * 220; btn.interactive = true; btn.buttonMode = true; btn.down = function (pos) { return function (x, y, obj) { playerPosition = pos.key; playerPositionName = pos.name; startNewCareer(); }; }(pos); mainContainer.addChild(btn); btns.push(btn); } } function startNewCareer() { state = "season"; playerAge = 18; playerClub = randomPick(clubs); playerStats = []; playerTrophies = []; playerTotalGoals = 0; playerTotalAssists = 0; playerTotalTrophies = 0; clearMainContainer(); clearTrophyNodes(); hideStatText(); hideSummaryText(); showInfo("He begins his career as " + playerPositionName); showSeasonText("Age: " + playerAge + " | " + playerClub); // Show player and club playerNode = new Player(); playerNode.x = 2048 / 2; playerNode.y = 900; mainContainer.addChild(playerNode); clubNode = new Club(); clubNode.x = 2048 / 2; clubNode.y = 1200; mainContainer.addChild(clubNode); var clubNameText = new Text2(playerClub, { size: 90, fill: 0x000000 }); clubNameText.anchor.set(0.5, 0.5); clubNameText.x = clubNode.x; clubNameText.y = clubNode.y; mainContainer.addChild(clubNameText); showNextButton("Start Season", function () { mainContainer.removeChild(playerNode); mainContainer.removeChild(clubNode); mainContainer.removeChild(clubNameText); startSeason(); }); } function startSeason() { state = "season"; clearMainContainer(); clearTrophyNodes(); hideStatText(); hideSummaryText(); showInfo("Age:" + playerAge + " | " + playerClub); showSeasonText("Season: " + (playerAge - 17)); // Show player and club playerNode = new Player(); playerNode.x = 2048 / 2; playerNode.y = 900; mainContainer.addChild(playerNode); clubNode = new Club(); clubNode.x = 2048 / 2; clubNode.y = 1200; mainContainer.addChild(clubNode); var clubNameText = new Text2(playerClub, { size: 90, fill: "#00000" }); clubNameText.anchor.set(0.5, 0.5); clubNameText.x = clubNode.x; clubNameText.y = clubNode.y; mainContainer.addChild(clubNameText); // Random stats var goals = 0, assists = 0; if (playerPosition == "GK") { goals = randomInt(0, 1); assists = randomInt(0, 2); } else if (playerPosition == "DEF") { goals = randomInt(0, 4); assists = randomInt(0, 5); } else if (playerPosition == "MID") { goals = randomInt(2, 10); assists = randomInt(3, 12); } else if (playerPosition == "FWD") { goals = randomInt(5, 30); assists = randomInt(2, 10); } // Trophy chance var wonTrophies = []; if (randomInt(1, 100) <= 20) { // 20% chance var t = randomPick(trophies); wonTrophies.push(t); playerTrophies.push(t); } // Save season stats currentSeasonStats = { age: playerAge, club: playerClub, goals: goals, assists: assists, trophies: wonTrophies }; playerStats.push(currentSeasonStats); playerTotalGoals += goals; playerTotalAssists += assists; playerTotalTrophies += wonTrophies.length; // Show stats var statMsg = "Goals: " + goals + " | Assists: " + assists; if (wonTrophies.length > 0) { statMsg += "\n🏆 " + wonTrophies.join(", "); } showStatText(statMsg); // Show trophies clearTrophyNodes(); // No trophy icons, only text for trophies // Next: transfer offers or retirement showNextButton("End of Season", function () { mainContainer.removeChild(playerNode); mainContainer.removeChild(clubNode); mainContainer.removeChild(clubNameText); hideStatText(); clearTrophyNodes(); if (playerAge >= 35) { startSummary(); } else { startTransfer(); } }); } function startTransfer() { state = "transfer"; clearMainContainer(); clearTrophyNodes(); hideStatText(); hideSummaryText(); showInfo("New Transfer Offers"); showSeasonText("Age: " + playerAge + " | " + playerClub); // Generate 2-3 random offers (not current club) transferOffers = []; var offerCount = randomInt(2, 3); var usedClubs = {}; usedClubs[playerClub] = true; for (var i = 0; i < offerCount; i++) { var c; do { c = randomPick(clubs); } while (usedClubs[c]); usedClubs[c] = true; transferOffers.push(c); } // Add "Stay" option transferOffers.push(playerClub); // Show buttons clearTransferButtons(); for (var i = 0; i < transferOffers.length; i++) { var c = transferOffers[i]; var isStay = c == playerClub; var btn = new Text2(isStay ? "Stay at Club (" + c + ")" : c, { size: 80, fill: isStay ? "#00ff99" : "#fff" }); btn.anchor.set(0.5, 0.5); btn.x = 2048 / 2; btn.y = 900 + i * 180; btn.interactive = true; btn.buttonMode = true; btn.down = function (c) { return function (x, y, obj) { playerClub = c; playerAge += 1; clearTransferButtons(); startSeason(); }; }(c); mainContainer.addChild(btn); transferButtons.push(btn); } } function startSummary() { state = "summary"; clearMainContainer(); clearTrophyNodes(); hideStatText(); showInfo("Career Completed! (Retired)"); showSeasonText(""); // Show player playerNode = new Player(); playerNode.x = 2048 / 2; playerNode.y = 900; mainContainer.addChild(playerNode); // Show summary stats var summaryMsg = "⚽ Total Goals: " + playerTotalGoals + "\n🥅 Total Assists: " + playerTotalAssists + "\n" + "\n🏆 Total Trophies: " + playerTotalTrophies; if (playerTrophies.length > 0) { summaryMsg += "\n" + playerTrophies.join("\n "); } showSummaryText(summaryMsg); // Show "Yeniden Oyna" button showNextButton("Play Again", function () { mainContainer.removeChild(playerNode); hideSummaryText(); startChoosePosition(); }); } // --- Start Game --- startChoosePosition();
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// Club class
var Club = Container.expand(function () {
var self = Container.call(this);
var clubArt = self.attachAsset('club', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {};
return self;
});
// Player class
var Player = Container.expand(function () {
var self = Container.call(this);
var playerArt = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x0a1a2f
});
/****
* Game Code
****/
// --- Data ---
// Shapes for player, club, and trophy
var positions = [{
key: 'GK',
name: 'Goalkeeper'
}, {
key: 'DEF',
name: 'Defender'
}, {
key: 'MID',
name: 'Midfielder'
}, {
key: 'FWD',
name: 'Forward'
}];
var clubs = ["Galatasaray", "Fenerbahçe", "Beşiktaş", "Trabzonspor", "Başakşehir", "Bursaspor", "Inter Miami", "Al Nassr", "Real Madrid", "Barcelona", "Manchester United", "Liverpool", "Chelsea", "Bayern Münih", "Juventus", "PSG", "Ajax", "Porto", "Celtic", "Inter", "Zenit", "Club Brugge", "Anderlecht", "Monaco", "Roma", "Milan"];
var trophies = ["Süper Lig", "Türkiye Kupası", "Şampiyonlar Ligi", "UEFA Avrupa Ligi", "La Liga", "Premier Lig", "Bundesliga", "Serie A", "Ligue 1", "Eredivisie"];
// --- State ---
var state = "choose_position"; // choose_position, season, transfer, summary
var playerPosition = null;
var playerPositionName = "";
var playerAge = 18;
var playerClub = "";
var playerStats = []; // [{age, club, goals, assists, trophies:[]}]
var playerTrophies = [];
var playerTotalGoals = 0;
var playerTotalAssists = 0;
var playerTotalTrophies = 0;
var currentSeasonStats = null;
var transferOffers = [];
var selectedTransfer = null;
// --- UI Elements ---
var mainContainer = new Container();
game.addChild(mainContainer);
var infoText = new Text2("", {
size: 90,
fill: "#fff"
});
infoText.anchor.set(0.5, 0);
infoText.y = 0;
LK.gui.top.addChild(infoText);
var seasonText = new Text2("", {
size: 70,
fill: "#fff"
});
seasonText.anchor.set(0.5, 0);
seasonText.y = infoText.height + 10;
LK.gui.top.addChild(seasonText);
var clubNode = null;
var playerNode = null;
var trophyNodes = [];
var statText = null;
var transferButtons = [];
var nextButton = null;
var summaryText = null;
// --- Helper Functions ---
function randomInt(min, max) {
return min + Math.floor(Math.random() * (max - min + 1));
}
function randomPick(arr) {
return arr[randomInt(0, arr.length - 1)];
}
function clearMainContainer() {
while (mainContainer.children.length) {
mainContainer.removeChild(mainContainer.children[0]);
}
}
function clearTransferButtons() {
for (var i = 0; i < transferButtons.length; i++) {
mainContainer.removeChild(transferButtons[i]);
}
transferButtons = [];
}
function clearTrophyNodes() {
for (var i = 0; i < trophyNodes.length; i++) {
mainContainer.removeChild(trophyNodes[i]);
}
trophyNodes = [];
}
function showInfo(msg) {
// If text is too wide, split into multiple lines
infoText.setText(msg);
var maxWidth = 2048 - 200;
if (infoText.width > maxWidth) {
// Try to split by space
var words = msg.split(" ");
var lines = [];
var current = "";
for (var i = 0; i < words.length; i++) {
var test = current.length > 0 ? current + " " + words[i] : words[i];
infoText.setText(test);
if (infoText.width > maxWidth && current.length > 0) {
lines.push(current);
current = words[i];
} else {
current = test;
}
}
if (current.length > 0) {
lines.push(current);
}
infoText.setText(lines.join("\n"));
}
}
function showSeasonText(msg) {
// If text is too wide, split into multiple lines
seasonText.setText(msg);
var maxWidth = 2048 - 200;
if (seasonText.width > maxWidth) {
var words = msg.split(" ");
var lines = [];
var current = "";
for (var i = 0; i < words.length; i++) {
var test = current.length > 0 ? current + " " + words[i] : words[i];
seasonText.setText(test);
if (seasonText.width > maxWidth && current.length > 0) {
lines.push(current);
current = words[i];
} else {
current = test;
}
}
if (current.length > 0) {
lines.push(current);
}
seasonText.setText(lines.join("\n"));
}
}
function showNextButton(label, cb) {
if (nextButton) {
mainContainer.removeChild(nextButton);
}
nextButton = new Text2(label, {
size: 80,
fill: 0x00FF99
});
nextButton.anchor.set(0.5, 0.5);
nextButton.x = 2048 / 2;
nextButton.y = 2732 - 300;
nextButton.interactive = true;
nextButton.buttonMode = true;
nextButton.down = function (x, y, obj) {
cb();
};
mainContainer.addChild(nextButton);
}
function hideNextButton() {
if (nextButton) {
mainContainer.removeChild(nextButton);
nextButton = null;
}
}
function showStatText(msg) {
if (statText) {
mainContainer.removeChild(statText);
}
statText = new Text2(msg, {
size: 70,
fill: "#fff"
});
statText.anchor.set(0.5, 0.5);
statText.x = 2048 / 2;
statText.y = 2732 / 2 + 320;
mainContainer.addChild(statText);
}
function hideStatText() {
if (statText) {
mainContainer.removeChild(statText);
statText = null;
}
}
function showSummaryText(msg) {
if (summaryText) {
mainContainer.removeChild(summaryText);
}
summaryText = new Text2(msg, {
size: 80,
fill: "#fff"
});
summaryText.anchor.set(0.5, 0.5);
summaryText.x = 2048 / 2;
summaryText.y = 2732 / 2 + 400;
mainContainer.addChild(summaryText);
}
function hideSummaryText() {
if (summaryText) {
mainContainer.removeChild(summaryText);
summaryText = null;
}
}
// --- Game Flow Functions ---
function startChoosePosition() {
state = "choose_position";
clearMainContainer();
clearTrophyNodes();
hideStatText();
hideSummaryText();
showInfo("Choose Your Position!");
showSeasonText("");
// Show position buttons
var btns = [];
for (var i = 0; i < positions.length; i++) {
var pos = positions[i];
var btn = new Text2(pos.name, {
size: 90,
fill: 0x1E90FF
});
btn.anchor.set(0.5, 0.5);
btn.x = 2048 / 2;
btn.y = 800 + i * 220;
btn.interactive = true;
btn.buttonMode = true;
btn.down = function (pos) {
return function (x, y, obj) {
playerPosition = pos.key;
playerPositionName = pos.name;
startNewCareer();
};
}(pos);
mainContainer.addChild(btn);
btns.push(btn);
}
}
function startNewCareer() {
state = "season";
playerAge = 18;
playerClub = randomPick(clubs);
playerStats = [];
playerTrophies = [];
playerTotalGoals = 0;
playerTotalAssists = 0;
playerTotalTrophies = 0;
clearMainContainer();
clearTrophyNodes();
hideStatText();
hideSummaryText();
showInfo("He begins his career as " + playerPositionName);
showSeasonText("Age: " + playerAge + " | " + playerClub);
// Show player and club
playerNode = new Player();
playerNode.x = 2048 / 2;
playerNode.y = 900;
mainContainer.addChild(playerNode);
clubNode = new Club();
clubNode.x = 2048 / 2;
clubNode.y = 1200;
mainContainer.addChild(clubNode);
var clubNameText = new Text2(playerClub, {
size: 90,
fill: 0x000000
});
clubNameText.anchor.set(0.5, 0.5);
clubNameText.x = clubNode.x;
clubNameText.y = clubNode.y;
mainContainer.addChild(clubNameText);
showNextButton("Start Season", function () {
mainContainer.removeChild(playerNode);
mainContainer.removeChild(clubNode);
mainContainer.removeChild(clubNameText);
startSeason();
});
}
function startSeason() {
state = "season";
clearMainContainer();
clearTrophyNodes();
hideStatText();
hideSummaryText();
showInfo("Age:" + playerAge + " | " + playerClub);
showSeasonText("Season: " + (playerAge - 17));
// Show player and club
playerNode = new Player();
playerNode.x = 2048 / 2;
playerNode.y = 900;
mainContainer.addChild(playerNode);
clubNode = new Club();
clubNode.x = 2048 / 2;
clubNode.y = 1200;
mainContainer.addChild(clubNode);
var clubNameText = new Text2(playerClub, {
size: 90,
fill: "#00000"
});
clubNameText.anchor.set(0.5, 0.5);
clubNameText.x = clubNode.x;
clubNameText.y = clubNode.y;
mainContainer.addChild(clubNameText);
// Random stats
var goals = 0,
assists = 0;
if (playerPosition == "GK") {
goals = randomInt(0, 1);
assists = randomInt(0, 2);
} else if (playerPosition == "DEF") {
goals = randomInt(0, 4);
assists = randomInt(0, 5);
} else if (playerPosition == "MID") {
goals = randomInt(2, 10);
assists = randomInt(3, 12);
} else if (playerPosition == "FWD") {
goals = randomInt(5, 30);
assists = randomInt(2, 10);
}
// Trophy chance
var wonTrophies = [];
if (randomInt(1, 100) <= 20) {
// 20% chance
var t = randomPick(trophies);
wonTrophies.push(t);
playerTrophies.push(t);
}
// Save season stats
currentSeasonStats = {
age: playerAge,
club: playerClub,
goals: goals,
assists: assists,
trophies: wonTrophies
};
playerStats.push(currentSeasonStats);
playerTotalGoals += goals;
playerTotalAssists += assists;
playerTotalTrophies += wonTrophies.length;
// Show stats
var statMsg = "Goals: " + goals + " | Assists: " + assists;
if (wonTrophies.length > 0) {
statMsg += "\n🏆 " + wonTrophies.join(", ");
}
showStatText(statMsg);
// Show trophies
clearTrophyNodes();
// No trophy icons, only text for trophies
// Next: transfer offers or retirement
showNextButton("End of Season", function () {
mainContainer.removeChild(playerNode);
mainContainer.removeChild(clubNode);
mainContainer.removeChild(clubNameText);
hideStatText();
clearTrophyNodes();
if (playerAge >= 35) {
startSummary();
} else {
startTransfer();
}
});
}
function startTransfer() {
state = "transfer";
clearMainContainer();
clearTrophyNodes();
hideStatText();
hideSummaryText();
showInfo("New Transfer Offers");
showSeasonText("Age: " + playerAge + " | " + playerClub);
// Generate 2-3 random offers (not current club)
transferOffers = [];
var offerCount = randomInt(2, 3);
var usedClubs = {};
usedClubs[playerClub] = true;
for (var i = 0; i < offerCount; i++) {
var c;
do {
c = randomPick(clubs);
} while (usedClubs[c]);
usedClubs[c] = true;
transferOffers.push(c);
}
// Add "Stay" option
transferOffers.push(playerClub);
// Show buttons
clearTransferButtons();
for (var i = 0; i < transferOffers.length; i++) {
var c = transferOffers[i];
var isStay = c == playerClub;
var btn = new Text2(isStay ? "Stay at Club (" + c + ")" : c, {
size: 80,
fill: isStay ? "#00ff99" : "#fff"
});
btn.anchor.set(0.5, 0.5);
btn.x = 2048 / 2;
btn.y = 900 + i * 180;
btn.interactive = true;
btn.buttonMode = true;
btn.down = function (c) {
return function (x, y, obj) {
playerClub = c;
playerAge += 1;
clearTransferButtons();
startSeason();
};
}(c);
mainContainer.addChild(btn);
transferButtons.push(btn);
}
}
function startSummary() {
state = "summary";
clearMainContainer();
clearTrophyNodes();
hideStatText();
showInfo("Career Completed! (Retired)");
showSeasonText("");
// Show player
playerNode = new Player();
playerNode.x = 2048 / 2;
playerNode.y = 900;
mainContainer.addChild(playerNode);
// Show summary stats
var summaryMsg = "⚽ Total Goals: " + playerTotalGoals + "\n🥅 Total Assists: " + playerTotalAssists + "\n" + "\n🏆 Total Trophies: " + playerTotalTrophies;
if (playerTrophies.length > 0) {
summaryMsg += "\n" + playerTrophies.join("\n ");
}
showSummaryText(summaryMsg);
// Show "Yeniden Oyna" button
showNextButton("Play Again", function () {
mainContainer.removeChild(playerNode);
hideSummaryText();
startChoosePosition();
});
}
// --- Start Game ---
startChoosePosition();