-
Notifications
You must be signed in to change notification settings - Fork 1
/
comets.lua
51 lines (34 loc) · 1.01 KB
/
comets.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
comet = {}
for i = -10, 10, 4 do
table.insert(comet, i)
end
function comet:new()
self.e = true
self.dx = self[math.random(#self)]
self.dy = self[math.random(#self)]
if math.random(2) > 1 then
self.x = love.graphics.getWidth()/2 - self.dx/math.abs(self.dx) * love.graphics.getWidth()/2
self.y = math.random(0, love.graphics.getHeight())
else
self.x = math.random(0, love.graphics.getWidth())
self.y = love.graphics.getHeight()/2 - self.dy/math.abs(self.dy) * love.graphics.getHeight()/2
end
end
function comet:update(dt)
self.x = self.x + self.dx * dt * 0x40
self.y = self.y + self.dy * dt * 0x40
if self.x < - love.graphics.getWidth() or self.x > love.graphics.getWidth() * 2
or self.y < - love.graphics.getWidth() or self.y > love.graphics.getHeight() * 2 then
self.e = nil
end
end
function comet:draw()
for i = 16, 1, -1 do
local c = 0x80/i
love.graphics.setColor(0xff, 0xff, 0xff, c)
love.graphics.line(
self.x, self.y,
self.x - i * self.dx, self.y - i * self.dy
)
end
end