marshroom/game.sh
2025-02-09 15:44:54 +00:00

187 lines
4.4 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
playintro=0
# $1 message
echowait () {
echo $1
read -s -n 1
}
intro () {
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 ""
}
[ $playintro -eq 1 ] && intro
maxbattery=10
depletebattery () {
battery=$((battery-1))
}
# position id
# start roughly in the middle
# vertical movement +/- battery
# 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
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
}
# 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 () {
# 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))
# 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
run=0
while [ 1 ]
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
# 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")
echowait "you look around and see many interesting things!"
depletebattery
;;
"move")
move $(gum choose "north" "east" "south" "west")
esac
done
echowait "my battery is low and it's getting dark ;-;"
done