-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstar.lua
More file actions
54 lines (48 loc) · 1.15 KB
/
star.lua
File metadata and controls
54 lines (48 loc) · 1.15 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
constants = require 'constants'
---@diagnostic disable: lowercase-global, undefined-global
---@
COLORS = {
WHITE = { 1, 1, 1 },
BLACK = { 0.1, 0.1, 0.1 },
}
COLORS_ARRAY = {
COLORS.WHITE,
COLORS.BLACK,
}
function drawStar()
love.graphics.push()
for i = 1, #stars do
local star = stars[i]
love.graphics.setColor(star.color)
love.graphics.circle(
'fill',
star.x,
star.y,
star.radius
)
end
love.graphics.pop()
end
function createStars(numStars)
stars = {}
for i = 1, numStars do
table.insert(stars, {
x = math.random(0, VIRTUAL_WIDTH),
y = math.random(0, VIRTUAL_HEIGHT),
radius = math.random(0.1, 1.1),
speed = math.random(20, 314),
color = COLORS_ARRAY[math.random(#COLORS_ARRAY)]
})
end
return stars
end
function animateStars(dt)
for i = 1, #stars do
local star = stars[i]
star.y = star.y + star.speed * dt
if star.y > VIRTUAL_HEIGHT then
star.y = 0
star.x = math.random(0, VIRTUAL_WIDTH)
end
end
end