2019-02-09 16:48:40 +00:00
|
|
|
: blah
|
|
|
|
' seremit task-emit !
|
|
|
|
' log-emit task-echo ! ;
|
2019-02-16 00:39:50 +00:00
|
|
|
|
2019-02-12 04:23:00 +00:00
|
|
|
' seremit task-emit !
|
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
|
|
|
|
|
|
|
|
1 const ^ESC
|
|
|
|
28 const ^ENTER
|
|
|
|
29 const ^CTRL
|
2019-02-18 01:14:56 +00:00
|
|
|
51 const ^<
|
|
|
|
52 const ^>
|
2019-02-09 16:48:40 +00:00
|
|
|
56 const ^ALT
|
|
|
|
57 const ^SPACE
|
|
|
|
72 const ^UP
|
|
|
|
75 const ^LEFT
|
|
|
|
77 const ^RIGHT
|
|
|
|
80 const ^DOWN
|
|
|
|
|
|
|
|
: wait-key ( k -- ) begin dup key-pressed not while suspend repeat drop ;
|
|
|
|
: udelta ( u u -- u )
|
|
|
|
2dup u> if
|
|
|
|
swap -1 swap - + 1 +
|
|
|
|
else
|
|
|
|
swap -
|
|
|
|
then ;
|
|
|
|
: sleep ( count -- )
|
|
|
|
ticks swap begin over ticks udelta over u< while suspend repeat drop drop ;
|
2019-02-11 00:17:58 +00:00
|
|
|
|
|
|
|
defer tick
|
|
|
|
defer draw
|
|
|
|
|
|
|
|
: defentity var 2 cells allot ;
|
|
|
|
: entity.x ;
|
|
|
|
: entity.y cell + ;
|
|
|
|
: entity.dir 2 cells + ;
|
|
|
|
|
|
|
|
0 const W
|
|
|
|
1 const E
|
|
|
|
2 const N
|
|
|
|
3 const S
|
|
|
|
|
2019-02-18 01:14:56 +00:00
|
|
|
: 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 ;
|
|
|
|
|
2019-02-11 00:17:58 +00:00
|
|
|
: defsprite ( s n e w ) b, b, b, b, here 4 - const ;
|
|
|
|
: sprindex ( sprite dir ) + b@ ;
|
|
|
|
|
|
|
|
3 1 0 2 defsprite s_car
|
|
|
|
|
|
|
|
defentity player
|
|
|
|
|
2019-02-18 01:14:56 +00:00
|
|
|
128 player entity.x !
|
|
|
|
128 player entity.y !
|
2019-02-11 00:17:58 +00:00
|
|
|
|
2019-02-12 04:23:00 +00:00
|
|
|
( timer + lerping )
|
|
|
|
: clamp0 ( range val -- i )
|
|
|
|
2dup <= if drop else
|
|
|
|
dup 0 <= if drop drop 0 else
|
|
|
|
swap drop then then ;
|
|
|
|
: >ratio ( range value -- f )
|
2019-02-18 01:14:56 +00:00
|
|
|
over swap clamp0 swap />ratio ;
|
|
|
|
: <ratio ( range ratio -- v ) *<ratio ;
|
2019-02-12 04:23:00 +00:00
|
|
|
: >range ( start end -- start range ) over - ;
|
|
|
|
: <range ( start range -- start end ) over + ;
|
|
|
|
: lerpr ( start end ratio ) r> >range r< <ratio + ;
|
|
|
|
: lerpn ( start1 end1 start2 end2 val )
|
2019-02-24 17:18:34 +00:00
|
|
|
r> >range r< <rot - >ratio lerpr ;
|
2019-02-24 15:14:56 +00:00
|
|
|
: lerp ( start end duration start -- i )
|
|
|
|
ticks udelta ( start end duration delta )
|
2019-02-12 04:23:00 +00:00
|
|
|
>ratio lerpr ;
|
|
|
|
|
|
|
|
: triggered ( duration timer -- b )
|
|
|
|
dup r> @ ticks udelta ( duration delta )
|
|
|
|
2dup <= if drop r< +! 1 else drop drop 0 then ;
|
|
|
|
|
|
|
|
: now! ( timer -- ) ticks swap ! ;
|
|
|
|
|
2019-02-17 00:21:02 +00:00
|
|
|
( F O O T E R )
|
|
|
|
var footer-y
|
|
|
|
0 footer-y !
|
|
|
|
|
|
|
|
: draw-footer footer-y @ split-screen ;
|
|
|
|
|
2019-02-24 17:18:34 +00:00
|
|
|
: text1 6 4 <rot text ;
|
|
|
|
: text2 6 12 <rot text ;
|
2019-02-17 00:21:02 +00:00
|
|
|
: clear s" " dup text1 text2 ;
|
|
|
|
|
2019-02-24 17:18:34 +00:00
|
|
|
: move-to ( target speed p -- )
|
|
|
|
dup r> @ >rot ticks ( from to duration start )
|
2019-02-17 00:21:02 +00:00
|
|
|
begin
|
2019-02-24 15:14:56 +00:00
|
|
|
4dup lerp r@ !
|
2019-02-24 17:18:34 +00:00
|
|
|
<rot dup r@ @ != ( from duration start to !done )
|
2019-02-17 00:21:02 +00:00
|
|
|
while
|
2019-02-24 17:18:34 +00:00
|
|
|
>rot suspend
|
2019-02-24 15:14:56 +00:00
|
|
|
repeat rdrop drop drop drop drop ;
|
2019-02-17 00:21:02 +00:00
|
|
|
|
2019-02-24 17:18:34 +00:00
|
|
|
: show-footer 24 10 footer-y move-to ;
|
|
|
|
: hide-footer 0 10 footer-y move-to ;
|
2019-02-17 00:21:02 +00:00
|
|
|
|
|
|
|
: say1 ( s -- ) clear text1 show-footer ^ENTER wait-key ;
|
|
|
|
: say2 ( s1 s2 -- ) clear text2 text1 show-footer ^ENTER wait-key ;
|
|
|
|
|
2019-02-18 01:14:56 +00:00
|
|
|
( M O U S E )
|
|
|
|
|
|
|
|
var prevbutton
|
|
|
|
: tick-debounce
|
|
|
|
mousebuttons prevbutton ! ;
|
|
|
|
|
|
|
|
1 const MOUSEL
|
|
|
|
: mousedown ( button -- bool ) mousebuttons & ;
|
|
|
|
: clicked ( button -- bool )
|
|
|
|
dup mousedown not swap
|
|
|
|
prevbutton @ & and ;
|
|
|
|
|
|
|
|
( M A P )
|
|
|
|
: +pos ( x1 y1 x2 y2 -- x y )
|
2019-02-24 17:18:34 +00:00
|
|
|
<rot + >rot + swap ;
|
2019-02-18 01:14:56 +00:00
|
|
|
|
|
|
|
var tileselect
|
2019-02-24 22:26:28 +00:00
|
|
|
8 const MAXTILE
|
2019-02-18 01:14:56 +00:00
|
|
|
|
|
|
|
: mouseworldpos mousepos scrollpos +pos ;
|
|
|
|
: mousetile mouseworldpos 4 >> swap 4 >> swap ;
|
|
|
|
: tile ( x y -- ptr ) mapsize drop * + map + ;
|
|
|
|
|
|
|
|
: tick-mapedit
|
|
|
|
tileselect @
|
|
|
|
^< key-pressed if 1 - then
|
|
|
|
^> key-pressed if 1 + then
|
|
|
|
dup 0 < if drop MAXTILE then
|
|
|
|
dup MAXTILE > if drop 0 then
|
|
|
|
tileselect !
|
|
|
|
|
|
|
|
MOUSEL mousedown if tileselect @ mousetile tile b! then ;
|
2019-02-17 00:21:02 +00:00
|
|
|
|
2019-02-24 22:26:28 +00:00
|
|
|
: copy-mapseg ( neww oldw y -- )
|
|
|
|
r> ( oldw neww r: y )
|
|
|
|
2dup min >rot ( copyw neww oldw )
|
|
|
|
r@ * map + ( copyw neww src )
|
|
|
|
swap r< * map + ( copyw src dst )
|
|
|
|
swap <rot memmove ;
|
|
|
|
|
|
|
|
: resize-map ( neww newh -- )
|
|
|
|
swap mapsize r> ( newh neww oldw r: oldh )
|
|
|
|
2dup < if 1 r< else r< 1 - 0 then ( newh neww copyw ystart ylim )
|
|
|
|
for 2dup i copy-mapseg next
|
|
|
|
drop swap mapsize! ;
|
|
|
|
|
2019-02-24 17:18:34 +00:00
|
|
|
: save-map ( filename -- )
|
|
|
|
fdeactivate swap overwrite
|
|
|
|
mapsize swap fput fput
|
|
|
|
mapsize * map fwrite
|
|
|
|
factivate ;
|
|
|
|
|
|
|
|
: load-map ( filename -- )
|
2019-02-24 22:26:28 +00:00
|
|
|
fdeactivate swap open tell .
|
|
|
|
fget tell . fget tell . cr .s
|
2019-02-24 17:18:34 +00:00
|
|
|
2dup * map fread
|
|
|
|
mapsize!
|
|
|
|
factivate ;
|
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 )
|
|
|
|
|
|
|
|
: move-player
|
|
|
|
player entity.dir @ dir>pos
|
|
|
|
dup if swap drop player entity.y ( d v -- )
|
|
|
|
else drop player entity.x then
|
2019-02-24 17:18:34 +00:00
|
|
|
swap 16 * over @ + 4 <rot move-to ;
|
2019-02-18 01:14:56 +00:00
|
|
|
|
|
|
|
: tick-player
|
|
|
|
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
|
|
|
|
if ' move-player JOB send then ;
|
|
|
|
|
|
|
|
: hello-world
|
|
|
|
s" Hello, world!" say1
|
|
|
|
s" How are you" s" today?" say2 ;
|
2019-02-12 04:23:00 +00:00
|
|
|
|
2019-02-17 00:21:02 +00:00
|
|
|
: mode-move
|
|
|
|
tick-player
|
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-11 00:17:58 +00:00
|
|
|
: draw-player
|
|
|
|
player entity.x @
|
|
|
|
player entity.y @
|
|
|
|
s_car player entity.dir @ sprindex
|
|
|
|
draw-sprite ;
|
|
|
|
|
|
|
|
: full-draw
|
|
|
|
player entity.x @ 152 -
|
|
|
|
player entity.y @ 92 -
|
|
|
|
scroll
|
|
|
|
|
|
|
|
draw-player
|
2019-02-18 01:14:56 +00:00
|
|
|
48 64 0 draw-sprite
|
|
|
|
640 640 2 draw-sprite
|
|
|
|
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
|
|
|
|
|
|
|
s" pete.map" load-map
|