added message

This commit is contained in:
Nico 2021-03-18 10:54:27 +00:00
parent c5bad6bf85
commit 75c737516b
1 changed files with 30 additions and 8 deletions

38
main.fs
View File

@ -29,18 +29,34 @@ variable devicerate
create membercost 0 , 0 ,
\ the variable "membercount" is how many chat members you've hired. For each chat member, device gain delay decreases.
variable membercount
\ message contains a string message which is printed on the screen.
\ because forth is weird, strings can be stored in variables but it's easier to just store them someplace else and then store that address and the string's length (this is what S" " does)
\ as I'd like changed? etc to work on this, it needs to have three cells, arranged like this:
\ [length change-flag address]
\ TODO this is a terrible idea. Potential better ideas:
\ * have the change flag be the first value, so then the subsequent values can be any length
\ * actually learn better how strings work in this language
create message 0 , 0 , 0 ,
\ set-message sets the message
: set-message ( addr len -- ) message ! message 2 cells + ! message changed ;
\ get-message gets the message
: get-message ( -- addr len ) message @ message 2 cells + @ swap ;
\ any-change? leaves a -1 on the stack if any value has changed, 0 otherwise
: any-change? ( -- flag ) membercost changed? devices changed? ;
: any-change? ( -- flag ) membercost changed? devices changed? message changed? or or ;
\ clear-all clears the change flag on all values.
: clear-all membercost cleared devices cleared ;
: clear-all membercost cleared devices cleared message cleared ;
\ 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 ;
10 membercost !
S" A friendly townie wants to help out." set-message
then ;
\ the word unlock tests to see if any unlock conditions are matched, and unlocks them if they are.
: unlock unlock-members ;
@ -65,11 +81,12 @@ variable membercount
membercost @ dup !0= swap \ checks if member cost is nonzero, leaving member cost on the stack
devices @ <= \ tests if the member cost is less than the amount of devices we have
and if
devices @ membercost @ - devices ! \ remove devices that "pay" for the members
devices @ membercost @ - devices ! \ remove devices that "pay" for the member
devicerate @ 500 - devicerate ! \ increase the device rate by 500
1 membercount +! \ add a member to the count
membercount @ 2 * 5 + membercost +! \ increase the cost of buying a new member
membercost changed
S" " set-message \ blank the message, because we did a thing.
then ;
@ -86,6 +103,11 @@ variable membercount
\ 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
." (" devicerate @ s>f 1000e f/ 1e fswap f/ f. ." devices/second)" ;
\ draw-message draws the stored message on the screen.
: draw-message
1 2 at-xy
clear-line get-message type ;
\ draw-devices draws the number of devices on the screen.
: draw-devices
devices @ dup
@ -97,14 +119,14 @@ variable membercount
\ draw-actions draws a list of the actions you've unlocked.
: draw-actions
1 3 at-xy
1 4 at-xy
membercost @ dup !0= if \ if membercost is non-zero (members have been unlocked)
." (h)ire a chat member [" . ." Devices] (you have " membercount @ . ." chat members helping you)" cr
." (h)ire a chat member [" . ." Devices] (you have " membercount @ . ." chat members helping you)" cr 1 move-right
else drop then
1 move-right ." (q)uit (without saving)" ;
." (q)uit (without saving)" ;
\ draw-screen redraws the screen, but only if there's been a change.
: draw-screen any-change? if draw-devices draw-actions clear-all then ;
: draw-screen any-change? if draw-devices draw-actions draw-message clear-all then ;
\ main game loop
: game-loop begin game-tick handle-input draw-screen 0 until ;