99 lines
3.2 KiB
Forth
99 lines
3.2 KiB
Forth
\ JAVAPOOL - THE GAME (an incremental game based on the lore of #javapool on tilde.town)
|
|
\ this code likely sucks, because I'm bad at forth and figuring stuff out as I go.
|
|
|
|
\ ANSI escape sequences. gforth already provides at-xy and page, but I also need a word for clearing the current line and displaying the cursor.
|
|
: hide-cursor esc[ ." ?25l" ;
|
|
: show-cursor esc[ ." ?25h" ;
|
|
: clear-line esc[ ." K" ;
|
|
: move-right ( x -- ) esc[ 0 .R ." C" ;
|
|
|
|
\ initialise some variables that encode game state.
|
|
\ the variable "counter" holds the count of the current tick. It always starts at 0.
|
|
variable counter
|
|
\ the variable "devices" holds the amount of devices currently in the pool.
|
|
variable devices
|
|
\ the variable "devicerate" is the amount of ticks between devices getting added.
|
|
variable devicerate
|
|
2000 devicerate !
|
|
\ the variable "membercost" is the cost of hiring a new chat member. If it is zero, hiring chat members hasn't been unlocked yet.
|
|
variable membercost
|
|
\ the variable "membercount" is how many chat members you've hired. For each chat member, device gain delay decreases.
|
|
variable membercount
|
|
|
|
\ the word !0= tests if something is non-zero
|
|
: !0= 0= 0= ;
|
|
|
|
\ the world unlock-members tests to see if hiring chat members can be unlocked. if so, they are unlocked.
|
|
: unlock-members
|
|
devices @ 5 = membercost @ 0= and if
|
|
10 membercost ! then ;
|
|
|
|
\ the word unlock tests to see if any unlock conditions are matched, and unlocks them if they are.
|
|
: unlock unlock-members ;
|
|
|
|
\ the word tick waits a tick. Ticks are 1ms currently.
|
|
: tick 1 ms ;
|
|
|
|
\ the word tick-up ticks the counter up
|
|
: tick-up tick 1 counter +! ;
|
|
|
|
\ the word game-tick runs a single tick of the game
|
|
: game-tick tick-up unlock counter @
|
|
devicerate @ mod 0= if 1 devices +! then ;
|
|
|
|
\ TODO saving
|
|
\ the word exit-game exits the game.
|
|
: exit-game page show-cursor bye ;
|
|
|
|
|
|
\ the word hire-chat-member hires a chat member.
|
|
: hire-chat-member
|
|
membercost @ dup !0= swap
|
|
devices @ <=
|
|
and if
|
|
devices @ membercost @ - devices !
|
|
devicerate @ 500 - devicerate !
|
|
1 membercount +!
|
|
membercount @ 2 * 5 + membercost +!
|
|
then ;
|
|
|
|
|
|
\ the word handle-input handles input every time around the game loop.
|
|
: handle-input
|
|
key? if key case
|
|
[char] q of exit-game endof
|
|
[char] h of hire-chat-member endof
|
|
endcase then ;
|
|
|
|
\ print-rate prints the current device output rate on the screen.
|
|
\ TODO make this be devices/s
|
|
: print-rate
|
|
2 set-precision
|
|
." (" devicerate @ s>f 1000e f/ 1e fswap f/ f. ." devices/second)" ;
|
|
|
|
\ draw-devices draws the number of devices on the screen.
|
|
: draw-devices
|
|
devices @ dup
|
|
1 1 at-xy
|
|
clear-line
|
|
1 = if ." There is 1 device in the javapool." drop else
|
|
." There are " . ." devices in the javapool." then
|
|
space print-rate ;
|
|
|
|
\ draw-actions draws a list of the actions you've unlocked.
|
|
: draw-actions
|
|
1 3 at-xy
|
|
membercost @ dup !0= if
|
|
." (h)ire a chat member [" . ." Devices] (you have " membercount @ . ." chat members helping you)" cr
|
|
else drop then
|
|
1 move-right ." (q)uit" ;
|
|
|
|
\ TODO this is a stub
|
|
: draw-screen draw-devices draw-actions ;
|
|
|
|
\ main game loop
|
|
: game-loop begin game-tick handle-input draw-screen 0 until ;
|
|
|
|
\ clear the screen and start the game
|
|
page hide-cursor game-loop
|