1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
---@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()
stopAllSounds()
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
|