star.lua
900 Bytes
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
star = class:new()
function star:init()
self.x = math.random(100)
self.y = math.random(80)-90
self.speed = math.random(10)+1000
end
function star:update(dt)
if not starmover then
self.y = self.y + self.speed*dt
else
self.y = self.y + math.cos(starmover)*self.speed*dt
self.x = self.x + math.sin(starmover)*self.speed*dt
end
if self.y > 110 or self.y < -10 or self.x > 110 or self.x < -10 then
self.speed = math.random(10)+1000
self.x = math.random(100)
if self.y > 110 then
self.y = self.y-120
elseif self.y < -10 then
self.y = self.y+120
elseif self.x > 110 then
self.x = self.x-120
else
self.x = self.x+120
end
end
end
function star:draw()
local r, g, b = love.graphics.getColor()
love.graphics.setColor(255, 255, 255, 255*staralpha)
draw(starimg, self.x, self.y, 0, 1, 1, 4.5)
love.graphics.setColor(r, g, b)
end