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
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
34 function rotate_arrows(x
, y
, turns
)
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
47 pf
.arrows
= shape_to_arrows(pf
.shape
)
49 playfield
[x
][y
].phase
= 0
53 update
= function(self
)
54 playfield
[x
][y
].phase
= self
.step
/ 5 * turns
60 function explode_arrow(x
, y
, direction
, distance
, kill
, target
)
61 -- arrows with kill=true show dead player at the end of animation
62 local laststep
= distance
* 10 - 5
67 after
= {[laststep
] = function(self
)
68 playfield
[x
][y
].arrows
[direction
] = false
71 -- remove arrows so they don't cause errror when reviving memories
72 playfield
[playfield
.clickedx
][playfield
.clickedy
].arrows
= nil
74 -- yellow arrows are marked with dot here, not earlier,
75 -- so that it blends with exploding arrow animation
76 if target
then target
.center
= 'dot' end
80 update
= function(self
)
81 playfield
[x
][y
].arrows
[direction
] = self
.step
/ 10
87 function grow_arrows(x
, y
)
88 -- this animation grows base of regenerating arrows
89 -- by changing the phase from -1 to 0
90 playfield
[x
][y
].phase
= -1
98 update
= function(self
)
99 playfield
[x
][y
].phase
= (self
.step
- laststep
) / laststep
105 function animate_gifts()
106 game
.phase
= 'opengifts'
107 playfield
.giftsphase
= 0
113 after
= {[laststep
] = function(self
)
114 -- unset ingift for opened gifts in case some additional gifts be created
115 inplayfield(function (x
, y
, p
) p
.ingift
= nil end)
119 update
= function(self
)
120 playfield
.giftsphase
= 1 - (laststep
- self
.step
) / laststep
126 function animate_arrow_gift(x
, y
)
127 --game.phase = 'openarrowgift'
128 playfield
[x
][y
].arrowgiftphase
= .4
134 after
= {[laststep
] = function(self
)
135 -- acknowledge arrowgift
136 playfield
[x
][y
].arrowgiftphase
= nil
137 playfield
[x
][y
] = playfield
[x
][y
].arrowgift
138 if playfield
[x
][y
].kind
== 'gift' then fill_gifts(game
.currentlevel
) end
142 update
= function(self
)
143 playfield
[x
][y
].arrowgiftphase
= .4 + .6 * self
.step
/ laststep