#!/bin/bash # Author: Mark Cardinal # Date: December 12th 2007 # Program: pacman.sh # # # USAGE: ./pacman.sh [Options] # # Options: -s NUM - where NUM is the delay in seconds before moving pacman # -o NUM - where NUM is a number between 40 - 47 representing the eye colour for Open Mouth pacman # -c NUM - where NUM is a number between 40 - 47 representing the eye colour for closed mouth pacman # -b NUM - where NUM is a number between 40 - 47 representing the body colour for pacman (later make option for open/closed mouth body pacman) # -R NUM - where NUM is a number greater than zero representing the number of rows to make pacman romp on the screen # -C NUM - where NUM is a number greater than zero representing the number of rows to make pacman romp on the screen # -r NUM - where NUM is a number greater than zero representing the number of rotations the program will run for, DEFAULT continuous # -h - prints this usage clear speed=1 # number of seconds between drawing new packman (speed packman appears to move at) eyecolourA=45 # eye colour for Open mouth packman eyecolourB=44 # eye colour for Closed mouth packman bodycolour=43 # body colour of packman numrows=2 # number of rows for pacman to traverse numcols=2 # number of columns for pacman to traverse rotations=0 # number rotations the program runs for, DEFAULTS to 0 for infinite x=1 # x coordinate of the top left corner of the packman to draw/Erase in DrawPackman/Erase respectively y=1 # y coordinate of the top left corner of the packman to draw/Erase in DrawPackman/Erase respectively width=18 # constant; height=9 # constant; mouthdirection=0 # 0 means draw the packman with mouth on the right side| 1 means draw the packman with mouth on the left side mouthstatus=0 # 0 means draw with open mouth && eyecolourA | 1 means draw with closed mouth and eyecolourB function PrintColours(){ for((i=40;i<=47;i++)); do printf "\033[${30};${i}m${i}\033[0m " done } while getopts "hs:o:c:b:R:C:r:" flag do case "$flag" in [s]) if (($OPTARG>0)); then speed=$OPTARG else printf " -s requires an integer argument greater than zero\n" exit 1 fi ;; [o]) if (($OPTARG>=40 && $OPTARG<=47)); then eyecolourA=$OPTARG else printf " -o requires an integer argument from 40 to 47\n" exit 1 fi ;; [c]) if (($OPTARG>=40 && $OPTARG<=47)); then eyecolourB=$OPTARG else printf " -c requires an integer argument from 40 to 47\n" exit 1 fi ;; [b]) if (($OPTARG>=40 && $OPTARG<=47)); then bodycolour=$OPTARG else printf " -b requires an integer argument from 40 to 47\n" exit 1 fi ;; [R]) if (($OPTARG>0)); then numrows=$OPTARG else printf " -R requires an integer argument greater than zero\n" exit 1 fi ;; [C]) if (($OPTARG>0)); then numcols=$OPTARG else printf " -C requires an integer argument greater than zero\n" exit 1 fi ;; [r]) if (($OPTARG>0)); then rotations=$OPTARG else printf " -r requires an integer argument greater than zero\n" exit 1 fi ;; [h]) printf "USAGE: ./pacman.sh [Options]\n\n" printf "Options: \n" printf "%5s -s NUM - where NUM is the delay in seconds before moving pacman\n" "" printf "%5s -o NUM - where NUM is a number between 40 - 47 representing the eye colour for Open Mouth pacman\n" "" printf "%5s -c NUM - where NUM is a number between 40 - 47 representing the eye colour for closed mouth pacman\n" "" printf "%5s -b NUM - where NUM is a number between 40 - 47 representing the body colour for pacman (later make option for open/closed mouth body pacman)\n" "" printf "%5s -R NUM - where NUM is a number greater than zero representing the number of rows to make pacman romp on the screen\n" "" printf "%5s -C NUM - where NUM is a number greater than zero representing the number of rows to make pacman romp on the screen\n" "" printf "%5s -r NUM - where NUM is a number greater than zero representing the number of rotations the program will run for, DEFAULT continuous\n" "" printf "%5s -h %3s - prints this usage\n" "" "" printf "%5s (Colours: " "" PrintColours printf " )\n\n" exit 0 ;; esac done function DrawPackman(){ # copy x,y coordinates; y because it changes in the function and x just to make things look clean funcX=$x funcY=$y printf "\033[${funcY};${funcX}H"; printf "%6s\033[${bodycolour}m%8s\033[0m" " " " "; ((funcY++)) printf "\033[${funcY};${funcX}H"; if [ $mouthstatus -eq 0 ]; then # print with eye colour A printf "%4s\033[${bodycolour}m%5s\033[${eyecolourA}m%2s\033[${bodycolour}m%5s\033[0m" " " " " " "; else # print with eye colour B printf "%4s\033[${bodycolour}m%5s\033[${eyecolourB}m%2s\033[${bodycolour}m%5s\033[0m" " " " " " "; fi ((funcY++)) printf "\033[${funcY};${funcX}H"; printf "%2s\033[${bodycolour}m%16s\033[0m" "" " "; ((funcY++)) printf "\033[${funcY};${funcX}H"; if [ $mouthstatus -eq 0 ]; then # print top half of open mouth if [ $mouthdirection -eq 0 ]; then # print right facing pacman mouth printf "%1s\033[${bodycolour}m%12s\033[0m" "" " "; else # print left facing pacman mouth printf "%6s\033[${bodycolour}m%12s\033[0m" "" " "; fi else # print top half of closed mouth printf "%1s\033[${bodycolour}m%17s\033[0m" "" " "; fi ((funcY++)) printf "\033[${funcY};${funcX}H"; if [ $mouthdirection -eq 0 ]; then # print right facing pacman mouth printf "%1s\033[${bodycolour}m%9s\033[0m" "" " "; else # print left facing pacman mouth printf "%9s\033[${bodycolour}m%9s\033[0m" "" " "; fi ((funcY++)) printf "\033[${funcY};${funcX}H"; if [ $mouthstatus -eq 0 ]; then # print bottom half of open mouth if [ $mouthdirection -eq 0 ]; then # print right facing pacman mouth printf "%1s\033[${bodycolour}m%12s\033[0m" "" " "; else # print left facing pacman mouth printf "%6s\033[${bodycolour}m%12s\033[0m" "" " "; fi else # print bottom half of closed mouth printf "%1s\033[${bodycolour}m%17s\033[0m" "" " "; fi ((funcY++)) printf "\033[${funcY};${funcX}H"; printf "%2s\033[${bodycolour}m%16s\033[0m" "" " "; ((funcY++)) printf "\033[${funcY};${funcX}H"; printf "%4s\033[${bodycolour}m%12s\033[0m" "" " "; ((funcY++)) printf "\033[${funcY};${funcX}H"; printf "%6s\033[${bodycolour}m%8s\033[0m" " " " "; } function Erase(){ for((j=y;j