-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.lua
More file actions
240 lines (205 loc) · 5.73 KB
/
Copy pathmain.lua
File metadata and controls
240 lines (205 loc) · 5.73 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
238
239
240
require 'roundrect'
math.randomseed(os.time())
varfilter = '$(%w+)%$?'
function printf(template, rep)
return (template:gsub(varfilter, rep))
end
state = {frame = 0, totaltime = 0, current = 'mainmenu'}
states = {}
officialnames = {a = 'Amania', b = 'Bzadoria',
c = 'Cadadonia', d = 'Darzamin', ar = 'Anarchists',
br = 'Fighters for the Common Good', cr = 'Eclectic Monkeys',
dr = 'Alliance of Oppressed People', dem = 'Deus Ex Machines',
player = 'You', sc = 'SpaceCorp'}
function registerstate(name)
states[name] = {}
states[name].keypressed = {}
end
registerstate'game'
registerstate'dead'
require "hook"
function love.load()
smallfont = love.graphics.newFont('gemfontone.ttf', 16)
largefont = love.graphics.newFont('gemfontone.ttf', 30)
mediumfont = love.graphics.newFont('gemfontone.ttf', 22)
love.graphics.setFont(largefont)
require "map"
require "graphics"
require "ui"
require "player"
require "ai"
require "ships"
require "physics"
require "mainmenu"
require "base"
require "mission"
require "diplomacy"
require "help"
require "conv"
require "mapview"
require "file"
restart()
end
function restart()
map.load()
graphics.load()
ui.load()
ships.load()
player.load()
ai.load()
physics.load()
mainmenu.load()
base.load()
mission.load()
help.load()
conv.load()
diplomacy.load()
mapview.load()
end
function love.update(dt)
if state.current == 'game' then
state.frame = state.frame + 1
if not ui.cmdstring then
state.totaltime = state.totaltime + dt
mission.update(dt)
map.update(dt)
ui.update(dt)
player.update(dt)
ai.update(dt)
ships.update(dt)
physics.update(dt)
graphics.update(dt)
end
love.timer.sleep(10)
elseif state.current == 'paused' then
state.frame = state.frame + 1
love.timer.sleep(20)
elseif state.current == 'dead' then
love.timer.sleep(50)
elseif state.current == 'mainmenu' then
mainmenu.update(dt)
love.timer.sleep(10)
elseif state.current == 'base' then
ui.base.update(dt)
love.timer.sleep(20)
elseif state.current == 'help' then
help.update(dt)
love.timer.sleep(20)
elseif state.current == 'conv' then
conv.update(dt)
love.timer.sleep(20)
elseif state.current == 'mapview' then
mapview.update(dt)
love.timer.sleep(20)
elseif state.current:sub(1,7) == 'mission' then
mission.updatescreen(dt)
love.timer.sleep(20)
elseif state.current:sub(1,4) == 'base' then
base.update(dt)
love.timer.sleep(20)
elseif state.current:sub(1,8) == 'mainmenu' then
mainmenu[state.current:sub(10)].update(dt)
love.timer.sleep(20)
end
end
function love.draw()
if state.current == 'game' or state.current == 'paused' then
map.draw()
graphics.draw()
ui.draw()
player.draw()
ai.draw()
ships.draw()
physics.draw()
elseif state.current == 'help' then
help.draw()
elseif state.current == 'dead' then
love.graphics.print('Nice steering, captain. You\'re dead now.', 100, 100)
love.graphics.print('Press R to restart the game.', 100, 130)
elseif state.current == 'base' then
ui.drawbase()
elseif state.current == 'mainmenu' then
mainmenu.draw()
elseif state.current == 'conv' then
conv.draw()
elseif state.current == 'mapview' then
mapview.draw()
elseif state.current:sub(1,7) == 'mission' then
mission.drawscreen()
elseif state.current:sub(1,4) == 'base' then
base.draw()
elseif state.current:sub(1,8) == 'mainmenu' then
mainmenu[state.current:sub(10)].draw()
end
end
function love.keypressed(key, unicode)
if key == 'return' then key = 'enter' end
if states[state.current].keypressed[key] then
states[state.current].keypressed[key]()
elseif states[state.current].keypressed.other then
states[state.current].keypressed.other(key, unicode)
end
end
if not debug then return end -- do not use custom error handler when debug is
-- not available (most likely because we're
-- running on SELÖVE)
local function error_printer(msg, layer)
print((debug.traceback("Error: " .. msg, 1+(layer or 1)):gsub("\n[^\n]+$", "")))
end
function love.errhand(msg)
error_printer(msg, 2)
-- Load.
love.graphics.setScissor()
love.graphics.setColor(255, 255, 255, 255)
local trace = debug.traceback()
love.graphics.clear()
local err = {msg}
for l in string.gmatch(trace, "(.-)\n") do
if not string.match(l, "boot.lua") then
l = string.gsub(l, "stack traceback:", "Traceback\n")
table.insert(err, l)
end
end
local p = table.concat(err, "\n")
p = string.gsub(p, "\t", "")
p = string.gsub(p, "%[string \"(.-)\"%]", "%1")
local wi = love.graphics.getWidth() - 140
address = 'github.com/gvx/space/issues'
local wa = love.graphics.getWidth() - largefont:getWidth(address) - 20
local ha = love.graphics.getHeight() - 45
local fb = love.graphics.newFramebuffer()
local function draw()
love.graphics.setFont(largefont)
love.graphics.print('Oops! Something went wrong.', 20, 10)
love.graphics.print(address, wa, ha)
love.graphics.setFont(mediumfont)
if showtrace then
love.graphics.printf(p, 70, 95, wi)
else
love.graphics.printf('An error occurred. It would be great if you want to file a bug report. To do that, please visit github.com/gvx/space/issues. First check if this bug has not been fixed already. If you have no terminal with the traceback of the error, press space. To quit, press escape.', 70, 95, wi)
end
end
fb:renderTo(draw)
love.graphics.clear()
love.graphics.draw(fb, 0, 0)
love.graphics.present()
local e, a, b, c
while true do
e, a, b, c = love.event.wait()
if e == "q" then
return
end
if e == "kp" then
if a == "escape" then
return
elseif a == ' ' then
showtrace = not showtrace
fb:renderTo(draw)
end
end
love.graphics.clear()
love.graphics.draw(fb, 0, 0)
love.graphics.present()
love.timer.sleep(25)
end
end