forked from alesan99/mari0_ae
-
Notifications
You must be signed in to change notification settings - Fork 1
/
emancipateanimation.lua
65 lines (53 loc) · 2.17 KB
/
emancipateanimation.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
emancipateanimation = class:new()
emancemaxspeed = 3
emanceaccel = 20
function emancipateanimation:init(x, y, width, height, img, quad, speedx, speedy, rotation, offsetX, offsetY, quadcenterX, quadcenterY)
self.x = x
self.y = y
self.width = width
self.height = height
self.img = img
self.quad = quad
self.speedx = speedx
self.speedy = speedy
self.rotation = rotation
self.offsetX = offsetX
self.offsetY = offsetY
self.quadcenterX = quadcenterX
self.quadcenterY = quadcenterY
self.speedx = math.max(-emancemaxspeed, math.min(emancemaxspeed, self.speedx))
self.speedy = math.max(-emancemaxspeed, math.min(emancemaxspeed, self.speedy))
self.rotationspeed = (math.random()-.5)*8
self.timer = 0
self.timer2 = 0
end
function emancipateanimation:update(dt)
self.speedx = self.speedx + (math.random()-.5)*dt*emanceaccel
self.speedy = self.speedy + (math.random()-.5)*dt*emanceaccel
self.x = self.x + self.speedx*dt
self.y = self.y + self.speedy*dt
self.rotation = self.rotation + self.rotationspeed*dt
if self.timer < emancipateanimationtime-emancipatefadeouttime then
self.timer2 = self.timer2 + dt
while self.timer2 > emancipationfizzledelay do
table.insert(emancipationfizzles, emancipationfizzle:new(self.x+math.random()*self.width, self.y+math.random()*self.height, self.speedx, self.speedy))
self.timer2 = self.timer2 -emancipationfizzledelay
end
end
self.timer = self.timer + dt
if self.timer > emancipateanimationtime then
return true
else
return false
end
end
function emancipateanimation:draw()
local black = 1-self.timer/emancipateanimationtime
local a = math.min(1, 1-(self.timer-(emancipateanimationtime-emancipatefadeouttime))/emancipatefadeouttime)
love.graphics.setColor(black, black, black, a)
if self.quad then
love.graphics.draw(self.img, self.quad, math.floor(((self.x-xscroll)*16+self.offsetX)*scale), math.floor(((self.y-yscroll)*16-self.offsetY)*scale), self.rotation, scale, scale, self.quadcenterX, self.quadcenterY)
else
love.graphics.draw(self.img, math.floor(((self.x-xscroll)*16+self.offsetX)*scale), math.floor(((self.y-yscroll)*16-self.offsetY)*scale), self.rotation, scale, scale, self.quadcenterX, self.quadcenterY)
end
end