Skip to content

Instantly share code, notes, and snippets.

@fbwright
Last active August 29, 2015 14:15
Show Gist options
  • Save fbwright/98a1aacbd4a4c5c30ee2 to your computer and use it in GitHub Desktop.
Save fbwright/98a1aacbd4a4c5c30ee2 to your computer and use it in GitHub Desktop.
frogue.fs
( frogue.fs 2015-02-23T09.05 by fbwright )
( A [simple] roguelike in gforth; move the @, collide with # )
( And [comments excluded] fits into a block [1000/1024 B] )
variable &i 64 constant W 16 constant H create _M W H * chars
allot 6 constant MS 32 constant MM create _O MS MM * chars allot
: U 0 -1 ; : D 0 1 ; : R 1 0 ; : L -1 0 ; : # W * + _M + ; : &
MS * _O + ; : b? H 1- mod 0= swap W 1- mod 0= or ; : p? c@ '# <>
; : #d 2dup at-xy # c@ emit ; : #n 2dup # -rot b? if '# else bl
then swap c! ; : &xy@ & 1+ dup c@ swap 1+ c@ ; : &xy! & 1+ rot
over c! 1+ c! ; : &d dup &xy@ at-xy & c@ emit ; : &n &i @ & swap
if '@ else 'Z then swap c! &i @ &xy! 1 &i +! ; : +d rot + -rot +
swap ; : &m { n } n &xy@ +d 2dup # p? if n &xy@ #d n &xy! else
2drop then ; : (#) { x } H 0 u+do W 0 u+do i j x execute loop
loop ; : (&) { x } &i @ 0 u+do i x execute loop ; : @m 0 &m ;
: g# ['] #n (#) ; : d# page ['] #d (#) ; : g& 20 8 0 &n ; : d&
['] &d (&) ; : g@ W 2 / H 2 / -1 &n ; : g g# g@ g& ; : hK 0 0 H
at-xy key case 'i of U @m endof 'k of D @m endof 'l of R @m
endof 'j of L @m endof 'Q of drop -1 endof ." Unknown command."
endcase ; : main g d# begin d& hk until bye ; main
@fbwright
Copy link
Author

Still doesn't do anything; you can use I|J|K|L to move the @ around, there are walls around the map and it clears the space behind the player, but nothing else.
You can move on the walls and delete (not really, they are still on the map, but they don't show up) them, and go beyond the screen. Sooo... just testing the waters.

@fbwright
Copy link
Author

I just rewrote it from scratch, and then golfed it. It now handles collisions (terrain only) and has facilities for mobs (the player is nothing more than mob 0). Still no items, the mobs are anything but (they are "mobiles", but they don't move) and there is no victory condition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment