add constructs, refactor
This commit is contained in:
parent
ec9a89e42d
commit
4ec3c66df6
56
main.fs
56
main.fs
|
@ -30,13 +30,20 @@ create devices 0e f, -1 ,
|
|||
\ old devices is the old device count. For convenience.
|
||||
: old-devices devices float + ;
|
||||
|
||||
\ d/s converts a devices per second value into devices per tick.
|
||||
: d/s 1000e f/ ;
|
||||
|
||||
\ the variable "base-devices/tick" is the base amount of devices added per tick.
|
||||
variable base-devices/tick
|
||||
0.0005e base-devices/tick f!
|
||||
0.5e d/s base-devices/tick f!
|
||||
\ the variable "membercost" is the cost of hiring a new chat member. If it is zero, hiring chat members hasn't been unlocked yet. It has a change flag and is fixed-point.
|
||||
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
|
||||
\ the variable "constructcost" is how expensive a construct is. Follows the same rules as membercost.
|
||||
create constructcost 0 , 0
|
||||
\ the variable "constructcount" follows the same rules as membercount, but for constructs.
|
||||
variable constructcount
|
||||
\ count-messages-shown contains the amount of device count milestone messages that have been shown.
|
||||
variable count-messages-shown
|
||||
\ message contains a string message which is printed on the screen.
|
||||
|
@ -68,8 +75,13 @@ S" you feel like throwing some stuff into the pool." set-message
|
|||
10 membercost !
|
||||
S" A friendly townie wants to help out." set-message then ;
|
||||
|
||||
: unlock-constructs
|
||||
devices f@ ftrunc 30e f= constructcost @ 0= and if
|
||||
40 constructcost !
|
||||
S" You figure out that you can probably hack these devices." set-message then ;
|
||||
|
||||
\ the word unlock tests to see if any unlock conditions are matched, and unlocks them if they are.
|
||||
: unlock unlock-members ;
|
||||
: unlock unlock-members unlock-constructs ;
|
||||
|
||||
\ the word wait-tick waits a tick. Ticks are 1ms currently.
|
||||
: wait-tick 1 ms ;
|
||||
|
@ -84,8 +96,9 @@ S" you feel like throwing some stuff into the pool." set-message
|
|||
\ devices/tick calculates the amount of devices that are to be added per tick.
|
||||
: devices/tick ( f: -- r )
|
||||
base-devices/tick f@
|
||||
membercount @ s>f 2000e f/ \ each member adds 0.5 d/s
|
||||
f+ ;
|
||||
membercount @ s>f 0.5e d/s f* \ each member adds 0.5 d/s
|
||||
constructcount @ s>f 2e d/s f* \ each construct adds 2 d/s
|
||||
f+ f+ ;
|
||||
|
||||
\ set-count-message sets the message to certain things based on the amount of devices in the pool. The count-messages-shown variable is used to track how many of these have already been shown.
|
||||
: set-count-message
|
||||
|
@ -112,25 +125,43 @@ S" you feel like throwing some stuff into the pool." set-message
|
|||
\ the word exit-game exits the game.
|
||||
: exit-game page show-cursor bye ;
|
||||
|
||||
\ the word can-afford? tests if you could afford n devices.
|
||||
: can-afford? ( n -- flag ) s>f devices f@ f<= ;
|
||||
|
||||
\ the word pay pays an amount of devices
|
||||
: pay ( n -- ) s>f devices f@ fswap f- devices f! ;
|
||||
|
||||
\ the word hire-chat-member hires a chat member.
|
||||
: hire-chat-member
|
||||
membercost @ dup !0= swap \ checks if member cost is nonzero, leaving member cost on the stack
|
||||
s>f devices f@ f<= \ tests if the member cost (converted to a float) is less than the amount of devices we have
|
||||
can-afford? \ tests if the member cost (converted to a float) is less than the amount of devices we have
|
||||
and if
|
||||
." hit!"
|
||||
devices f@ membercost @ s>f f- devices f! \ remove devices that pay for the member
|
||||
membercost @ pay
|
||||
1 membercount +! \ add a member to the count
|
||||
membercount @ 2 * 5 + membercost +! \ increase the cost of buying a new member
|
||||
membercost 1 changed
|
||||
S" " set-message \ blank the message, because we did a thing.
|
||||
then ;
|
||||
|
||||
\ the word build-construct builds a construct.
|
||||
: build-construct
|
||||
constructcost @ dup !0= swap \ checks if member cost is nonzero, leaving member cost on the stack
|
||||
can-afford? \ tests if the member cost (converted to a float) is less than the amount of devices we have
|
||||
and if
|
||||
constructcost @ pay \ remove devices that pay for the construct
|
||||
1 constructcount +! \ add a construct to the count
|
||||
constructcount @ 4 * 10 + constructcost +! \ increase the cost of buying a new construct
|
||||
constructcount 1 changed
|
||||
S" " set-message \ blank the message, because we did a thing.
|
||||
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
|
||||
[char] b of build-construct endof
|
||||
[char] D of debug-console endof
|
||||
endcase then ;
|
||||
|
||||
|
@ -154,6 +185,14 @@ S" you feel like throwing some stuff into the pool." set-message
|
|||
." There are " . ." devices in the javapool." then
|
||||
space print-rate ;
|
||||
|
||||
\ draw-constructs draws the option for building a construct
|
||||
: draw-constructs
|
||||
clear-line
|
||||
constructcost @ dup !0= if
|
||||
." (b)uild a device-throwing construct [" . ." Devices]"
|
||||
space ." (" constructcount @ 0 .R ." )"
|
||||
else drop then ;
|
||||
|
||||
\ draw-members draws the option for hiring a chat member
|
||||
: draw-members
|
||||
clear-line
|
||||
|
@ -161,11 +200,12 @@ S" you feel like throwing some stuff into the pool." set-message
|
|||
." (h)ire a chat member [" . ." Devices]"
|
||||
space ." (" membercount @ 0 .R ." )"
|
||||
else drop then ;
|
||||
|
||||
|
||||
\ draw-actions draws a list of the actions you've unlocked.
|
||||
: draw-actions
|
||||
1 4 at-xy
|
||||
draw-members cr 1 move-right
|
||||
draw-constructs cr 1 move-right
|
||||
." (q)uit (without saving)" ;
|
||||
|
||||
\ draw-screen redraws the screen, but only if there's been a change.
|
||||
|
|
Reference in New Issue