marshroom/game.sh
Cat Flynn e5d6d00834 feat: find mushrooms
also some debug options
2025-02-10 01:48:35 +00:00

222 lines
5.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# find mushroom
# break wheel
# examine rock
# deplete power
# reset to beginning
# print status: battery
# print status: wheels
# generate a map of where we have been
# debug options
enablestory=0
enablebattery=1
enablehazards=1
# $1 message
echowait () {
echo $1
read -s -n 1
}
intro () {
[ $enablestory -eq 1 ] || return
echowait "CRASH!!!"
echowait "ah!!"
echowait "..."
echowait "...uh oh. hmm. uh. huh. hmmmm."
echowait "i appear to have fallen through the surface..."
echowait "...into some kind of tunnel?"
echo ""
}
meetsplork () {
[ $enablestory -eq 1 ] || return
echowait "...waht?"
echowait "i was down in the tunnel and my batteries died..."
echowait "how did i get back?"
echo
# we need to make this visually distinct so it's not confusing...
echowait "i can help with that!"
echo
echowait "AHHHHHHH"
echo
echowait "whoa there! its ok!"
echowait "i saw ya down there in the depths and figured"
echowait "you's prolly what made this here light-hole."
echowait "figured you came from up there so maybe you's a light-thing!"
echo
echowait "you're a... you're a..."
echo
echowait "brave n mighty rescuer, yup. that's me. name's splork, nice to meet ya!"
echo
echowait "..."
}
maxbattery=10
depletebattery () {
[ $enablebattery -eq 1 ] || return
battery=$((battery-1))
}
# position id
# start roughly in the middle
# vertical movement +/- battery*2
# horizontal movement +/- 1
# this setup allows for different "cells" of different values which can be hashed for fun and profit
# without actually needing to do any 2d math or *shudder* collision detection
# making the number of columns equal to double the battery means that we can never reach the edge of the map
# battery is doubled to allow us to move at most battery units in any direction
posid=200 # (2*maxbattery)^2/2
# $1 direction
# north, east, south or west
move () {
echo "you move $1"
depletebattery
case $1 in
"north")
posid=$((posid-maxbattery*2))
;;
"east")
posid=$((posid+1))
;;
"south")
posid=$((posid+maxbattery*2))
;;
"west")
posid=$((posid-1))
;;
esac
checkhazard
}
# 80 random cells out of ~400 (calculated from maxbattery^2)
hazards=($(shuf -i 0-400 -n 120))
#echo "${hazards[@]}"
# split the hazard cells proportionally into sand traps and hard rocks
checkhazard () {
[ $enablehazards -eq 1 ] && return
# are we in a hazard cell?
for hazard in "${hazards[@]}"; do
[ $posid -ne $hazard ] && continue
echowait "you got stuck in sand!"
echowait "expended extra energy to escape"
depletebattery
# hard rocks break wheels
done
}
# is there something to find upon examination?
mushrooms=($(shuf -i 0-400 -n 200))
foundmushrooms=() # list of positions we found mushrooms at during a run
# inentory should be persistent between runs
inventory=0
# lightning mushrooms
# round mushrooms
checkmushroom () {
for floormushroom in "${mushrooms[@]}"
do
[ $posid -ne $floormushroom ] && continue
# don't find the same mushroom twice
for foundmushroom in "${foundmushrooms[@]}"
do
[ $posid -eq $foundmushroom ] && return 0
done
return 1
done
return 0
}
examine () {
depletebattery
checkmushroom
local result=$?
if [ $result -eq 1 ]
then
echowait "there's something growing here! found a mushroom, yay!!!"
# TODO: make it so we can't pick up the same mushroom twice
inventory=$((inventory+1))
foundmushrooms+=($posid)
else
echowait "didn't find anything :("
fi
}
endrun () {
echowait "my battery is low and it's getting dark ;-;"
# reset run-specific memory
foundmushrooms=()
}
run=0
while [ 1 ]
do
run=$((run+1))
echo "day $run"
echo "...awake and fully charged!"
[ $run -eq 2 ] && meetsplork
# we have access to the shop after the first run.
if [ $run -gt 1 ]
then
echowait "well heya there my rovy pal! what can i do ya for?"
gum confirm "sell 3 mushrooms for +1 battery?"
if [[ $? -eq 0 ]] # compare last exit code
then
if [ $inventory -lt 3 ]
then
echowait "oooo, sorry, you need 3 mushrooms for that!"
else
inventory=$((inventory-3))
maxbattery=$((maxbattery+1))
fi
fi
fi
battery=$maxbattery
while [ $battery -gt 0 ]
do
# print debug status
#echo "pos: $posid battery: $battery"
# print status
echo "battery: $battery mushrooms: $inventory"
case $(gum choose "move" "examine" "exit") in
"exit")
gum confirm && exit 1
;;
"examine")
examine
;;
"move")
move $(gum choose "north" "east" "south" "west")
esac
done
endrun
done