-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.lua
More file actions
239 lines (191 loc) · 5.99 KB
/
Copy pathsettings.lua
File metadata and controls
239 lines (191 loc) · 5.99 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
-- This file is part of SpaceShooter.
--
-- SpaceShooter is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- SpaceShooter is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with SpaceShooter. If not, see <http://www.gnu.org/licenses/>.
local selected = 1
local key_wait_idx = 0
local function draw_title ()
local x,y
local myfont = font["title"]
local text = "SpaceShooter"
love.graphics.setFont (myfont)
x = win_width / 2
y = 75
love.graphics.setColor (255, 255, 255, 255)
local w, h = draw_text (text, x, y, myfont, "top", "center")
draw_text ("Settings", x, y + h, font["large"], "top", "center")
end
local function update_key_text (idx)
local item = settings_text[idx]
if item.key then
item.val = get_key_name (settings.controls[item.key])
end
end
local function update_friction_text (idx)
local item = settings_text[idx]
item.val = settings.space_friction
end
local function draw_settings ()
local font = font["med"]
local left, right, y, w, h
love.graphics.setColor (255, 255, 255, 255)
left = 100
right = win_width - 100
y = 200
for i = 1,#settings_text do
local ltext = settings_text[i].name
local rtext = settings_text[i].val
if i == selected then
rtext = "[ " .. rtext .. " ]"
if settings_text[i].hint then
draw_text (settings_text[i].hint, win_width / 2,
win_height - 50, font, "bottom", "center")
end
end
if settings_text[i].spacing then
y = y + settings_text[i].spacing
end
w,h = draw_text (ltext, left, y, font, "top", "left")
draw_text (rtext, right, y, font, "top", "right")
y = y + h * 1.3
end
end
local function set_control_key (idx, key)
local control = settings_text[idx].key
-- Assign key to control
settings.controls[control] = key
-- Update settings screen control list
settings_text[idx].update (idx)
end
local function settings_key_select (idx)
settings_text[idx].val = "..."
key_wait_idx = idx
end
local function settings_return (idx)
set_state ("start")
end
local function settings_friction_inc (idx)
settings.space_friction = settings.space_friction +
settings.space_friction_step
if settings.space_friction > 1.0 then
settings.space_friction = 1.0
end
settings_text[idx].update (idx)
end
local function settings_friction_dec (idx)
settings.space_friction = settings.space_friction -
settings.space_friction_step
if settings.space_friction < 0.05 then
settings.space_friction = 0.0
end
settings_text[idx].update (idx)
end
settings_text = {
{
name = "Forward Thrust",
key = "up",
select = settings_key_select,
update = update_key_text,
hint = "Key to accelerate your ship forwards"
},
{
name = "Reverse Thrust",
key = "down",
select = settings_key_select,
update = update_key_text,
hint = "Key to accelerate your ship backwards"
},
{
name = "Spin Left",
key = "left",
select = settings_key_select,
update = update_key_text,
hint = "Key to rotate your ship left (counter-clockwise)"
},
{
name = "Spin Right",
key = "right",
select = settings_key_select,
update = update_key_text,
hint = "Key to rotate your ship right (clockwise)"
},
{
name = "Fire",
key = "fire",
select = settings_key_select,
update = update_key_text,
hint = "Key to fire your ship's weapons"
},
{
name = "Space Friction",
spacing = 25,
inc = settings_friction_inc,
dec = settings_friction_dec,
update = update_friction_text,
hint = "Rate at which your ship naturally slows over time"
},
{
name = "",
spacing = 40,
val = "return",
select = settings_return,
hint = "Return to title screen"
},
}
function settings_activate ()
selected = 1
for i,setting in pairs (settings_text) do
if setting.update then
setting.update (i)
end
end
end
function settings_draw (game_time, dt)
draw_title ()
draw_settings ()
end
function settings_key (key)
local action
-- If a control key is being assigned, accept this key press as the
-- newly assigned key
if (key_wait_idx > 0) then
set_control_key (key_wait_idx, key)
key_wait_idx = 0
return
end
action = get_key_action (key)
-- Always support up, down, left, right, enter on the settings screen.
-- Also support whatever control keys the player has bound.
if (key == "down" or action == "down") then
selected = selected + 1
elseif (key == "up" or action == "up") then
selected = selected - 1
elseif (key == "left" or action == "left") then
if settings_text[selected].dec then
settings_text[selected].dec (selected)
end
elseif (key == "right" or action == "right") then
if settings_text[selected].inc then
settings_text[selected].inc (selected)
end
elseif (key == "return" or action == "fire") then
if settings_text[selected].select then
settings_text[selected].select (selected)
end
end
if (selected > #settings_text) then
selected = #settings_text
elseif (selected < 1) then
selected = 1
end
end