-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
executable file
·362 lines (321 loc) · 9.47 KB
/
main.lua
File metadata and controls
executable file
·362 lines (321 loc) · 9.47 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
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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
debug = true
--require( "tablesave.lua" )
require 'physics1'
require 'map1-functions'
require 'itemmap'
require 'charactercontroller'
require 'shooter'
require 'metroidcamera'
love.filesystem.load("acca.lua")
require 'enemystate'
--some player variables
canShoot = true
canShootTimerMax = 0.2
canShootTimer = canShootTimerMax
function love.load(arg)
ingame = false
if ingame then
else
retrofont = love.graphics.newFont("assets/retrofont.ttf", 15)
cursorimg = love.graphics.newImage("itemimg/Dagger/01.png")
cursorPosition = 2
loadPage = 1
-- love.graphics.setFont(font)
-- love.graphics.printf("You have obtained the\nRing of Power\n\nYou can now push blocks", windowSize.x/2-120, windowSize.y/2-60, windowSize.y/2, 'center')
end
end
function loadGame(loadtable)
background = love.graphics.newImage("assets/background1.png")
-- background2 = love.graphics.newImage("assets/background2.png")
-- camera:newLayer(0,function()
-- love.graphics.draw(background,0,0,0,1,1)
-- end)
-- camera:newLayer(1,function()
-- love.graphics.draw(background2,0,0,0,1,1)
-- end)
local loadPlayer = true
if loadtable ~= nil and fileExists(loadtable) then
player = table.load(loadtable)
loadPlayer = false
end
character_controller:load(arg, loadPlayer)
shooter:load(arg)
camera:load(arg)
metroidcamera:load(arg)
--startmap = 'assets/MapStringGenerator/MapScripts/entryroom.lua'
startmap = 'assets/MapStringGenerator/MapScripts/bonfireroom1.lua'
if loadPlayer then
--startmap = 'assets/MapStringGenerator/MapScripts/bonfireroom1.lua'
startmap = 'assets/MapStringGenerator/MapScripts/entryroom.lua'
else
startmap = player.respawnRoom
end
player.respawnPoint.x = player.x
player.respawnPoint.y = player.y
player.respawnRoom = startmap
loadMap(startmap)
loadMapBackground(startmap)
loadMapForeground(startmap)
loadItemMap(startmap)
loadEnemies(startmap)
-- playerImg = nil
-- playerImg = love.graphics.newImage('assets/aircrafts.png')
bulletImg = nil
bullets = {}
debugTools.startTimer = love.timer.getTime()
ingame = true
end
function reloadMaps(map_path, door, isRespawn)
loadMap(map_path)
loadMapBackground(map_path)
loadMapForeground(map_path)
loadItemMap(map_path)
loadEnemies(map_path)
player.speed = 0
if not isRespawn then
if door.position == "left" then
for _,d in ipairs(doorPositions) do
if d.position == "right" then
player.x = d.x - 48
player.y = d.y-64
end
end
else
for _,d in ipairs(doorPositions) do
if d.position == "left" then
player.x = d.x + 8
player.y = d.y-64
end
end
end
else
player.x = player.respawnPoint.x
player.y = player.respawnPoint.y
end
--player.x = door.dest_x + door.offset
--player.y = door.dest_y - 32
end
function love.update(dt)
if ingame then
if not ring.obtained and not vendorMenu.interacting then
character_controller:update(dt)
local doorBool, doorData = getDoorPosition()
if doorBool then
reloadMaps(doorData.destination,doorData)
end
if player.health == 0 then
debugTools.deathCounter = debugTools.deathCounter + 1
-- local door = nil
-- for _,d in ipairs(doorPositions) do
-- if d.position == "left" then
-- door = d
-- end
-- end
reloadMaps(player.respawnRoom,nil,true)
player.health = player.healthMax
player.hurt = false
end
button.button1.class:update(dt)
metroidcamera:update(dt)
checkBlowUpBoxes(dt)
updateEnemies(dt)
if love.keyboard.isDown('1') then
deletePushableBlocks()
loadItemMap()
end
end
else
if cursorPosition == 2 and love.keyboard.isDown('return') and loadPage == 1 then
loadPage = 2
end
end
end
function love.draw(dt)
if ingame then
love.graphics.draw(background,0,0,0,1,1)
camera:set()
--camera:draw()
love.graphics.setDefaultFilter("linear", "linear")
drawBackground()
love.graphics.setDefaultFilter("linear", "linear")
drawMap()
love.graphics.setDefaultFilter("linear", "linear")
drawItemMap()
drawParticle()
reDrawPushables()
drawEnemies(dt)
character_controller:draw()
drawRespawn()
drawForeground()
button.button1.class:draw()
--drawDebug()
camera:unset()
character_controller:drawHUD(dt)
if ring.obtained then
character_controller:drawRingBox()
end
if vendorMenu.interacting then
character_controller:drawVendorMenu()
end
else
if loadPage ==1 then
love.graphics.setFont(retrofont)
love.graphics.printf("Game Start", windowSize.x/2-120, windowSize.y/2-60, windowSize.y/2, 'center')
love.graphics.printf("Exit", windowSize.x/2-120, windowSize.y/2, windowSize.y/2, 'center')
love.graphics.draw(cursorimg,windowSize.x/2-80, windowSize.y/2-60*(cursorPosition-1),0,1,1)
elseif loadPage == 2 then
love.graphics.setFont(retrofont)
local _loadfile = "/Users/alex/Documents/Game/gamesaves/gamesave1.lua"
if fileExists(_loadfile) then
love.graphics.printf("Load Game", windowSize.x/2-120, windowSize.y/2-60, windowSize.y/2, 'center')
love.graphics.printf("New Game", windowSize.x/2-120, windowSize.y/2, windowSize.y/2, 'center')
else
love.graphics.printf("New Game", windowSize.x/2-120, windowSize.y/2-60, windowSize.y/2, 'center')
love.graphics.printf("New Game", windowSize.x/2-120, windowSize.y/2, windowSize.y/2, 'center')
end
love.graphics.draw(cursorimg,windowSize.x/2-80, windowSize.y/2-60*(cursorPosition-1),0,1,1)
end
end
end
function KeyPressGameStart(key)
if key == 's' then
cursorPosition = 1
end
if key == 'w' then
cursorPosition = 2
end
if key == 'return' and loadPage == 2 then
local _loadfile = "/Users/alex/Documents/Game/gamesaves/gamesave1.lua"
if fileExists(_loadfile) then
loadGame(_loadfile)
else
loadGame()
end
end
end
function table.load( sfile )
local ftables,err = loadfile( sfile )
if err then return _,err end
local tables = ftables()
for idx = 1,#tables do
local tolinki = {}
for i,v in pairs( tables[idx] ) do
if type( v ) == "table" then
tables[idx][i] = tables[v[1]]
end
if type( i ) == "table" and tables[i[1]] then
table.insert( tolinki,{ i,tables[i[1]] } )
end
end
-- link indices
for _,v in ipairs( tolinki ) do
tables[idx][v[2]],tables[idx][v[1]] = tables[idx][v[1]],nil
end
end
return tables[1]
end
function tableSave(filename)
table.save( player , filename )
end
function table.save( tbl,filename )
print(fileExists(filename))
if not fileExists(filename) then
createFile(filename)
end
local charS,charE = " ","\n"
local file,err = io.open( filename, "wb" )
if err then return err end
-- initiate variables for save procedure
local tables,lookup = { tbl },{ [tbl] = 1 }
file:write( "return {"..charE )
for idx,t in ipairs( tables ) do
file:write( "-- Table: {"..idx.."}"..charE )
file:write( "{"..charE )
local thandled = {}
for i,v in ipairs( t ) do
thandled[i] = true
local stype = type( v )
-- only handle value
if stype == "table" then
if not lookup[v] then
table.insert( tables, v )
lookup[v] = #tables
end
file:write( charS.."{"..lookup[v].."},"..charE )
elseif stype == "string" then
file:write( charS..exportstring( v )..","..charE )
elseif stype == "number" then
file:write( charS..tostring( v )..","..charE )
end
end
for i,v in pairs( t ) do
-- escape handled values
if (not thandled[i]) then
local str = ""
local stype = type( i )
-- handle index
if stype == "table" then
if not lookup[i] then
table.insert( tables,i )
lookup[i] = #tables
end
str = charS.."[{"..lookup[i].."}]="
elseif stype == "string" then
str = charS.."["..exportstring( i ).."]="
elseif stype == "number" then
str = charS.."["..tostring( i ).."]="
end
if str ~= "" then
stype = type( v )
-- handle value
if stype == "table" then
if not lookup[v] then
table.insert( tables,v )
lookup[v] = #tables
end
file:write( str.."{"..lookup[v].."},"..charE )
elseif stype == "string" then
file:write( str..exportstring( v )..","..charE )
elseif stype == "number" then
file:write( str..tostring( v )..","..charE )
end
end
end
end
file:write( "},"..charE )
end
file:write( "}" )
file:close()
end
function exportstring( s )
return string.format("%q", s)
end
function createFile(filename)
file = io.open(filename, "w")
end
function fileExists(name)
local f=io.open(name,"r")
if f~=nil then io.close(f) return true else return false end
end
--// The Load Function
function table.load( sfile )
local ftables,err = loadfile( sfile )
if err then return _,err end
local tables = ftables()
for idx = 1,#tables do
local tolinki = {}
for i,v in pairs( tables[idx] ) do
if type( v ) == "table" then
tables[idx][i] = tables[v[1]]
end
if type( i ) == "table" and tables[i[1]] then
table.insert( tolinki,{ i,tables[i[1]] } )
end
end
-- link indices
for _,v in ipairs( tolinki ) do
tables[idx][v[2]],tables[idx][v[1]] = tables[idx][v[1]],nil
end
end
return tables[1]
end