2019-03-09 23:49:45 +00:00
|
|
|
0 const EVTICK
|
|
|
|
1 const EVTOUCH
|
|
|
|
|
2019-03-10 23:51:24 +00:00
|
|
|
: world>tile 4 >> swap 4 >> swap ;
|
|
|
|
: tile>world 4 << swap 4 << swap ;
|
|
|
|
|
|
|
|
: defentity ( x y dir anim -- ) array ' drop , , , tile>world , , ;
|
2019-03-09 23:49:45 +00:00
|
|
|
: entity.x 4 cells + ;
|
|
|
|
: entity.y 3 cells + ;
|
|
|
|
: entity.dir 2 cells + ;
|
|
|
|
: entity>sprite cell + @ execute ;
|
|
|
|
: entity>do ( entity event ) swap @ execute ;
|
2019-03-10 00:59:52 +00:00
|
|
|
: entity>pos dup entity.x @ swap entity.y @ ;
|
|
|
|
: entity.pos! ( x y entity ) <rot over entity.x ! entity.y ! ;
|
2019-03-09 23:49:45 +00:00
|
|
|
|
|
|
|
var entity-defstate
|
|
|
|
: entitydo-ev ( [cp ifhere] ev -- )
|
|
|
|
entity-defstate @ if swap [ ' then , ]
|
|
|
|
else 1 entity-defstate ! :noname swap then
|
|
|
|
' dup , lit ' = , [ ' if , ] ;
|
|
|
|
: :touch EVTOUCH entitydo-ev ; immediate
|
|
|
|
: :tick EVTICK entitydo-ev ; immediate
|
|
|
|
: ;entity ( entity cp ifhere -- )
|
|
|
|
[ ' then , ] ' drop , [ ' ; , ]
|
|
|
|
0 entity-defstate ! swap ! ; immediate
|
|
|
|
|
|
|
|
0 const W
|
|
|
|
1 const E
|
|
|
|
2 const N
|
|
|
|
3 const S
|
|
|
|
|
|
|
|
: dir>pos ( dir -- dx dy )
|
|
|
|
dup W = if drop -1 0 ret then
|
|
|
|
dup E = if drop 1 0 ret then
|
|
|
|
N = if 0 -1
|
|
|
|
else 0 1 then ;
|
|
|
|
|
|
|
|
: frame ( s n e w ) b, b, b, b, ;
|
|
|
|
array frames
|
|
|
|
( 0: car ) 3 1 0 2 frame
|
|
|
|
( 1: pete stand ) 11 9 7 5 frame
|
|
|
|
( 2: pete walk ) 12 10 8 6 frame
|
|
|
|
|
|
|
|
: sprindex ( dir frame ) 2 << frames + + b@ ;
|
|
|
|
: defstatic ( frame -- ) create b, does> b@ sprindex ;
|
|
|
|
: defanim ( frame... framecount ticks-per-frame -- )
|
|
|
|
create b, dup b, 0 for b, next
|
|
|
|
does> ( dir a -- )
|
|
|
|
dup dup 1 + b@ swap b@ ( dir a count tpf )
|
|
|
|
ticks swap / swap % ( dir a index )
|
|
|
|
2 + + b@ sprindex ;
|
|
|
|
|
|
|
|
0 defstatic {car}
|
|
|
|
1 defstatic {pete-stand}
|
|
|
|
1 2 2 5 defanim {pete-walk}
|