-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathSnow.lua
More file actions
49 lines (45 loc) · 1.06 KB
/
Snow.lua
File metadata and controls
49 lines (45 loc) · 1.06 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
----------------- 下雪动画 ----------------
Snow = Class("Snow",GameObject)
local circles={}
function Snow:init(x,y,sets)
self.x = x
self.y = y
local sets = sets or {}
for k, v in pairs(sets) do
self[k] = v
end
self.dead = false
self.cd = 0
local n = self.n or 40
local w = 1280
local h = 720
for i=1,n do
local x,y = math.random(1, w),math.random(1, h)
local radius = math.random(6, 14)
local color = {1,1,1,math.random(0.1,0.5)}
circle = {x=x,y=y,r=radius,color=color}
table.insert(circles, circle)
end
end
function Snow:draw()
for _,v in ipairs(circles) do
love.graphics.setColor(v.color)
love.graphics.circle("fill",v.x,v.y,v.r-1)
love.graphics.circle("fill",v.x,v.y,v.r-2)
love.graphics.circle("fill",v.x,v.y,v.r-3)
love.graphics.circle("fill",v.x,v.y,v.r-4)
love.graphics.circle("fill",v.x,v.y,v.r-5)
love.graphics.circle("fill",v.x,v.y,v.r-6)
end
end
function Snow:update(dt)
for i = #circles,1,-1 do
v=circles[i]
v.y = v.y + v.r*0.1
if v.y>800 then
v.y=-10
v.x=v.x+math.random(-10, 10)
end
end
end
return Snow