-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
192 lines (140 loc) · 4.13 KB
/
main.lua
File metadata and controls
192 lines (140 loc) · 4.13 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
flowerM = require("scripts/garden/flowerM")
altarM = require("scripts/garden/altarM")
gardenM = require("scripts/garden/gardenM")
doorwayM = require("scripts/garden/doorwayM")
minigameM = require("scripts/garden/minigameM")
sceneM = require("scripts/util/sceneM")
infernoIntermission = require("scripts/inferno/infernoIntermission")
infernoM = require("scripts/inferno/infernoM")
layerV = require("scripts/inferno/layerVisuals")
playerM = require("scripts/inferno/playerM")
enemyM = require("scripts/inferno/enemyM")
battleM = require("scripts/inferno/battleM")
util = {}
util.sprites = require("scripts/util/sprites")
util.tween = require("scripts/util/tween")
util.time = require("scripts/util/time")
util.input = require("scripts/util/input")
util.text = require("scripts/util/text")
util.hitbox = require("scripts/util/hitbox")
util.dialogue = require("scripts/util/dialogue")
lang = require("localization/en_us")
cpf = 0
local paused = false
function love.focus(f)
paused = not f
end
cam = {
x = 0,
y = -50,
projX=0,
zoom = 5,
rot = 0,
yAddition = 0
}
cam.shake = function(strength)
cam.rot = math.rad(strength)
util.tween:tweenProperty(cam, "rot", 0, 1.5, "CamMoveRot", "out")
end
cam.zoomModifier = 1
function love.load()
love.graphics.setDefaultFilter("nearest", "nearest")
love.graphics.setBackgroundColor(0,0,0)
math.randomseed(os.time() + love.timer.getTime() * 1000)
baseWidth = 1466
baseHeight = 868
util.input:load()
util.sprites:load()
util.time:load()
util.text:load()
util.hitbox:load()
util.dialogue:load()
sceneM:load()
for s,s1 in pairs(sceneM.scenes) do
for f,f1 in ipairs(s1.managers) do
if f1.load ~= nil then f1:load() end
end
end
end
function love.update(dt)
if paused then
return
end
util.tween:update(dt)
util.time:update(dt)
sceneM:update(dt)
util.input:cleanup(dt)
util.hitbox:update(dt)
util.dialogue:update(dt)
if util.input.mousejustpressed then
util.input.mousejustpressed = false
util.input:loopClickers()
end
cpf = 0
end
function love.keypressed(key, scancode, isrepeat)
if sceneM.scenes[sceneM.activeScene] ~= nil then
for f,f1 in ipairs(sceneM.scenes[sceneM.activeScene].managers) do
if f1.keypressed ~= nil then
f1:keypressed(key, scancode, isrepeat)
end
end
end
if scancode == "i" then
local new = "garden"
if sceneM.activeScene == "garden" then new = "inferno" end
sceneM:switchScene(new)
end
end
function getScaleFactor()
local windowWidth = love.graphics.getWidth()
local windowHeight = love.graphics.getHeight()
return math.min(windowWidth / baseWidth, windowHeight / baseHeight)
end
function getWorldMouse()
local mx, my = love.mouse.getPosition()
local cx = love.graphics.getWidth() / 2
local cy = love.graphics.getHeight() / 2
local dx = mx - cx
local dy = my - cy
local r = -math.rad(cam.rot)
local cosr = math.cos(r)
local sinr = math.sin(r)
local rdx = dx * cosr - dy * sinr
local rdy = dx * sinr + dy * cosr
local scale = (cam.zoom * cam.zoomModifier) * getScaleFactor()
local wx = (rdx / scale) + cam.x
local wy = (rdy / scale) + cam.y
return wx, wy
end
function love.draw()
sceneM:draw()
util.input:draw()
util.hitbox:draw()
util.dialogue:draw()
end
function love.mousepressed(x, y, button, istouch)
if cpf == 0 then
if button == 1 then
cpf = cpf + 1
util.input.mousejustpressed = true
end
end
end
function cam:attach()
love.graphics.push()
love.graphics.translate(
love.graphics.getWidth() / 2,
love.graphics.getHeight() / 2
)
local screenScale = getScaleFactor()
love.graphics.scale((self.zoom * cam.zoomModifier) * screenScale)
love.graphics.rotate(math.rad(self.rot))
love.graphics.translate(-self.x, -self.y)
end
function cam:detach()
love.graphics.pop()
end
function clamp(min, val, max)
return math.max(min, math.min(val, max));
end