Compare commits
5 Commits
main
...
07ad405461
Author | SHA1 | Date |
---|---|---|
Nico | 07ad405461 | |
Nico | 75cc5ec09e | |
Nico | 7eee62f5da | |
Nico | 1406808004 | |
Nico | d134707466 |
59
main.fs
59
main.fs
|
@ -32,7 +32,7 @@ create devices 0e f, -1 ,
|
|||
: old-devices devices float + ;
|
||||
|
||||
\ d/s converts a devices per second value into devices per tick.
|
||||
: d/s 1000e f/ ;
|
||||
: d/s 20e f/ ;
|
||||
|
||||
\ the variable "base-speed" is the base amount of devices added per tick.
|
||||
variable base-speed
|
||||
|
@ -66,15 +66,6 @@ variable screens
|
|||
\ get-message gets the message
|
||||
: get-message ( -- addr len ) message @ message 1 cells + @ swap ;
|
||||
|
||||
\ the map! It's a character array. Every mapize entries is a new row.
|
||||
16 constant mapsize
|
||||
create map mapsize mapsize * allot
|
||||
map mapsize mapsize * 46 fill
|
||||
|
||||
\ "location" takes an x and y and returns the address of that position in the map. 0-indexed.
|
||||
: location ( x y -- a )
|
||||
mapsize * + map + ;
|
||||
|
||||
\ set an initial message
|
||||
S" you feel like throwing some stuff into the pool." set-message
|
||||
|
||||
|
@ -112,8 +103,9 @@ S" you feel like throwing some stuff into the pool." set-message
|
|||
\ the word unlock tests to see if any unlock conditions are matched, and unlocks them if they are.
|
||||
: unlock unlock-members unlock-constructs unlock-detector ;
|
||||
|
||||
\ the word wait-tick waits a tick. Ticks are 1ms currently.
|
||||
: wait-tick 1 ms ;
|
||||
\ the word wait-tick waits a tick. Ticks are 50ms currently.
|
||||
\ 20 ticks per second
|
||||
: wait-tick 50 ms ;
|
||||
|
||||
\ devices/tick calculates the amount of devices that are to be added per tick.
|
||||
: devices/tick ( f: -- r )
|
||||
|
@ -220,10 +212,14 @@ S" you feel like throwing some stuff into the pool." set-message
|
|||
[char] g of buy-detector endof
|
||||
endcase ;
|
||||
|
||||
\ the word garden-input contains the input cases specifically for the garden
|
||||
: garden-input ; \ TODO stub
|
||||
|
||||
\ the word handle-input handles input every time around the game loop.
|
||||
: handle-input
|
||||
key? if key dup case
|
||||
screen @ 0= if devices-input then
|
||||
screen @ 1 = if garden-input then
|
||||
[char] q of exit-game endof
|
||||
[char] D of debug-console endof
|
||||
[char] > of 1 move-screen endof
|
||||
|
@ -239,7 +235,7 @@ S" you feel like throwing some stuff into the pool." set-message
|
|||
: print-rate
|
||||
2 set-precision
|
||||
\ first convert to floating point, divide by 1000 to get seconds from milliseconds, then do 1/n to get the devices/second from seconds/device
|
||||
." (" devices/tick 1000e f* f. ." devices/second)" ;
|
||||
." (" devices/tick 20e f* f. ." devices/second)" ;
|
||||
|
||||
: draw-screen-name ( i -- )
|
||||
case
|
||||
|
@ -251,19 +247,28 @@ S" you feel like throwing some stuff into the pool." set-message
|
|||
: draw-tab-keys
|
||||
." (use < and > to switch tabs) " ;
|
||||
|
||||
|
||||
\ draw-tab-devices draws the device count on the tab bar
|
||||
: draw-tab-devices
|
||||
devices f@ f>s dup ." [" .
|
||||
1 = if ." Device]" else ." Devices] " then ;
|
||||
|
||||
\ draw-tab draws a single tab for a screen
|
||||
: draw-tab ( i -- )
|
||||
dup screen @ = if
|
||||
." >" bl
|
||||
drop then draw-screen-name ;
|
||||
|
||||
\ draw-tab-bar draws the tab bar. TODO make this into smaller words
|
||||
: draw-tab-bar ( x y -- )
|
||||
: draw-tab-bar ( x y -- x y )
|
||||
2dup at-xy
|
||||
clear-line
|
||||
screens @ if \ 0 is false in forth, so if the number of screens is zero, don't draw the bar.
|
||||
screens @ 1+ 0 do
|
||||
i dup
|
||||
screen @ = if
|
||||
." >" bl
|
||||
drop
|
||||
then
|
||||
draw-screen-name
|
||||
i dup draw-tab
|
||||
loop inc-y
|
||||
draw-tab-keys
|
||||
draw-tab-devices
|
||||
then ;
|
||||
|
||||
\ draw-message draws the stored message on the screen.
|
||||
|
@ -313,14 +318,6 @@ S" you feel like throwing some stuff into the pool." set-message
|
|||
." (g)o metal detecting! [400 Devices]"
|
||||
then inc-y ;
|
||||
|
||||
\ draw-map draws the map. TODO don't just ignore coords
|
||||
: draw-map ( x y -- x y )
|
||||
2dup at-xy
|
||||
mapsize mapsize * 0 do
|
||||
i map + c@ emit
|
||||
i 1 + mapsize mod 0= if
|
||||
cr over move-right then
|
||||
loop ;
|
||||
\ draw-actions draws a list of the actions you've unlocked.
|
||||
: draw-actions ( x y -- x y )
|
||||
2dup at-xy
|
||||
|
@ -334,13 +331,13 @@ S" you feel like throwing some stuff into the pool." set-message
|
|||
\ clear-xy clears the x and y positions from the stack
|
||||
: clear-xy ( x y -- ) 2drop ;
|
||||
|
||||
\ draw-screen redraws the devices screen, but only if there's been a change.
|
||||
\ ( x y -- )
|
||||
\ draw-devices-screen redraws the devices screen, but only if there's been a change.
|
||||
\ ( x y -- x y )
|
||||
: draw-devices-screen draw-message draw-devices draw-blank draw-actions ;
|
||||
\ : draw-screen clear-all ;
|
||||
|
||||
\ TODO draw the garden, this is a stub
|
||||
: draw-garden 2dup at-xy draw-map ;
|
||||
: draw-garden ( x y -- x y ) 2dup at-xy ." hi " ;
|
||||
|
||||
\ TODO apparently the forth-y way to do this is with a function table
|
||||
: draw-screen
|
||||
|
|
Reference in New Issue