- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
Latest commit
263 lines (240 loc) · 7.29 KB
/
Copy pathmain.lua
File metadata and controls
263 lines (240 loc) · 7.29 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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
--PROF_CAPTURE = true
prof=require'lib.jprof'
--prof.connect()
manual_gc=require'lib.manual_gc'
lume=require'lib.lume'
nut=require'lib.love_nut'
json=require'lib.json'
bitser=require'lib.bitser'
Camera=require'lib.camera'
require'tempCommon'
require'utils'
require'loadassets'
require'sound'
require'server'
require'client'
require'cursor'
require'text'
require'menu'
require'hud'
require'chat'
require'physics'
require'scene'
require'world'
require'entities'
require'projectiles'
require'slimeBalls'
require'playerController'
require'items'
require'lootBag'
require'portals'
require'damageText'
require'realm'
require'quests'
functionlove.load()
camera=Camera{ssx=gsx, ssy=gsy}
gameState='menu'
time=0
gameTime=0
-- don't shoot if pressing ui
uiMouseDown=false
drawDebug=false
menu.load()
hud.load()
serverRealm=realm.server:new()
clientRealm=realm.client:new()
love.mouse.setVisible(false)
end
gameScale=math.min(ssx/gsx, ssy/gsy)
functionlove.resize(w, h)
ssx=w
ssy=h
gameScale=math.min(ssx/gsx, ssy/gsy)
end
functionlove.update(dt)
prof.push('frame')
prof.push('update')
time=time+dt
love.window.setTitle('Tier (' ..love.timer.getFPS() ..' FPS)')
cursor.cursor=cursor.main
prof.push('update server')
ifserver.runningthen
server.update(dt)
end
prof.pop('update server')
prof.push('update client')
ifclient.connectedthen
client.update(dt)
end
prof.pop('update client')
prof.push('update menu')
menu.update(dt)
prof.pop('update menu')
prof.push('update gc')
manual_gc(1e-3, 64)
prof.pop('update gc')
prof.pop('update')
shaders.mapRender:send('drawDebug', drawDebug)
end
functionlove.mousepressed(x, y, btn, isTouch, presses)
menu.mousepressed(x, y, btn, isTouch, presses)
ifgameState=='playing' then
hud.mousepressed(x, y, btn, isTouch, presses)
playerController.mousepressed(x, y, btn, isTouch, presses)
items.client.mousepressed(x, y, btn, isTouch, presses)
end
end
functionlove.mousereleased(x, y, btn, isTouch, presses)
menu.mousereleased(x, y, btn, isTouch, presses)
ifgameState=='playing' then
hud.mousereleased(x, y, btn, isTouch, presses)
playerController.mousereleased(x, y, btn, isTouch, presses)
items.client.mousereleased(x, y, btn, isTouch, presses)
end
ifnotlove.mouse.isDown(1) andnotlove.mouse.isDown(2) then
uiMouseDown=false
localheldItem=playerController.heldItem
heldItem.itemId=nil
heldItem.bagId=nil
heldItem.slotId=nil
end
end
functionlove.textinput(t)
ifchat.activethen
chat.textinput(t)
else
menu.textinput(t)
end
end
functionlove.keypressed(k, scancode, isrepeat)
localchatActive=chat.active
localchatPanelOpen=hud.chatPanel.open
ifchatActiveorchatPanelOpenthen
chat.keypressed(k, scancode, isrepeat)
end
ifnotchatActivethen
ifgameState=='playing' andk=='return' andnotisrepeatthen
chat.active=true
hud.chatPanel.open=true
end
end
-- if chat open, esc pressed, chat.active=false & chatActive=true
ifnot (chatActiveorchat.active) then
ifgameState=='menu' then
menu.keypressed(k, scancode, isrepeat)
elseifgameState=='playing' then
hud.keypressed(k, scancode, isrepeat)
playerController.keypressed(k, scancode, isrepeat)
portals.client.keypressed(k, scancode, isrepeat)
iffalsethen
ifk=='q' then
localp=playerController.player
for_, costItemIdinipairs(quests.current.cost) do
localcostItem=items.client.getItem(costItemId)
ifcostItemthen
-- duplicates costItem
forinvSlotId, _inipairs(hud.inventorySlots) do
localslotType=slot2type[invSlotId]
ifp.inventory.items[invSlotId] ==nil
and (slotType==nilorslotType==costItem.type) then
client.setInventorySlot{
slotId=invSlotId,
itemId=costItemId
}
p.inventory.items[invSlotId] =costItemId
break
end
end
end
end
end
end
end
ifnotisrepeatthen
ifk=='escape' andnotchatPanelOpenthen
gameState='menu'
menu.state='main'
ifserver.runningthen
server.close()
end
ifclient.connectedthen
client.close()
end
love.mouse.setGrabbed(false)
elseifk=='f1' then
drawDebug=notdrawDebug
end
end
end
end
functionlove.draw()
prof.push('draw')
prof.push('draw setup')
localmx, my=window2game(love.mouse.getPosition())
mx, my=lume.round(mx), lume.round(my)
love.graphics.setBlendMode('alpha')
love.graphics.setCanvas(canvases.game2x)
love.graphics.clear()
love.graphics.setCanvas(canvases.game)
love.graphics.clear(0.15, 0.15, 0.15)
prof.pop('draw setup')
ifgameState=='playing' then
prof.push('draw playing')
camera:set()
prof.push('draw scene')
scene.reset()
-- world and loot bags
clientRealm:draw()
entities.client.draw()
projectiles.client.draw()
slimeBalls.draw()
portals.client.draw()
scene.draw()
damageText.draw()
prof.pop('draw scene')
prof.push('draw debug')
ifdrawDebugthen
ifserver.runningthen
serverRealm.physics:draw()
end
ifclient.connectedthen
clientRealm.physics:draw()
end
end
prof.pop('draw debug')
camera:reset()
prof.push('draw hud/chat')
hud.draw()
chat.draw()
prof.pop('draw hud/chat')
iflove.keyboard.isScancodeDown('g') then
clientRealm.world:drawMap('full')
end
prof.pop('draw playing')
end
prof.push('draw menu/cursor')
menu.draw()
cursor.draw()
prof.pop('draw menu/cursor')
prof.push('draw canvas')
-- draw game on game2x
setGameCanvas2x()
love.graphics.setCanvas()
love.graphics.setBlendMode('alpha', 'premultiplied')
love.graphics.clear(0, 0, 0)
love.graphics.setColor(1, 1, 1)
love.graphics.draw(canvases.game2x, ssx/2-gameScale*gsx/2, ssy/2-gameScale*gsy/2, 0, gameScale/2, gameScale/2)
prof.pop('draw canvas')
prof.pop('draw')
prof.pop('frame')
end
functionlove.quit()
ifserver.runningthen
server.close()
end
ifclient.connectedthen
client.close()
end
menu.writeDefaults()
--prof.write('prof.mpack')
end