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
46 pf
.name
= get_rotated_name(pf
.name
)
48 pf
.arrows
= shape_to_arrows(pf
.shape
)
50 playfield
[x
][y
].phase
= 0
54 update
= function(self
)
55 playfield
[x
][y
].phase
= self
.step
/ 5 * turns
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
68 after
= {[laststep
] = function(self
)
69 playfield
[x
][y
].arrows
[direction
] = false
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')
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
83 update
= function(self
)
84 playfield
[x
][y
].arrows
[direction
] = self
.step
/ 10
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
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
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)
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
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
145 update
= function(self
)
146 playfield
[x
][y
].arrowgiftphase
= .4 + .6 * self
.step
/ laststep