---@diagnostic disable: undefined-global, lowercase-global characters = require("assets.characters.characters-data") player1CharacterIndex = 1 player2CharacterIndex = 2 player1Character = characters[player1CharacterIndex] player2Character = characters[player2CharacterIndex] function StartGame() if characterSelectType == "Local 2P" then dofile("assets/scripts/local2P.lua") end if characterSelectType == "Multiplayer" then dofile("assets/scripts/multiplayer.lua") end Setup() end function BackToMainMenu() dofile("assets/scripts/mainMenu.lua") Setup() end function Setup() print("Using Character Select type: " .. characterSelectType) -- Debug print end function Update() -- Title and subtitle/paragraph texts local fontFile = "assets/fonts/OpenSans-Bold.ttf" local fontSize = 50 local text = "Character Select | " .. characterSelectType local textWidth = getTextWidth(fontFile, fontSize, text) local x = (WIDTH - textWidth) // 2 local y = 20 queueTextForRender(text, fontFile, x, y, fontSize, 255, 255, 255, 255) local fontFile = "assets/fonts/OpenSans-Regular.ttf" local fontSize = 17 local text = "Player 1: Use A & D to cycle through characters" local textWidth = getTextWidth(fontFile, fontSize, text) local x = (WIDTH - textWidth) // 2 local y = 120 queueTextForRender(text, fontFile, x, y, fontSize, 255, 255, 255, 255) local text = "Player 2: Use LEFT & RIGHT to cycle through characters" local textWidth = getTextWidth(fontFile, fontSize, text) local x = (WIDTH - textWidth) // 2 local y = 145 queueTextForRender(text, fontFile, x, y, fontSize, 255, 255, 255, 255) -- Character Portraits & Names local imageFile_player1 = player1Character.asset_dir .. "/portrait.png" local imageFile_player2 = player2Character.asset_dir .. "/portrait.png" local portraitWidth = 128 local nameFontFile = "assets/fonts/OpenSans-Bold.ttf" local nameFontSize = 20 local p1_x = (WIDTH // 4) - (portraitWidth // 2) queueTextureForRender(imageFile_player1, p1_x, 300) local p1Name = player1Character.name local p1NameWidth = getTextWidth(nameFontFile, nameFontSize, p1Name) local p1TextX = (WIDTH // 4) - (p1NameWidth // 2) queueTextForRender(p1Name, nameFontFile, p1TextX, 570, nameFontSize, 255, 255, 255, 255) local p2_x = (WIDTH * 3 // 4) - (portraitWidth // 2) queueTextureForRender(imageFile_player2, p2_x, 300) local p2Name = player2Character.name local p2NameWidth = getTextWidth(nameFontFile, nameFontSize, p2Name) local p2TextX = (WIDTH * 3 // 4) - (p2NameWidth // 2) queueTextForRender(p2Name, nameFontFile, p2TextX, 570, nameFontSize, 255, 255, 255, 255) local function wrapIndex(index) if index < 1 then return #characters elseif index > #characters then return 1 else return index end end local function getNextValidIndex(currentIndex, direction, otherIndex) local nextIndex = wrapIndex(currentIndex + direction) while nextIndex == otherIndex do nextIndex = wrapIndex(nextIndex + direction) end return nextIndex end -- Player 1 controls if Input.isKeyPressedOnce("A") then player1CharacterIndex = getNextValidIndex(player1CharacterIndex, -1, player2CharacterIndex) player1Character = characters[player1CharacterIndex] end if Input.isKeyPressedOnce("D") then player1CharacterIndex = getNextValidIndex(player1CharacterIndex, 1, player2CharacterIndex) player1Character = characters[player1CharacterIndex] end -- Player 2 controls if Input.isKeyPressedOnce("LEFT") then player2CharacterIndex = getNextValidIndex(player2CharacterIndex, -1, player1CharacterIndex) player2Character = characters[player2CharacterIndex] end if Input.isKeyPressedOnce("RIGHT") then player2CharacterIndex = getNextValidIndex(player2CharacterIndex, 1, player1CharacterIndex) player2Character = characters[player2CharacterIndex] end -- Start and back buttons queueButtonForRender("START!", WIDTH // 2 - buttonWidth // 2, HEIGHT - (buttonHeight * 2), buttonWidth, buttonHeight, "StartGame"); queueButtonForRender("Back to Main Menu", WIDTH - 220 - 20, 20, 220, 50, "BackToMainMenu") end