1portalparticle = class:new() 2 3function portalparticle:init(x, y, color, direction) 4 self.x = x 5 self.y = y 6 self.timer = 0 7 self.color = color 8 self.direction = direction 9 10 self.speedx, self.speedy = 0, 0 11 if self.direction == "left" then 12 self.speedx = -portalparticlespeed 13 elseif self.direction == "right" then 14 self.speedx = portalparticlespeed 15 elseif self.direction == "up" then 16 self.speedy = -portalparticlespeed 17 elseif self.direction == "down" then 18 self.speedy = portalparticlespeed 19 end 20end 21 22function portalparticle:update(dt) 23 self.timer = self.timer + dt 24 self.x = self.x + self.speedx*dt 25 self.y = self.y + self.speedy*dt 26 27 self.speedx = self.speedx + math.random(-10, 10)/70 28 self.speedy = self.speedy + math.random(-10, 10)/70 29 30 if self.direction == "up" then 31 if self.speedy > 0 then 32 self.speedy = 0 33 end 34 end 35 36 if self.timer > portalparticleduration then 37 return true 38 end 39 40 return false 41end 42 43function portalparticle:draw() 44 local r, g, b = unpack(self.color) 45 local a = (1 - self.timer/portalparticleduration) * 255 46 love.graphics.setColor(r, g, b, a) 47 love.graphics.draw(portalparticleimg, math.floor((self.x-xscroll)*16*scale), math.floor((self.y-.5)*16*scale), 0, scale, scale, .5, .5) 48end