1 ! (c)2010 Joe Groff bsd license
2 USING: accessors kernel locals math papier.map sequences typed ;
9 TUPLE: animation-cursor
14 : <animation-cursor> ( animation -- cursor )
15 0 0 animation-cursor boa ; inline
17 TYPED:: inc-cursor ( cursor: animation-cursor -- )
18 cursor [ time>> ] [ frame>> ] [ animation>> ] tri :> ( time# frame# animation )
19 frame# animation nth :> frame
21 time' frame duration>> = [
23 frame' animation length = [ 0 ] [ frame' ] if :> frame''
29 cursor time' >>time drop
32 TYPED: cursor-frame ( cursor: animation-cursor -- frame: fixnum )
33 [ frame>> ] [ animation>> nth ] bi slab-frame>> ; inline
35 : cursor++ ( cursor -- frame )
36 [ cursor-frame ] [ inc-cursor ] bi ; inline
38 : ++cursor ( cursor -- frame )
39 [ inc-cursor ] [ cursor-frame ] bi ; inline
43 { cursor animation-cursor } ;
45 : <sprite> ( -- sprite ) sprite new ; inline
47 : start-animation ( sprite animation -- sprite )
48 <animation-cursor> [ >>cursor ] keep
49 cursor-frame >>frame ; inline
51 : switch-animation ( sprite animation -- sprite )
52 2dup swap cursor>> animation>> eq?
53 [ drop ] [ start-animation ] if ; inline
55 : set-up-sprite ( animations sprite -- sprite )
58 first start-animation ; inline
60 : inc-sprite ( sprite -- sprite )
61 dup cursor>> ++cursor >>frame ; inline