Don't transfer devil status and rotate arrow which is just passing into memory.
[poca-love.git] / anim.lua
blob0bbd443b34a2377fe9c7adee414d1d697315bbe6
1 anim = {}
3 function animate(thing, dt, index)
4 --[[ This function keeps timing of running animations,
5 which are represented by "anim" array and drawn elsewhere.
6 Member has to have at least step, laststep, delay and speed defined.
7 Optional: paused, delay - postpones animation;
8 after[s]() is function to be executed after step s
9 update() is function to be executed at each step
11 if thing.paused then return end
12 thing.delay = thing.delay - dt
13 if thing.delay < 0 then
14 if thing.update then thing:update() end
15 if thing.after and thing.after[thing.step] then thing.after[thing.step]() end
16 thing.delay = thing.speed
17 thing.step = thing.step + 1
18 if thing.step > thing.laststep then
19 anim[index] = nil
20 end
21 end
22 end
25 function update_anim(dt)
26 if game.phase == 'play' then return end
27 for a, b in pairs(anim) do animate(b, dt, a) end
28 if not next(anim) then
29 next_phase()
30 end
31 end
34 function rotate_arrows(x, y, turns)
35 turns = turns or 1
36 local laststep = 6
37 table.insert(anim, {
38 paused = false,
39 step = 1,
40 laststep = laststep,
41 after = {[laststep] = function(self)
42 -- after animation, switch shape and redefine arrows
43 local pf = playfield[x][y].memory or playfield[x][y]
44 if turns % 2 == 1 then
45 if pf.shape == 'x' then pf.shape = '+' else pf.shape = 'x' end
46 pf.name = get_rotated_name(pf.name)
47 end
48 pf.arrows = shape_to_arrows(pf.shape)
49 pf.center = nil
50 playfield[x][y].phase = 0
51 end},
52 delay = 0,
53 speed = 0.1,
54 update = function(self)
55 playfield[x][y].phase = self.step / 5 * turns
56 end
58 end
61 function explode_arrow(x, y, direction, distance, kill, target)
62 -- arrows with kill=true show dead player at the end of animation
63 local laststep = distance * 10 - 5
64 table.insert(anim, {
65 paused = paused,
66 step = 1,
67 laststep = laststep,
68 after = {[laststep] = function(self)
69 playfield[x][y].arrows[direction] = false
70 if kill then
71 game.showkill = true
72 -- remove arrows so they don't cause error when reviving memories
73 --playfield[playfield.clickedx][playfield.clickedy].arrows = nil
74 -- just empty the tile
75 playfield[playfield.clickedx][playfield.clickedy] = recognizeink('R')
76 end
77 -- yellow arrows are marked with dot here, not earlier,
78 -- so that it blends with exploding arrow animation
79 if target then target.center = 'dot' end
80 end},
81 delay = 0,
82 speed = 0.02,
83 update = function(self)
84 playfield[x][y].arrows[direction] = self.step / 10
85 end
87 end
90 function grow_arrows(x, y)
91 -- this animation grows base of regenerating arrows
92 -- by changing the phase from -1 to 0
93 playfield[x][y].phase = -1
94 local laststep = 5
95 table.insert(anim, {
96 paused = false,
97 step = 1,
98 laststep = laststep,
99 delay = 0,
100 speed = 0.1,
101 update = function(self)
102 playfield[x][y].phase = (self.step - laststep) / laststep
108 function animate_gifts()
109 game.phase = 'opengifts'
110 playfield.giftsphase = 0
111 local laststep = 10
112 table.insert(anim, {
113 paused = false,
114 step = 1,
115 laststep = laststep,
116 after = {[laststep] = function(self)
117 -- unset ingift for opened gifts in case some additional gifts be created
118 inplayfield(function (x, y, p) p.ingift = nil end)
119 end},
120 delay = 0,
121 speed = 0.1,
122 update = function(self)
123 playfield.giftsphase = 1 - (laststep - self.step) / laststep
129 function animate_arrow_gift(x, y)
130 --game.phase = 'openarrowgift'
131 playfield[x][y].arrowgiftphase = .4
132 local laststep = 10
133 table.insert(anim, {
134 paused = false,
135 step = 1,
136 laststep = laststep,
137 after = {[laststep] = function(self)
138 -- acknowledge arrowgift
139 playfield[x][y].arrowgiftphase = nil
140 playfield[x][y] = playfield[x][y].arrowgift
141 if playfield[x][y].kind == 'gift' then fill_gifts(game.currentlevel) end
142 end},
143 delay = 0,
144 speed = 0.1,
145 update = function(self)
146 playfield[x][y].arrowgiftphase = .4 + .6 * self.step / laststep