-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.lua
90 lines (77 loc) · 1.99 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
game = {}
require("game.tilemap")
require("game.state")
require("game.summoning")
require("game.minions")
require("game.editor")
require("game.audio")
require("game.gui.index")
function love.load()
print("running on " .. love.system.getOS())
game.loadGraphics()
love.graphics.setDefaultFilter("nearest", "nearest", 1)
game.summoning.load()
game.tilemap.load()
game.minions.load()
game.editor.load()
game.audio.load()
game.gui.load()
game.loadLevel(1)
end
function love.update(dt)
-- always active modules
game.audio.update(dt)
game.gui.update(dt)
-- conditionally active modules
if game.state.isActive then
game.tilemap.update(dt)
game.summoning.update(dt)
game.minions.update(dt)
game.editor.update(dt)
end
end
function love.draw()
game.tilemap.draw()
game.minions.draw()
game.summoning.draw()
game.editor.draw()
game.gui.draw()
end
function love.keypressed(key, scancode, isrepeat)
-- always active modules
game.gui.keypressed(key, scancode, isrepeat)
-- conditionally active modules
if game.state.isActive then
game.summoning.keypressed(key, scancode, isrepeat)
game.minions.keypressed(key, scancode, isrepeat)
end
end
function love.wheelmoved(x, y)
game.editor.wheelmoved(x, y)
end
--- load the level with the given index
function game.loadLevel(id)
if id > #game.conf.level_sequence then
error("level id too high")
end
game.state.level.current = id
game.minions.loadLevel(id)
game.summoning.loadLevel(id)
game.gui.loadLevel(id)
game.tilemap.loadLevel(id)
end
function game.loadGraphics()
local w, h = love.window.getDesktopDimensions()
if h > 1080 then
game.conf.level.tileSize = 64
print("setting tile size to 64")
print(love.graphics.getDimensions())
else
game.conf.level.tileSize = 48
print("setting tile size to 48")
print(love.graphics.getDimensions())
end
local window_width = game.conf.level.tileSize * game.conf.level.width
local window_height = game.conf.level.tileSize * game.conf.level.height
love.window.setMode(window_width, window_height)
end