|
Post by Carl on Mar 13, 2013 18:47:08 GMT
From Julz
MiniRace is a tiny racing game, written in FIGnition Forth in <400 bytes:
5 var seed : rnd ( range -- random ) seed @ 1+ 75 * dup seed ! u* swap drop ;
( the graphic image for the car) hex 0BAFE var udg 0BA38 , 28AA , 0FE82 , decimal
( copy it to the UDG area) udg vram 608 + 8 cmove
( pause for delay/50ths of a second) : pause ( delay -- ) clock i@ + begin dup clock i@ - 0< until drop ;
( choose the start position for the next bit of road) : nupath 3 rnd 1- + 0 max 20 min ;
0 var hit
( has the car hit the side of the road?) : hit? 2dup 25 * + vram + ic@ hit ! ;
( create the next strip of road) : path 24 23 at cr 25 0 do i over < over 4 + i < or 128 and 32 + emit loop ;
( handle moving the car, left or right) : mv swap dup inkey dup 8 = swap 9 = 1 and + + 0 max 24 min dup 12 hit? at 1 emit swap 11 at 32 emit swap ;
0 var sc
( update the score) : score 1 sc +! 0 0 at sc @ . ;
( put everything together) : race cls 12 10 0 sc ! begin nupath path mv score >r over pause r> hit @ 32 = 0= until ;
|
|