-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.lua
99 lines (82 loc) · 2.43 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
94
95
96
97
98
99
-- _ __
-- / /_)/_/ |/ / /_/ /|//
--/ / \/ / / / / / / */
local util = require("util")
local vec2 = require("lib.vector2")
require("objects")
local opt = require("options")
local charts = require("chartloader")
local vars = require("vars")
local lastMousePos = vec2(love.mouse.getPosition())
MouseVel = vec2(0, 0)
local call = function (func, ...)
if func then
func(...)
end
end
love.mouse.setRelativeMode(true)
local callbacks = {
update = function(dt)
--vars.mousePos = vec2(love.mouse.getPosition())
vars.mouseVel = (vars.mousePos - lastMousePos) / dt
lastMousePos = vars.mousePos
local time = os.clock()
call(vars.state.update, dt)
-- print("update: ", (os.clock() - time) * 1000)
end,
draw = function()
local time = os.clock()
call(vars.state.draw)
-- print("draw: ", (os.clock() - time) * 1000)
love.graphics.circle("fill", vars.mousePos.x, vars.mousePos.y, 5)
end,
mousemoved = function(x, y, dx, dy, istouch)
if not love.window.hasFocus() then return end
local w, h = love.graphics.getDimensions()
if love.mouse.getRelativeMode() then
vars.mousePos = vars.mousePos + vec2(dx, dy)
vars.mousePos.x = math.max(math.min(vars.mousePos.x, w), 0)
vars.mousePos.y = math.max(math.min(vars.mousePos.y, h), 0)
--[[ if vars.mousePos.x <= 0 or vars.mousePos.x >= w or
vars.mousePos.y <= 0 or vars.mousePos.y >= h then
love.mouse.setRelativeMode(false)
love.mouse.setPosition(vars.mousePos.x, vars.mousePos.y)
end --]]
else
x = x + dx
y = y + dy
if x > 0 and x < w and
y > 0 and y < h then
vars.mousePos = vec2(x, y)
love.mouse.setRelativeMode(true)
end
end
end,
mousepressed = function(x, y, button)
call(vars.state.mousepressed, x, y, button)
end,
mousereleased = function(x, y, button)
call(vars.state.mousereleased, x, y, button)
end,
keypressed = function(key, scancode, isrepeat)
call(vars.state.keypressed, key, scancode, isrepeat)
end,
keyreleased = function(key)
call(vars.state.keyreleased, key)
end,
textinput = function(text)
call(vars.state.textinput, text)
end,
wheelmoved = function(x, y)
call(vars.state.wheelmoved, x, y)
end
}
function chartSelect()
for key, value in pairs(callbacks) do
love[key] = value
end
--list:SetVisible(true)
end
chartSelect()
util.loadState("chartselect")
--gameplay.play(require("options").chartName)