-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.lua
117 lines (103 loc) · 2.91 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
--
-- A game about a Vampire (villain + Day&Night, 2 themes) salvaging (3) an alien ship (outerspace)
-- and working (construction) inside a Nazi fortress (devil) a Chaos (7) Devices to cause the
-- End Of The World (music). You also need to construct something to make a journey (9)
-- to a parallel world (10).
--
require 'lib/middleclass'
require 'lib/AnAL'
require 'views/view'
require 'views/menu'
require 'views/map_view'
require 'level'
require 'map'
require 'sound_manager'
require 'actor'
fx = {}
fx.bloom_noise = require 'shader/bloom_noise'
game = {
state = 'menu',
current_level = 0,
levels = {},
views = { menu = MenuView() },
graphics = {
fullscreen = false,
mode = { height = love.graphics.getHeight(), width = love.graphics.getWidth() }
},
map = nil,
seed = (os.time() % 10) + 100,
fonts = {
small = love.graphics.newFont(10),
regular = love.graphics.newFont(14)
},
actors = {}
}
function game:start()
self:nextLevel()
self.views.map.display.width = game.graphics.mode.width - 10
self.views.map.display.height = game.graphics.mode.height - 10
self.state = 'map'
end
function game:exitTo(exit)
self:nextLevel(exit.level)
end
function game:nextLevel(level_num)
self.actors = {}
if not level_num then
self.current_level = game.current_level + 1
else
self.current_level = self.level_num
end
table.insert(self.levels, Level(self.current_level, self.seed))
game.map = self.levels[self.current_level].map
self.views.map = MapView(game.map)
end
function game:setMode(mode)
game.graphics.mode = mode
love.graphics.setMode(mode.width, mode.height)
end
function love.load()
game.animations = require('animations')
game.sounds = require('sounds')
love.audio.play(game.sounds.startmenu) -- stream and loop background music
game:start()
end
function love.draw()
if game.state == 'menu' then
drawValve()
game.views.menu:draw()
elseif game.state == 'map' then
love.graphics.setPixelEffect(fx.bloom_noise)
game.views.map:draw()
love.graphics.setPixelEffect()
end
love.graphics.setFont(game.fonts.small)
love.graphics.print(love.graphics.getCaption() .. ' Seed: ' .. game.seed, 10, love.graphics.getHeight(), 0, 1, 1, 0, 14)
love.graphics.setFont(game.fonts.regular)
end
function drawValve()
love.graphics.push()
love.graphics.scale(20,20)
game.animations.valve:draw(game.graphics.mode.width / 45, game.graphics.mode.height / 50)
love.graphics.pop()
end
function love.keypressed(key)
end
function love.update(dt)
love.audio.update()
if game.state == 'menu' then
game.views.menu:update(dt)
game.animations.valve.running = true
elseif game.state == 'map' then
for i, actor in ipairs(game.actors) do
actor:update(dt)
end
game.views.map:update(dt)
game.animations.valve.running = false
end
for i, animation in pairs(game.animations) do
if animation.running then
animation:update(dt)
end
end
end