-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
93 lines (71 loc) · 1.77 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
function love.load()
-- Libraries
anim8 = require("src/libraries/anim8/anim8")
sti = require("src/libraries/sti")
wf = require("src/libraries/windfield")
camera = require("src/libraries/hump/camera")
talkies = require("src/libraries/talkies/talkies")
-- Initialization
require("src/init")
initGame()
-- Helpers
require("src/utils")
-- Messageboxes
require("src/messageboxes")
-- World
require("src/world")
-- Camera
require("src/camera")
-- Player
require("src/player")
-- NPCs
require("src/npc")
spawnNPCs()
-- Chests
require("src/chest")
createChests()
-- Resources
require("src/sounds")
end
function love.update(dt)
player:update(dt)
npcs:update(dt)
chests:update(dt)
world:update(dt)
cam:update(dt)
messageboxes:update(dt)
end
function love.draw()
cam:attach()
drawMap()
-- Merge object tables and sort them.
objects = {unpack(npcs), unpack(chests)}
table.sort(objects, function(a, b) return a.y < b.y end)
local isDrawn = false
for i,_ in ipairs(objects) do
if not isDrawn and objects[i].y > player.y then
player:draw()
isDrawn = true
end
chests:draw()
npcs:draw()
end
-- If the player is below all objects, they won't be drawn within the for loop.
if not isDrawn then
player:draw()
end
-- Foreground objects go here...
-- (nothing at the moment)
if debug then
world:draw()
end
cam:detach()
messageboxes:draw()
drawHUD()
end
function love.keypressed(key)
if key == "space" then talkies.onAction()
elseif key == "c" then talkies.clearMessages()
elseif key == "escape" then love.event.quit()
end
end