-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsnow.lua
63 lines (54 loc) · 1.79 KB
/
snow.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
--name snow
--desc simple script to showcase classes in lua that draws snow particles.
--author sekc
local SNOW_AMOUNT = 400
local SNOW_SIZE = 1.5
-- create Snowflake class
Snowflake = {x = 0, y = 0, dx = 10, dy = 100}
function Snowflake:new(x, y, dx, dy)
o = {}
setmetatable(o, self)
self.__index = self
o.x = x
o.y = y
o.dx = dx
o.dy = dy
return o
end
function Snowflake:draw()
draw.filledCircle(Vec2(self.x % draw.getScreenSize().x, self.y % draw.getScreenSize().y), SNOW_SIZE, ui.getConfigCol("snow color"))
self.x = self.x + (self.dx * draw.deltaTime())
self.y = self.y + (self.dy * draw.deltaTime())
end
-- create table filled with SNOW_AMOUNT amount of Snowflake objects
local snow = {}
for i=1,SNOW_AMOUNT do
snow[i] = Snowflake:new(math.random(0, draw.getScreenSize().x), math.random(0, draw.getScreenSize().y), math.random(-10, 10), math.random(100, 140))
end
function doSnow()
if not ui.getConfigBool("snow only when menu open") or ui.isMenuOpen() then
-- loop through all items in snow table and run draw()
for i=1,#snow do
snow[i]:draw()
end
end
end
function drawHook()
if ui.getConfigBool("snow behind menu") then
doSnow()
end
end
function drawAboveHook()
if not ui.getConfigBool("snow behind menu") then
doSnow()
end
end
function uiHook()
ui.colorPicker("snow color", "snow color")
-- use ##snow here as "only when menu open" and "draw behind menu" are commonly used widget labels and may clash with other luas
ui.checkbox("draw behind menu##snow", "snow behind menu")
ui.checkbox("only when menu open##snow", "snow only when menu open")
end
eclipse.registerHook("draw", drawHook)
eclipse.registerHook("drawabove", drawAboveHook)
eclipse.registerHook("UI", uiHook)