Use state more, start on menus

This commit is contained in:
Bill Niblock 2024-11-02 17:09:38 -04:00
parent e63a0039b6
commit fd96d53a34
7 changed files with 315 additions and 217 deletions

View file

@ -186,3 +186,91 @@ Remaining tasks:
2. Draw floors
3. Draw sky-boxen
4. Add monster mechanics
---
Thinking about a HUD. On the top can be a compass, and then on the bottom can be
a few additional things.
For the compass, I know the direction of the player. I've implemented the state
function again, and am writing that data to it and reading from it for the
overlay. When the `player.getX` is greater than 0, I'm "facing" north; when less
than 0, facing south. For the `player.getY`, greater than 0 is west; less than
is east. It's easy to just print the value, but it'd be really cool to instead
print one of those compass bars. Theoretically it's printing out the elements of
a list at set screen intervals. The list may look like:
```lisp
(var compass-bar [":" "|" "N" "|" ":" "|" "E" "|" ":" "|" "S" "|" ":" "|" "W" "|"])
```
Then it would print 5 elements, starting at x, going to x + 5, wrapping around.
`x` would be determined based on the two values of `player.getX` and
`player.getY`.
This will ensure we loop properly through the indexes, assuming `x` is always
larger than the array length.
```lisp
(fn fi [x] (set r x) (while (> r 5) (set r (- r 5))) r)
```
Beyond this, it may be good to pair this with logic that allows adding or
subtracting from the index and not escaping the list. This would basically check
if the new index will be either less-than 0 or greater than the list length, and
adjust accordingly.
Could be something like:
```
(if x > 0) // northern half
index is set to north
(adjust index by ratio of y to (-1 .. 1))
(else) // southern half
index is set to south
(adjust index by ratio y to (-1 .. 1))
```
The adjustment algorithm is the same, and it's either added or subtracted from
the index, based on which hemisphere, probably?
This value `(math.floor (+ 10 (* 10 (player.getDirX))))` yields 0-19 in both an
east and west facing arc. If I use east and west as a switch, then when I'm
facing east I can move the compass bar list in one direction, and the other when
facing west.
In order to do this I need a proper circular-list approach.
```lisp
(var compass [<elements>])
(fn circular-compass [c n]
(if (< (+ c n) 1) (length compass)
(> (length compass) (+ c n)) 0
(+ c n))
```
---
Compass bar "works", at least well enough for now. Time to move to some menus. I
think a cool aesthetic would be the start menu being like the inside of the
escape pod you start outside of. The background would be a texture of some kind
of metallic wall, and there could be a flashing light effect. The menu items
would be the configuration for the maze: size, number of survivors, etc.. There
would be a button to start, and then a button to quit. If I have time, there can
be a button to remap keys, and maybe turn sound on and off.
Focusing on the menu buttons themselves, each one has a shape and text.
Additionally, each one should have a hover effect. Each menu can have a
left-action, right-action, and select-action.
```lisp
(var menu-font (love.graphics.newFont 20))
(fn menu-button [x y text la ra sa]
(love.graphics.polygon ...)
(love.graphics.printf text menu-font x (+ y ...) (+ x ...))
(var (left-area right-area mid-area) (values ...))
(when (left-area) (la))
(when (right-area) (ra))
(when (mid-area) (sa))
```
There should also be a way to navigate with the keyboard. Using up and down
arrows or keys will move the "selected" button, left/right arrows/keys will
activate the left/right actions, and enter/use will activate the select action.