Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- math.randomseed(os.time())
- math.random()
- local NB_STARS = 70
- local Star = {}
- Star.__index = Star
- function Star:new()
- return setmetatable({
- x = math.random(0, g2d.SCR_W),y = math.random(0, g2d.SCR_H),
- color = g2d.WHITE, far = math.random(0, 255)
- },
- self)
- end
- function Star:draw()
- g2d.SetCoordXY(self.x, self.y)
- g2d.SetColor(self.color)
- g2d.SetAlpha(self.far)
- g2d.Add()
- end
- function Star:move()
- self.x = self.x + self.far/200
- if(self.x > g2d.SCR_W) then
- self.x, self.y = 0, math.random(0, g2d.SCR_H)
- self.far = math.random(0, 255)
- end
- end
- local star = {}
- for i = 1, NB_STARS do
- star[i] = Star:new()
- end
- while true do
- g2d.Clear(g2d.BLACK)
- g2d.BeginPoints(g2d.VOID)
- for i = 1, NB_STARS do
- star[i]:move()
- star[i]:draw()
- end
- g2d.End()
- g2d.Flip(g2d.VSYNC)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement