Advertisement
JiiCeii

[PC/gLib2D] star.lua

Sep 16th, 2011
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.83 KB | None | 0 0
  1. math.randomseed(os.time())
  2. math.random()
  3.  
  4. local NB_STARS = 70
  5.  
  6. local Star = {}
  7. Star.__index = Star
  8.  
  9. function Star:new()
  10.     return setmetatable({
  11.             x = math.random(0, g2d.SCR_W),y = math.random(0, g2d.SCR_H),
  12.             color = g2d.WHITE, far = math.random(0, 255)
  13.         },
  14.         self)
  15. end
  16.  
  17. function Star:draw()
  18.     g2d.SetCoordXY(self.x, self.y)
  19.     g2d.SetColor(self.color)
  20.     g2d.SetAlpha(self.far)
  21.     g2d.Add()
  22. end
  23.  
  24. function Star:move()
  25.     self.x = self.x + self.far/200
  26.     if(self.x > g2d.SCR_W) then
  27.         self.x, self.y = 0, math.random(0, g2d.SCR_H)
  28.         self.far = math.random(0, 255)
  29.     end
  30. end
  31.  
  32. local star = {}
  33. for i = 1, NB_STARS do
  34.     star[i] = Star:new()
  35. end
  36.  
  37. while true do
  38.     g2d.Clear(g2d.BLACK)
  39.  
  40.     g2d.BeginPoints(g2d.VOID)
  41.         for i = 1, NB_STARS do
  42.             star[i]:move()
  43.             star[i]:draw()
  44.         end
  45.     g2d.End()
  46.  
  47.     g2d.Flip(g2d.VSYNC)
  48. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement