-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
136 lines (110 loc) · 4.21 KB
/
main.lua
File metadata and controls
136 lines (110 loc) · 4.21 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
---@diagnostic disable: lowercase-global, undefined-field, redundant-parameter, different-requires
Object = require 'libraries/classic/classic' --global var for class library
Input = require 'libraries/boipushy/Input' --global var for input library
Timer = require 'libraries/chrono/Timer' --global var for timer library
fn = require 'libraries/Moses/moses' --global var for table operation library
--Camera = require 'libraries/hump/camera' --slightly modified version of hump camura module with screen shake functionality
Camera = require 'libraries/STALKER-X/Camera' --camera module for LÖVE w/ all in one features
GameObject = require 'GameObject'
require 'utils' --this where all the functions that don't fit anywhere else go
function love.load()
love.graphics.setDefaultFilter('nearest') --pixelated look
love.graphics.setLineStyle('rough') --pixelated look
resize(3)
--loads in our Classes
local object_files = {}
recursiveEnumerate('objects', object_files)
requireFiles(object_files)
--loads in our Scenes/Rooms
local room_files = {}
recursiveEnumerate('rooms', room_files)
requireFiles(room_files)
timer = Timer()
input = Input()
camera = Camera(240, 135, 480, 270) -- to make the camera work with pixel camera we need to tell it what's the base resolution
current_room = nil
gotoRoom('Stage')
-- input:bind('f1', function() gotoRoom('CircleRoom') end)
-- input:bind('f2', function() gotoRoom('RectangleRoom') end)
-- input:bind('f3', function() gotoRoom('PolygonRoom') end)
end
function love.update(dt)
timer:update(dt)
camera:update(dt)
if current_room then current_room:update(dt) end
end
function love.draw()
if current_room then current_room:draw() end
end
function gotoRoom(room_type, ...)
print("Going to room: " .. room_type)
current_room = _G[room_type](...)
end
function resize(s)
love.window.setMode(s*gw, s*gh)
sx, sy = s, s
end
function recursiveEnumerate(folder, file_list)
local items = love.filesystem.getDirectoryItems(folder)
for _, item in ipairs(items) do
local file = folder .. '/' .. item
if love.filesystem.getInfo(file, 'file') then
table.insert(file_list, file)
elseif love.filesystem.getInfo(file, 'directory') then
recursiveEnumerate(file, file_list)
end
end
end
-- Automatically creates global variables for each class based on the filename
-- Since the class library returns a table, we can assign it to a global variable
function requireFiles(files)
for _, file in ipairs(files) do
if file:sub(-4) == '.lua' then
local file_path = file:sub(1, -5) -- remove .lua extension from filename
local last_foward_slash_index = file_path:find("/[^/]*$")
local class_name = file_path:sub(last_foward_slash_index + 1, #file_path) -- or local class_name = file_path:sub(index+1)
print(class_name)
_G[class_name] = require(file_path)
end
end
end
-- Use this fuction when the class definitions do not return a table
-- meaning they use ex. Circle = Object:extend() instead of 'local Circle = Object:extend() return Circle'
-- function requireFiles(files)
-- for _, file in ipairs(files) do
-- local file = file:sub(1, -5)
-- require(file)
-- end
-- end
function love.run()
if love.load then love.load(love.arg.parseGameArguments(arg), arg) end
-- We don't want the first frame's dt to include time taken by love.load.
if love.timer then love.timer.step() end
local dt = 0
-- Main loop time.
return function()
-- Process events.
if love.event then
love.event.pump()
for name, a,b,c,d,e,f in love.event.poll() do
if name == "quit" then
if not love.quit or not love.quit() then
return a or 0
end
end
love.handlers[name](a,b,c,d,e,f)
end
end
-- Update dt, as we'll be passing it to update
if love.timer then dt = love.timer.step() end
-- Call update and draw
if love.update then love.update(dt) end -- will pass 0 if love.timer is disabled
if love.graphics and love.graphics.isActive() then
love.graphics.origin()
love.graphics.clear(love.graphics.getBackgroundColor())
if love.draw then love.draw() end
love.graphics.present()
end
if love.timer then love.timer.sleep(0.001) end
end
end