Advertisement
Juaxix

Asteroides - Codea game - 4/10 - Explosion.lua

Nov 7th, 2011
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.00 KB | None | 0 0
  1. Explosion = class()
  2.  
  3. function Explosion:init(pos,ecolor,points)
  4.     self.position = pos
  5.     self.opacity = 255
  6.     self.time = 0
  7.     self.lines = {}
  8.     self.ecolor= ecolor
  9.     sound("explode",967)
  10.     self.text = points
  11.     for i = 1,10 do
  12.         dir = vec2(0,1)
  13.         dir = dir:rotate( math.rad(math.random(360)) )
  14.         table.insert( self.lines, dir*math.random(2,7) )
  15.     end
  16. end
  17.  
  18. function Explosion:isDone()
  19.     return self.opacity <= 0
  20. end
  21.  
  22. function Explosion:draw()
  23.     self.time = self.time + 0.5
  24.     
  25.     pushStyle()
  26.  
  27.     lineCapMode(ROUND)
  28.     strokeWidth(20)
  29.     smooth()
  30.     local e = self.ecolor
  31.     stroke(e.r,e.g,e.b,math.max(self.opacity,0))
  32.  
  33.     local p = self.position
  34.     for i,v in ipairs(self.lines) do
  35.         vt = p + v * self.time
  36.         line(p.x, p.y, vt.x, vt.y) 
  37.     end
  38.  
  39.     self.opacity = 255 * (1 - (self.time/30))
  40.  
  41.     popStyle()
  42.     drawText(""..self.text,2,1,p.x,p.y)
  43. end
  44.  
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement