wizardhatreal

I Did Forth

i wrote some forth

Forth is an interesting language and if I were to continue writing this code I would most certanly write it using pick instead of what i did I did try this on OpenBoot on an Ultra 25 and it does work there.

This is a very simple “game” I made where you can move a letter around with wasd.

2variable playercoords
12 12 playercoords 2!
page
: chardraw ( char x y -- )
        at-xy
        emit
;

: collision_check ( a b ex ey -- ex ey flag )
        ( do a+ex b+ey so i can check against it before commiting)
        rot
        swap
        +
        rot
        rot
        +
        swap

        2dup

        25
        <
        0=

        swap
        64
        <
        0=
        or

;

: entitymove ( char a b ex ey -- ex ey)
        2dup at-xy space

        collision_check
        if
        [char] G emit
        else

        ( stack stupidity to do a 3dup and chardraw and return ex and ey)
        2dup
        0
        2rot
        swap
        rot
        drop
        dup
        2rot
        swap
        chardraw
        drop
        swap
        then
;


: playermove
        [char] A
        rot rot
        playercoords 2@
        entitymove
        playercoords 2!

;

: up 0 -1 ;
: down 0 1 ;
: left -1 0 ;
: right 1 0 ;


: zombiegame ( -- )

begin

        key? if

        key
        case
                [char] w of up playermove endof
                [char] a of left playermove endof
                [char] s of down playermove endof
                [char] d of right playermove endof
        endcase




        then

again

;

zombiegame