61 lines
1.7 KiB
Plaintext
Executable file
61 lines
1.7 KiB
Plaintext
Executable file
0 const EVTICK
|
|
1 const EVTOUCH
|
|
|
|
: world>tile 4 >> swap 4 >> swap ;
|
|
: tile>world 4 << swap 4 << swap ;
|
|
|
|
: defentity ( x y dir anim -- ) array ' drop , , , tile>world , , ;
|
|
: entity.x 4 cells + ;
|
|
: entity.y 3 cells + ;
|
|
: entity.dir 2 cells + ;
|
|
: entity>sprite cell + @ execute ;
|
|
: entity>do ( entity event ) swap @ execute ;
|
|
: entity>pos dup entity.x @ swap entity.y @ ;
|
|
: entity.pos! ( x y entity ) <rot over entity.x ! entity.y ! ;
|
|
|
|
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 ;
|
|
: defsingle ( sprindex -- ) create b, does> swap drop b@ ;
|
|
: 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}
|
|
13 defsingle {pete-table}
|
|
14 defsingle {chair}
|
|
15 defsingle {pete-bed}
|
|
16 defsingle {horse}
|