-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.lua
328 lines (285 loc) · 9.49 KB
/
main.lua
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
require("maths")
require("vectors")
require("strings")
require("stars")
require("suns")
require("colonies")
require("spores")
require("connections")
require("planets")
require("players")
require("deathRipples")
require("game")
require("interface")
require("tutorial")
local shine = require("shine")
require("dumper/dumper")
FANCY_GRAPHICS = true
FPS = 60
UNIT_RADIUS = 5
SEGMENTS = 60
FONT_SIZE = 20
TITLE_OPACITY = .8
LAUNCH_ANGLE = TAU*.75
function love.load()
math.randomseed( os.time() )
love.filesystem.setIdentity('prospora')
love.keyboard.setKeyRepeat(true)
-- setup window
love.window.setTitle("Prospora")
love.window.setMode(800, 600, {fullscreen=false, fullscreentype='desktop'})
love.window.setIcon(love.graphics.newImage('assets/prospora-128x128.png'):getData())
love.graphics.setBackgroundColor(0, 0, 0)
love.graphics.setLineStyle('smooth')
love.graphics.setPointStyle('rough')
-- setup fonts
fontMessageSmallest = love.graphics.newFont('assets/furore.otf', FONT_SIZE*.6)
fontMessageSmall = love.graphics.newFont('assets/furore.otf', FONT_SIZE*.8)
fontMessage = love.graphics.newFont('assets/bender.otf', FONT_SIZE)
font = love.graphics.newFont('assets/furore.otf', FONT_SIZE)
fontLarge = love.graphics.newFont('assets/furore.otf', FONT_SIZE*2)
fontTitle = love.graphics.newFont('assets/furore.otf', FONT_SIZE*5)
love.graphics.setFont(font)
-- setup audio
gameMusic = love.audio.newSource('assets/alg0rh1tm-circuit.mp3', 'stream')
gameMusic:setLooping(true)
winMusic = love.audio.newSource('assets/broke_for_free-covered_in_oil.mp3', 'stream')
winMusic:setLooping(true)
loseSound = love.audio.newSource('assets/generdyn-brams01.wav', 'static')
launchSound = love.audio.newSource('assets/fins-laser.wav', 'static')
selectSound = love.audio.newSource('assets/nickgoa-plink.wav', 'static')
selectSound:setVolume(0.5)
buttonSound = love.audio.newSource('assets/junggle-btn402.mp3', 'static')
buttonSound:setVolume(0.1)
hitPlanetSound = love.audio.newSource('assets/reitanna-drop-metal-thing.wav', 'static')
hitPlanetSound:setVolume(0.5)
attackedSound = love.audio.newSource('assets/reitanna-defeated-sigh.wav', 'static')
spawnSound = love.audio.newSource('assets/fins-creature.wav', 'static')
homeWorldLossSound = love.audio.newSource('assets/generdyn-hits10.wav', 'static')
-- setup cool vignette effect
post_effect = setupFancyGraphics()
-- load previous game or setup new game
if not pcall(loadGame) then
game = newGame(true)
game:load()
end
end
timeSinceLastUpdate = 0
function love.update(dt)
timeSinceLastUpdate = timeSinceLastUpdate + dt
if (timeSinceLastUpdate >= 1/FPS) then
game:update()
if TITLE_OPACITY > 0 then
TITLE_OPACITY = TITLE_OPACITY - 0.003
end
timeSinceLastUpdate = timeSinceLastUpdate - (1/FPS)
end
end
function love.draw()
game:draw()
if TITLE_OPACITY > 0 then
love.graphics.setColor(0,0,0, 255*TITLE_OPACITY)
love.graphics.rectangle('fill', 0,0, love.graphics.getWidth(), love.graphics.getHeight())
love.graphics.setColor(255, 255, 255, 255*TITLE_OPACITY)
love.graphics.setFont(fontTitle)
love.graphics.printf(strings.prospora, 0, love.graphics.getHeight()/2-FONT_SIZE*4, love.graphics.getWidth(), 'center')
end
end
function love.mousepressed(x, y, button)
game:mousepressed(x, y)
end
function love.mousereleased(x, y, button)
game:mousereleased(x, y)
end
function love.keyreleased(k)
if (k == ' ' or k == 'return') then
if not game.paused and (love.keyboard.isDown('lshift') or love.keyboard.isDown('rshift')) then
local d = unitVectorFromAngle(LAUNCH_ANGLE)
d = vMul(d, game.human.selectedPlanet.radius)
d = vAdd(d, game.human.selectedPlanet.location)
game:launchHumanSpore(d)
elseif game.interface.messages[1] and not game.interface.messages[1]:activateSelectedButton() and not game.paused then
centerOnSelection()
end
elseif k == 'escape' then
game:togglePause()
end
end
function love.keypressed(k, isRepeat)
if k == 'left' then
if not game.paused and (love.keyboard.isDown('lshift') or love.keyboard.isDown('rshift')) then
if isRepeat then
LAUNCH_ANGLE = LAUNCH_ANGLE - TAU/33
else
LAUNCH_ANGLE = LAUNCH_ANGLE - TAU/100
end
elseif game.interface.messages[1] and game.interface.messages[1]:selectPrevButton() then
--
elseif not game.paused then
game.offset.x = game.offset.x + 20
adjustOffset()
game.flags.shiftView = true
end
elseif k == 'right' then
if not game.paused and (love.keyboard.isDown('lshift') or love.keyboard.isDown('rshift')) then
if isRepeat then
LAUNCH_ANGLE = LAUNCH_ANGLE + TAU/33
else
LAUNCH_ANGLE = LAUNCH_ANGLE + TAU/100
end
elseif game.interface.messages[1] and game.interface.messages[1]:selectNextButton() then
--
elseif not game.paused then
game.offset.x = game.offset.x - 20
adjustOffset()
game.flags.shiftView = true
end
elseif k == 'up' then
if not game.paused and (love.keyboard.isDown('lshift') or love.keyboard.isDown('rshift')) then
if isRepeat then
LAUNCH_ANGLE = LAUNCH_ANGLE - TAU/33
else
LAUNCH_ANGLE = LAUNCH_ANGLE - TAU/100
end
elseif game.interface.messages[1] and game.interface.messages[1]:selectPrevButton() then
--
elseif not game.paused then
game.offset.y = game.offset.y + 20
adjustOffset()
game.flags.shiftView = true
end
elseif k == 'down' then
if not game.paused and (love.keyboard.isDown('lshift') or love.keyboard.isDown('rshift')) then
if isRepeat then
LAUNCH_ANGLE = LAUNCH_ANGLE + TAU/33
else
LAUNCH_ANGLE = LAUNCH_ANGLE + TAU/100
end
elseif game.interface.messages[1] and game.interface.messages[1]:selectNextButton() then
--
elseif not game.paused then
game.offset.y = game.offset.y - 20
adjustOffset()
game.flags.shiftView = true
end
elseif k == 'q' then
game.human.colony.attack = game.human.colony.attack * 0.8
game.human.colony:adjustGenes()
elseif k == 'w' then
game.human.colony.attack = game.human.colony.attack * 1.25
game.human.colony:adjustGenes()
game.flags.increaseAttack = true
elseif k == 'a' then
game.human.colony.spawn = game.human.colony.spawn * 0.8
game.human.colony:adjustGenes()
elseif k == 's' then
game.human.colony.spawn = game.human.colony.spawn * 1.25
game.human.colony:adjustGenes()
game.flags.increaseSpawn = true
elseif k == 'z' then
game.human.colony.travel = game.human.colony.travel * 0.8
game.human.colony:adjustGenes()
elseif k == 'x' then
game.human.colony.travel = game.human.colony.travel * 1.25
game.human.colony:adjustGenes()
game.flags.increaseTravel = true
elseif k == 'tab' and not game.paused then
local firstPlanet = nil
local chooseNextPlanet = false
local chosenPlanet = nil
for i, planet in pairs(planets) do
local friends = planet:countFriends(game.human.colony)
if friends > 0 then
if not firstPlanet then firstPlanet = planet end
if planet == game.human.selectedPlanet then
chooseNextPlanet = true
elseif chooseNextPlanet then
chosenPlanet = planet
chooseNextPlanet = false
end
end
end
if not chosenPlanet and firstPlanet then
chosenPlanet = firstPlanet
end
if chosenPlanet == game.human.homeWorld then
game.flags.selectHomeWorld = true
end
game.human.selectedPlanet = chosenPlanet
centerOnSelection()
end
-- if paused, arrows select prev/next button
-- also if paused, ENTER or SPACE activate selected button
-- to launch from keyboard: shift to show target circle,
-- arrows while holding shift to aim,
-- ENTER or SPACE to launch
end
function love.quit ()
if game.tutorial or game.flags.win or game.flags.lose then
love.filesystem.remove('savegame')
else
saveGame()
end
end
function saveGame ()
game.stars = stars
game.suns = suns
game.planets = planets
game.planetConnections = planetConnections
love.filesystem.write('savegame', DataDumper(game))
end
function loadGame ()
local f = love.filesystem.read('savegame')
local fun = loadstring(f)
game = fun()
stars = game.stars
suns = game.suns
planets = game.planets
planetConnections = game.planetConnections
toggleFullscreen(true)
if game.soundOn then
if game.paused then
gameMusic:setVolume(0.5)
else
gameMusic:setVolume(1)
end
gameMusic:play()
end
end
function toggleFullscreen (doNotToggle)
if not doNotToggle then game.isFullscreen = not game.isFullscreen end
love.window.setFullscreen(game.isFullscreen)
if FANCY_GRAPHICS then post_effect = setupFancyGraphics() end
end
function setupFancyGraphics ()
love.graphics.setBackgroundColor(0,0,0)
love.graphics.setColor(255,255,255)
local vignette = shine.vignette()
vignette.parameters = {radius = .95, opacity = 0.2}
local separate_chroma = shine.separate_chroma()
separate_chroma.parameters = {radius = 0.5}
local filmgrain = shine.filmgrain()
filmgrain.parameters = {opacity = 0.05}
return separate_chroma:chain(vignette:chain(filmgrain))
end
function adjustPos (x, y)
local v = newVector(x, y)
v = vSub(v, game.offset)
v = vDiv(v, game.zoom)
return v
end
function unAdjustPos (x, y)
local v = newVector(x, y)
v = vMul(v, game.zoom)
v = vAdd(v, game.offset)
return v
end
function adjustOffset ()
game.offset.x = math.min(0, math.max(-game.world_size.width * game.zoom + love.graphics.getWidth(), game.offset.x))
game.offset.y = math.min(0, math.max(-game.world_size.height * game.zoom + love.graphics.getHeight(), game.offset.y))
end
function drawFilledCircle(x, y, r)
love.graphics.circle('fill', x*game.zoom, y*game.zoom, r*game.zoom-.5, SEGMENTS)
love.graphics.setLineWidth(1)
love.graphics.circle('line', x*game.zoom, y*game.zoom, r*game.zoom-.5, SEGMENTS)
end