Compare commits

...
This repository has been archived on 2021-04-27. You can view files and clone it, but cannot push or open issues or pull requests.

9 Commits

Author SHA1 Message Date
Nico a0a562b962 Merge branch 'rethink' of tildegit.org:nihilazo/javapool into rethink 2021-04-27 19:06:34 +01:00
Nico 955ad5c8e1 to merge 2021-04-27 19:05:29 +01:00
Nico 9f0724e1bc fix bar issues 2021-04-27 13:55:21 +01:00
Nico d21141cb06 stuff, but it's borked 2021-04-26 13:22:10 +01:00
Nico 07ad405461 refactor tab bar 2021-04-23 12:02:08 +01:00
Nico 75cc5ec09e add device counter to tab bar 2021-04-23 11:42:09 +01:00
Nico 7eee62f5da add garden input stub 2021-04-23 10:42:25 +01:00
Nico 1406808004 strip out existing garden mechanics 2021-04-23 10:41:02 +01:00
Nico d134707466 make ticks far less frequent 2021-04-21 11:31:47 +01:00
2 changed files with 45 additions and 48 deletions

View File

@ -20,24 +20,13 @@ like https://candybox2.github.io/
* can only be bought once
* batteries
* when bought, immediately gives 1 energy
* water generator
* costs N devices and 1 spoon (always one)
* lore: the spoon controls the water flowing through the generator,
which allows it to power a turbine and produce energy
* could implement the notion of a moon phase to make the spoons
stronger and cause higher energy production?
* oxygen bottles
* for extra oxygen while swimming in the pool
* oracle
* costs 3 billion devices
* ends the game with a thank you note from sun microsystems
## the garden
* you can move around the garden with the arrow keys
* you can use the detector in the garden for 1 energy
* you might find a moon rune moonsoon spoon with the detector
* you can find bells and whistles
* You can metal detect on a timer
## the pool

80
main.fs
View File

@ -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
@ -58,6 +58,13 @@ variable screen
\ variable screens contains the highest unlocked screen number.
variable screens
0 screens !
\ variable searchspeed is the speed of going metal detecting (per tick). When it reaches 1000, it's done.
variable searchspeed
10 searchspeed !
\ variable searchprogress is the progress through metal detecting. It has an update flag.
create searchprogress 0 , 0 ,
\ variable searching is true if metal detecting is in progress.
\ 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 in the variable (this is what S" " does and what "type" expects)
create message 0 , 0 , 0 ,
@ -66,15 +73,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
@ -82,9 +80,9 @@ S" you feel like throwing some stuff into the pool." set-message
: f+! ( addr -- ) ( F: r -- ) dup f@ f+ f! ;
\ any-change? leaves a -1 on the stack if any value has changed, 0 otherwise
: any-change? ( -- flag ) membercost 1 changed? devices 2 changed? message 2 changed? or or ;
: any-change? ( -- flag ) membercost 1 changed? devices 2 changed? message 2 changed? searchprogress 1 changed? or or or ;
\ clear-all clears the change flag on all values.
: clear-all membercost 1 cleared devices 2 cleared message 2 cleared ;
: clear-all membercost 1 cleared devices 2 cleared message 2 cleared searchprogress 1 cleared ;
\ the word !0= tests if something is non-zero
: !0= ( n -- flag ) 0= 0= ;
\ the word f!0= tests if a floating thing is non-zero
@ -112,8 +110,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 )
@ -181,6 +180,8 @@ S" you feel like throwing some stuff into the pool." set-message
1 screens +! then
page ;
\ the word metal-detect goes metal detecting!
: metal-detect ; \ TODO stub
\ DEBUGGING STUFF
\ the word debug-console is used for entering debug mode.
@ -220,10 +221,17 @@ 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
case
[char] m of metal-detect endof
endcase ; \ 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 +247,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 +259,27 @@ S" you feel like throwing some stuff into the pool." set-message
: draw-tab-keys
." (use < and > to switch tabs) " ;
\ draw-tab-bar draws the tab bar. TODO make this into smaller words
: draw-tab-bar ( x y -- )
\ 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
." >" else space then draw-screen-name ;
\ draw-tab-bar draws the tab bar.
: 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 draw-tab
loop inc-y
draw-tab-keys
draw-tab-devices
then ;
\ draw-message draws the stored message on the screen.
@ -313,14 +329,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 +342,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 draw-message draw-devices draw-blank draw-actions ;
\ draw-devices-screen redraws the devices screen, but only if there's been a change.
\ ( x y -- x y )
: draw-devices-screen 2dup at-xy 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 draw-blank ." hi " ;
\ TODO apparently the forth-y way to do this is with a function table
: draw-screen
@ -354,7 +362,7 @@ S" you feel like throwing some stuff into the pool." set-message
begin
wait-tick game-tick handle-input
any-change? if
1 1 draw-tab-bar draw-blank draw-screen clear-xy clear-all
1 1 draw-tab-bar draw-message draw-blank draw-screen clear-xy clear-all
then
0 until ;