2019-03-05 22:35:50 +00:00
|
|
|
: blah ' seremit task-emit ! ;
|
|
|
|
blah
|
2019-02-09 16:48:40 +00:00
|
|
|
|
|
|
|
: start-repl activate blah
|
|
|
|
s" .:: J O R T H ( jean forth) ::." type cr
|
2019-02-11 00:17:58 +00:00
|
|
|
begin receive loadstring s" ok" type cr again ;
|
2019-02-09 16:48:40 +00:00
|
|
|
task const REPL
|
|
|
|
REPL start-repl
|
|
|
|
|
2019-02-11 00:17:58 +00:00
|
|
|
defer tick
|
|
|
|
defer draw
|
|
|
|
|
2019-03-09 23:49:45 +00:00
|
|
|
:noname
|
|
|
|
s" input.jor" loadfile
|
|
|
|
s" entity.jor" loadfile
|
|
|
|
s" timer.jor" loadfile
|
|
|
|
s" footer.jor" loadfile
|
|
|
|
s" map.jor" loadfile
|
|
|
|
; execute
|
2019-02-11 00:17:58 +00:00
|
|
|
|
2019-02-18 01:14:56 +00:00
|
|
|
( J O B )
|
2019-02-17 00:21:02 +00:00
|
|
|
var MODE-MOVE
|
|
|
|
var MODE-WAIT
|
2019-02-12 04:23:00 +00:00
|
|
|
|
2019-02-17 00:21:02 +00:00
|
|
|
: listen-for-jobs activate blah
|
|
|
|
begin receive
|
|
|
|
MODE-WAIT @ ' tick redefine
|
|
|
|
execute
|
|
|
|
hide-footer
|
|
|
|
MODE-MOVE @ ' tick redefine
|
|
|
|
again ;
|
2019-02-12 04:23:00 +00:00
|
|
|
|
2019-02-17 00:21:02 +00:00
|
|
|
task const JOB
|
|
|
|
JOB listen-for-jobs
|
2019-02-12 04:23:00 +00:00
|
|
|
|
2019-02-18 01:14:56 +00:00
|
|
|
( T I C K )
|
2019-03-01 02:46:04 +00:00
|
|
|
defer entities
|
2019-03-09 23:49:45 +00:00
|
|
|
:noname 0 ; ' entities redefine
|
2019-03-01 02:46:04 +00:00
|
|
|
|
|
|
|
: entity-at ( x y -- entity|0 )
|
|
|
|
0 >rot
|
|
|
|
entities each r> 2dup ( 0 x y x y r:e )
|
|
|
|
r@ entity.x @ r@ entity.y @ world>tile 2= ( 0 x y eq r:e )
|
|
|
|
if <rot drop r< >rot break ( e x y )
|
|
|
|
else rdrop then ( 0 x y )
|
|
|
|
more drop drop ;
|
|
|
|
|
|
|
|
( P L A Y E R )
|
|
|
|
var player.state
|
|
|
|
defer player
|
|
|
|
|
|
|
|
1 const MOVING
|
|
|
|
2 const DRIVING
|
|
|
|
|
|
|
|
: {player}
|
|
|
|
player.state DRIVING f@ if {car}
|
|
|
|
else player.state MOVING f@ if {pete-walk}
|
|
|
|
else {pete-stand} then then ;
|
|
|
|
|
2019-02-27 02:44:22 +00:00
|
|
|
: player.canmove? ( x y -- )
|
|
|
|
player.state DRIVING f@ if DRIVABLE else WALKABLE then mapflag? ;
|
2019-02-18 01:14:56 +00:00
|
|
|
|
2019-03-03 01:03:34 +00:00
|
|
|
12 9 N ' {player} defentity player
|
|
|
|
|
2019-03-05 22:35:50 +00:00
|
|
|
: entity-dst ( e -- x y )
|
|
|
|
r> r@ entity.dir @ dir>pos
|
|
|
|
r@ entity.x @ r< entity.y @ world>tile +pos ;
|
|
|
|
|
2019-03-01 02:46:04 +00:00
|
|
|
: move-entity ( e -- )
|
|
|
|
dup entity.dir @ dir>pos ( e dx dy )
|
|
|
|
dup if swap drop swap entity.y
|
|
|
|
else drop swap entity.x then
|
|
|
|
swap 16 * over @ + 4 <rot move-to ;
|
|
|
|
|
2019-02-18 01:14:56 +00:00
|
|
|
: move-player
|
2019-03-03 01:03:34 +00:00
|
|
|
1 player.state MOVING f!
|
|
|
|
player move-entity
|
|
|
|
0 player.state MOVING f! ;
|
|
|
|
|
|
|
|
: out-of-bounds ( x y -- b )
|
|
|
|
2dup 0 < swap 0 < or >rot mapsize ( b x y w h )
|
|
|
|
<rot <= >rot ( b b x w )
|
|
|
|
>= or or ;
|
|
|
|
|
|
|
|
: no-touch drop drop 0 ;
|
|
|
|
defer player-touch ( x y -- b )
|
|
|
|
' no-touch ' player-touch redefine
|
|
|
|
|
|
|
|
: check-player-touch ( x y -- b )
|
|
|
|
2dup entity-at dup if EVTOUCH entity>do drop drop 1 else drop
|
|
|
|
2dup player-touch if drop drop 1 else
|
|
|
|
2dup out-of-bounds if drop drop 1 else
|
|
|
|
player.canmove? if 0 else 1 then then then then ;
|
|
|
|
|
|
|
|
: try-move-player
|
2019-03-05 22:35:50 +00:00
|
|
|
player entity-dst check-player-touch not if move-player then ;
|
|
|
|
|
|
|
|
: check-entity-touch ( x y -- b )
|
|
|
|
2dup entity-at if drop drop 1 else
|
|
|
|
2dup out-of-bounds if 1 else
|
|
|
|
WALKABLE mapflag? if 0 else 1 then then then ;
|
|
|
|
|
|
|
|
: try-move-entity ( e -- )
|
|
|
|
dup entity-dst check-entity-touch not if move-entity then ;
|
2019-03-03 01:03:34 +00:00
|
|
|
|
|
|
|
player :tick
|
2019-02-18 01:14:56 +00:00
|
|
|
0 ^LEFT key-down if drop 1 W player entity.dir ! then
|
|
|
|
^RIGHT key-down if drop 1 E player entity.dir ! then
|
|
|
|
^UP key-down if drop 1 N player entity.dir ! then
|
|
|
|
^DOWN key-down if drop 1 S player entity.dir ! then
|
2019-03-03 01:03:34 +00:00
|
|
|
if ' try-move-player JOB send then
|
|
|
|
;entity
|
2019-03-01 02:46:04 +00:00
|
|
|
|
|
|
|
( S T U F F )
|
2019-02-18 01:14:56 +00:00
|
|
|
: hello-world
|
2019-02-27 02:44:22 +00:00
|
|
|
player.state DRIVING f@ not player.state DRIVING f! ;
|
2019-02-12 04:23:00 +00:00
|
|
|
|
2019-02-17 00:21:02 +00:00
|
|
|
: mode-move
|
2019-03-01 02:46:04 +00:00
|
|
|
entities each EVTICK entity>do more
|
2019-02-18 01:14:56 +00:00
|
|
|
tick-mapedit
|
2019-02-12 04:23:00 +00:00
|
|
|
^SPACE key-pressed if
|
2019-02-17 00:21:02 +00:00
|
|
|
' hello-world JOB send
|
2019-02-18 01:14:56 +00:00
|
|
|
then
|
|
|
|
tick-debounce ;
|
|
|
|
|
2019-02-17 00:21:02 +00:00
|
|
|
' mode-move MODE-MOVE !
|
2019-02-18 01:14:56 +00:00
|
|
|
' tick-debounce MODE-WAIT !
|
2019-02-12 04:23:00 +00:00
|
|
|
|
2019-02-27 02:44:22 +00:00
|
|
|
: draw-entity
|
|
|
|
r> r@ entity.x @ r@ entity.y @
|
2019-03-01 02:46:04 +00:00
|
|
|
r@ entity.dir @ r< entity>sprite
|
2019-02-11 00:17:58 +00:00
|
|
|
draw-sprite ;
|
|
|
|
|
|
|
|
: full-draw
|
|
|
|
player entity.x @ 152 -
|
|
|
|
player entity.y @ 92 -
|
|
|
|
scroll
|
|
|
|
|
2019-03-01 02:46:04 +00:00
|
|
|
entities each draw-entity more
|
2019-02-18 01:14:56 +00:00
|
|
|
mouseworldpos 4 draw-sprite
|
2019-02-17 00:21:02 +00:00
|
|
|
draw-screen
|
|
|
|
draw-footer ;
|
2019-02-11 00:17:58 +00:00
|
|
|
|
2019-02-17 00:21:02 +00:00
|
|
|
MODE-MOVE @ ' tick redefine
|
2019-02-12 04:23:00 +00:00
|
|
|
' full-draw ' draw redefine
|
2019-02-24 22:26:28 +00:00
|
|
|
|
2019-03-01 02:46:04 +00:00
|
|
|
:noname
|
2019-03-09 23:49:45 +00:00
|
|
|
s" pete.jor" loadfile
|
|
|
|
; ' onload redefine
|