feat: find mushrooms

also some debug options
This commit is contained in:
Cat Flynn 2025-02-10 01:43:29 +00:00
parent a8116f42ea
commit e5d6d00834

123
game.sh
View File

@ -9,7 +9,10 @@
# print status: wheels
# generate a map of where we have been
playintro=0
# debug options
enablestory=0
enablebattery=1
enablehazards=1
# $1 message
echowait () {
@ -18,6 +21,8 @@ echowait () {
}
intro () {
[ $enablestory -eq 1 ] || return
echowait "CRASH!!!"
echowait "ah!!"
echowait "..."
@ -27,21 +32,45 @@ intro () {
echo ""
}
[ $playintro -eq 1 ] && intro
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
# 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
@ -68,14 +97,14 @@ move () {
checkhazard
}
# TODO: generate a map
# TODO: put hazards on the map
# 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
@ -90,23 +119,54 @@ checkhazard () {
# 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
examine () {
# are we in a hazard cell?
for mushroom in "${hazards[@]}"; do
[ $posid -ne $mushroom ] && continue
echowait "there's something growing here! found a mushroom, yay!!!"
inventory=$((inventory+1))
done
}
# 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 ]
@ -114,30 +174,7 @@ do
run=$((run+1))
echo "day $run"
echo "...awake and fully charged!"
if [ $run -eq 2 ]
then
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 "..."
fi
[ $run -eq 2 ] && meetsplork
# we have access to the shop after the first run.
if [ $run -gt 1 ]
@ -173,14 +210,12 @@ do
;;
"examine")
echowait "you look around and see many interesting things!"
depletebattery
examine
;;
"move")
move $(gum choose "north" "east" "south" "west")
esac
done
echowait "my battery is low and it's getting dark ;-;"
endrun
done