-
Notifications
You must be signed in to change notification settings - Fork 17
/
portalparticle.lua
48 lines (40 loc) · 1.28 KB
/
portalparticle.lua
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
38
39
40
41
42
43
44
45
46
47
48
portalparticle = class("portalparticle")
function portalparticle:init(x, y, color, direction)
self.x = x or 0
self.y = y or 0
self.timer = 0
self.color = color or {1, 1, 1, 0}
self.direction = direction
self.speedx, self.speedy = 0, 0
if self.direction == "left" then
self.speedx = -portalparticlespeed
elseif self.direction == "right" then
self.speedx = portalparticlespeed
elseif self.direction == "up" then
self.speedy = -portalparticlespeed
elseif self.direction == "down" then
self.speedy = portalparticlespeed
end
end
function portalparticle:update(dt)
self.timer = self.timer + dt
self.x = self.x + self.speedx*dt
self.y = self.y + self.speedy*dt
self.speedx = self.speedx + math.random(-10, 10)/70
self.speedy = self.speedy + math.random(-10, 10)/70
if self.direction == "up" then
if self.speedy > 0 then
self.speedy = 0
end
end
if self.timer > portalparticleduration then
return true
end
return false
end
function portalparticle:draw()
local r, g, b = unpack(self.color)
local a = (1 - self.timer/portalparticleduration)
love.graphics.setColor(r, g, b, a)
love.graphics.draw(portalparticleimg, math.floor((self.x-xscroll)*16*scale), math.floor((self.y-yscroll-.5)*16*scale), 0, scale, scale, .5, .5)
end