billr@saab.CNA.TEK.COM (Bill Randle) (08/11/90)
Submitted-by: Kevin Wright <kevin@altair.csustan.edu>
Posting-number: Volume 11, Issue 22
Archive-name: sunbots/Part01
[I ran this on my 3/60 (OS 3.5) with no problems. -br]
[[This is a version of robots for sunview. It has a lot of the
flavor of Daleks for the Mac.]]
#! /bin/sh
# This is a shell archive. Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file". To overwrite existing
# files, type "sh file -c". You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g.. If this archive is complete, you
# will see the following message at the end:
# "End of archive 1 (of 3)."
# Contents: README MANIFEST level.c pics pics/human_d8.pic proc.c
# sunbots.c sunbots.h
# Wrapped by billr@saab on Fri Aug 10 10:47:55 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'README' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'README'\"
else
echo shar: Extracting \"'README'\" \(1401 characters\)
sed "s/^X//" >'README' <<'END_OF_FILE'
XSunbots:
X
XSunbots is a sunview version of Robots. It also has additions that
Xmake it resemble Daleks for the Mac.
X
XThe program should compile up easily enough. Just type make and it
Xshould do the rest. You can edit the Makefile to tell it a few things
Xlike where to install the game, etc.
X
XI don't know of any bugs in the program, of course there always could
Xbe some. There are a few things that could be done:
X
X 1) The filer option for saving and loading is not implemented.
X It probably wouldn't be hard at all to add this.
X 2) The gems that appear on later levels should probably be
X renamed and redrawn to be Jelly Babies to fit the Dr. Who
X look of things more.
X 3) My method of attempting to assure mutually exclusive access
X to the high score file during updates is a bit crude and could
X be fixed.
X
XPeople around our site seem to be content with the game as it is. It is
Xa mild diversion for when you are tired of doing work.
X
XAnyone can do anything they want with this code. If anyone makes improvements
Xor modifications to the program, it would be nice if you could send me a
Xcopy of your changes so that I can take a look.
X
XHave Fun!
X
X Kevin Wright
X
XE-mail : kevin@altair.csustan.edu or kevin@csustan.csustan.edu
XUS-mail: California State University, Stanislaus
X Computer Science Department
X 801 West Monte Vista Avenue
X Turlock, CA 95380
XPhone : (209) 667-3273
END_OF_FILE
if test 1401 -ne `wc -c <'README'`; then
echo shar: \"'README'\" unpacked with wrong size!
fi
# end of 'README'
fi
if test -f 'MANIFEST' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'MANIFEST'\"
else
echo shar: Extracting \"'MANIFEST'\" \(1212 characters\)
sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
X File Name Archive # Description
X-----------------------------------------------------------
X MANIFEST 1
X Makefile 2
X README 1
X images.c 2
X images.h 2
X level.c 1
X move.c 2
X pics 1
X pics/debug.pic 2
X pics/filer.pic 2
X pics/gem.pic 3
X pics/human2.pic 2
X pics/human_d1.pic 2
X pics/human_d8.pic 1
X pics/icon.pic 2
X pics/live.pic 2
X pics/quit.pic 2
X pics/reset.pic 2
X pics/robot.pic 3
X pics/robot2.pic 2
X pics/scores.pic 2
X pics/sonic.pic 2
X pics/stand.pic 2
X pics/tardis.pic 2
X pics/teleport1.pic 2
X pics/teleport2.pic 2
X pics/tomb.pic 2
X pics/trash.pic 3
X pics/zap1.pic 3
X pics/zap2.pic 3
X pics/zap3.pic 3
X pics/zap4.pic 2
X proc.c 1
X sunbots.c 1
X sunbots.h 1
X sunbots.man 2
END_OF_FILE
if test 1212 -ne `wc -c <'MANIFEST'`; then
echo shar: \"'MANIFEST'\" unpacked with wrong size!
fi
# end of 'MANIFEST'
fi
if test -f 'level.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'level.c'\"
else
echo shar: Extracting \"'level.c'\" \(9776 characters\)
sed "s/^X//" >'level.c' <<'END_OF_FILE'
X/*****************************************************************
X *
X * level.c - Level creation and manipulation routines
X *
X * Created -- 1/5/90 Kevin Wright
X *
X *****************************************************************/
X
X#include "sunbots.h" /* Robots header file */
X
X/*****************************************************************
X * make_level() - Create a new level. Delete all
X * existing robots and create a new
X * set of them. Reset screwdriver
X * and place all objects.
X *****************************************************************/
X
Xmake_level()
X{
X ScreenItem temp; /* Temp pointer to robot list */
X
X /* Destroy old and create new robots */
X destroy_robots();
X create_robots();
X
X /* Create gems if level is right */
X if(current_level >= 10)
X create_gems();
X
X /* Reset screwdriver */
X screwdriver_uses = 1;
X
X /* Reset last stand */
X last_stand_set = FALSE;
X
X /* Display level message */
X switch(current_level) {
X case 1:
X display_msg("Welcome to Sunbots!", 2);
X break;
X case 5:
X display_msg("Double Speed Robots", 2);
X break;
X case 10:
X display_msg("Grab Gems For Extra Points!", 2);
X break;
X default:
X break;
X }
X
X /* Place human */
X human->oldrow = human->oldcol = -1;
X find_empty(human, &(human->row), (&human->col));
X place_item(human, -1, -1);
X
X /* Place robots and gems */
X for(temp = robot_list; temp; temp = temp->next) {
X temp->oldrow = temp->oldcol = -1;
X find_empty(temp, &(temp->row), &(temp->col));
X place_item(temp, 0, 0);
X }
X}
X
X
X/*****************************************************************
X * remove_robots() - Remove robots in the
X * specified rectangle.
X *****************************************************************/
X
Xremove_robots(x0, y0, x1, y1, mode, score)
Xint x0, y0, x1, y1, mode, score;
X{
X ScreenItem temp; /* Temp pointer to robot list */
X
X temp = robot_list;
X while(temp) {
X if(temp->row >= y0 && temp->row <= y1 &&
X temp->col >= x0 && temp->col <= x1)
X if(mode == ALL_STATES ||
X (mode == LIVE_STATE && !temp->dead) ||
X (mode == DEAD_STATE && temp->dead)) {
X if(score && !temp->dead)
X if(temp->type == SPEEDER_ROBOT)
X update_score(10);
X else
X update_score(5);
X remove_item(temp);
X }
X
X temp = temp->next;
X }
X}
X
X
X/*****************************************************************
X * destroy_robots() - Destroy all robots in the
X * list.
X *****************************************************************/
X
Xdestroy_robots()
X{
X ScreenItem temp; /* Temp pointer to robot list */
X
X /* Traverse list and destroy each item */
X while(robot_list) {
X temp = robot_list;
X robot_list = robot_list->next;
X destroy_item(temp);
X }
X
X /* Clear the playfield */
X pw_rop(playfield_pw, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT,
X PIX_CLR, NULL, 0, 0);
X}
X
X
X/*****************************************************************
X * remove_item() - Remove an item from the robot_list.
X *****************************************************************/
X
Xremove_item(item)
XScreenItem item;
X{
X ScreenItem temp; /* Temp pointer to robot list */
X
X /* If item is first, then redirect main pointer */
X if(robot_list == item) {
X robot_list = robot_list->next;
X destroy_item(item);
X }
X
X /* Traverse list and find item to remove */
X temp = robot_list;
X while(temp) {
X if(temp->next == item) {
X temp->next = temp->next->next;
X destroy_item(item);
X }
X temp = temp->next;
X }
X}
X
X
X/*****************************************************************
X * destroy_item() - Destroy a panel and free
X * an item structure.
X *****************************************************************/
X
Xdestroy_item(item)
XScreenItem item;
X{
X /* Free memory */
X free(item);
X}
X
X
X/*****************************************************************
X * create_robots() - Create a list of robots. The number
X * is based on the current level.
X *****************************************************************/
X
Xcreate_robots()
X{
X int i; /* Loop variable */
X int robot_num; /* Number of robots on this level */
X Image image_type; /* Type of robot image */
X ScreenItem temp; /* Temp pointer to robots */
X
X robot_num = (current_level < 12 ? 10 * current_level : 120);
X
X /* Create item structures and panels for robots */
X for(i = 0; i < robot_num; i++) {
X temp = (ScreenItem) malloc(sizeof(struct screen_item));
X
X if(current_level>=SPEEDER_LEVEL && RND(100)<SPEEDER_CHANCE) {
X temp->type = SPEEDER_ROBOT;
X image_type = robot2_image;
X } else {
X temp->type = NORMAL_ROBOT;
X image_type = robot_image;
X }
X
X temp->image = image_type;
X temp->dead = FALSE;
X temp->next = robot_list;
X robot_list = temp;
X }
X}
X
X
X/*****************************************************************
X * create_gems()
X *****************************************************************/
X
Xcreate_gems()
X{
X int i; /* Loop variable */
X int gem_num; /* Number of gems on this level */
X ScreenItem temp; /* Temp pointer to gems */
X
X gem_num = (current_level < 15 ? 4 * (current_level - 9) : 20);
X
X /* Create item structures and panels for gems */
X for(i = 0; i < gem_num; i++) {
X temp = (ScreenItem) malloc(sizeof(struct screen_item));
X temp->type = GEM;
X temp->image = gem_image;
X temp->dead = TRUE;
X temp->next = robot_list;
X robot_list = temp;
X }
X}
X
X
X/*****************************************************************
X * find_empty() - Find a random empty location on the
X * screen.
X *****************************************************************/
X
Xfind_empty(item, row, col)
XScreenItem item;
Xint *row, *col;
X{
X ScreenItem temp; /* Temp pointer to robot list */
X int found = TRUE; /* Flag indicating collision found */
X
X /* Find that spot */
X while(found) {
X *row = (rand() >> 3) % 40;
X *col = (rand() >> 3) % 40;
X found = (
Xoccupied(item, *row, *col) != NULL);
X }
X}
X
X
X/*****************************************************************
X * occupied() - Check for occupation of square.
X *****************************************************************/
X
XScreenItem occupied(item, row, col)
XScreenItem item;
Xint row, col;
X{
X ScreenItem temp;
X
X if(item != human && human->row == row && human->col == col)
X return(human);
X
X temp = robot_list;
X while(temp) {
X if(item != temp && temp->row == row && temp->col == col)
X return(temp);
X temp = temp->next;
X }
X
X return(NULL);
X}
X
X/*****************************************************************
X * place_item() - Set the row/col values for an item
X * and redisplay.
X *****************************************************************/
X
Xplace_item(item, xoffset, yoffset)
XScreenItem item;
Xint xoffset, yoffset;
X{
X int row, col, oldrow, oldcol;
X
X /* Calculate pixel offsets */
X oldrow = ROW_HEIGHT * (item->oldrow + yoffset);
X oldcol = COL_WIDTH * (item->oldcol + xoffset);
X row = ROW_HEIGHT * (item->row + yoffset);
X col = COL_WIDTH * (item->col + xoffset);
X
X /* Clear old picture and place new picture */
X pw_rop(playfield_pw, oldcol, oldrow, item->image->width,
X item->image->height, PIX_CLR, NULL, 0, 0);
X pw_rop(playfield_pw, col, row, item->image->width,
X item->image->height, PIX_SRC, item->image->picture, 0, 0);
X}
X
X
X/*****************************************************************
X * set_image() - Change the image of the specified
X * item.
X *****************************************************************/
X
Xset_image(item, newimage, xoffset, yoffset)
XScreenItem item;
XImage newimage;
Xint xoffset, yoffset;
X{
X int row, col;
X
X /* Calculate pixel offsets */
X row = ROW_HEIGHT * (item->row + yoffset);
X col = COL_WIDTH * (item->col + xoffset);
X
X /* Clear old picture and place new picture */
X pw_rop(playfield_pw, col, row, item->image->width,
X item->image->height, PIX_CLR, NULL, 0, 0);
X pw_rop(playfield_pw, col, row, item->image->width,
X item->image->height, PIX_SRC, newimage->picture, 0, 0);
X
X item->image = newimage;
X}
X
X
X/*****************************************************************
X * refresh_image() - Redraw the picture for an item.
X *****************************************************************/
X
Xrefresh_image(item, xoffset, yoffset)
XScreenItem item;
Xint xoffset, yoffset;
X{
X int row, col;
X
X /* Calculate pixel offsets */
X row = ROW_HEIGHT * (item->row + yoffset);
X col = COL_WIDTH * (item->col + xoffset);
X
X pw_rop(playfield_pw, col, row, item->image->width,
X item->image->height, PIX_SRC, item->image->picture, 0, 0);
X}
X
X
X/*****************************************************************
X * update_score() - Update the score by the given
X * amount and redisplay it.
X *****************************************************************/
X
Xupdate_score(amount)
Xint amount;
X{
X char temp_string[80]; /* Temporary storage string */
X
X /* Add amount and create new string */
X current_score += amount;
X sprintf(temp_string, "Level %6d Score %6d",
X current_level, current_score);
X
X /* Display new string */
X panel_set(score, PANEL_LABEL_STRING, temp_string, 0);
X}
X
X
X/*****************************************************************
X * update_level() - Update the level by the given
X * amount and redisplay it.
X *****************************************************************/
X
Xupdate_level(amount)
Xint amount;
X{
X char temp_string[80]; /* Temporary storage string */
X
X /* Add amount and create new string */
X current_level += amount;
X sprintf(temp_string, "Level %6d Score %6d",
X current_level, current_score);
X
X /* Display new string */
X panel_set(score, PANEL_LABEL_STRING, temp_string, 0);
X}
X
X
X/*****************************************************************
X * do_death() - Display a tomb stone where the
X * player used to be.
X *****************************************************************/
X
Xdo_death()
X{
X /* Change human picture to tombstone */
X set_image(human, tomb_image, -1, -1);
X
X make_hs();
X if(!window_get(hs_popup_frame, WIN_SHOW))
X do_pop_proc();
X}
X
X
END_OF_FILE
if test 9776 -ne `wc -c <'level.c'`; then
echo shar: \"'level.c'\" unpacked with wrong size!
fi
# end of 'level.c'
fi
if test ! -d 'pics' ; then
echo shar: Creating directory \"'pics'\"
mkdir 'pics'
fi
if test -f 'pics/human_d8.pic' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'pics/human_d8.pic'\"
else
echo shar: Extracting \"'pics/human_d8.pic'\" \(8429 characters\)
sed "s/^X//" >'pics/human_d8.pic' <<'END_OF_FILE'
X/* Format_version=1, Width=48, Height=48, Depth=8, Valid_bits_per_item=16
X */
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0002,0x0200,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0202,0x0202,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0002,0x0202,0x0202,0x0200,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0002,0x0202,0x0202,0x0200,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0002,0x0200,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0002,0x0202,0x0202,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0002,0x0200,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0202,0x0202,0x0200,0x0000,0x0000,
X 0x0000,0x0000,0x0002,0x0202,0x0202,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0002,0x0200,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0202,0x0202,0x0200,0x0000,0x0000,
X 0x0000,0x0000,0x0002,0x0202,0x0200,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0002,0x0200,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0002,0x0202,0x0200,0x0000,0x0000,
X 0x0000,0x0000,0x0002,0x0202,0x0202,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0002,0x0200,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0202,0x0202,0x0200,0x0000,0x0000,
X 0x0000,0x0000,0x0002,0x0200,0x0202,0x0200,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0002,0x0200,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0002,0x0202,0x0002,0x0200,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0002,0x0202,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0002,0x0200,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0202,0x0200,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0202,0x0200,0x0000,
X 0x0000,0x0000,0x0000,0x0002,0x0200,0x0000,0x0000,0x0000,
X 0x0000,0x0002,0x0202,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0002,0x0202,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0202,0x0200,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0202,0x0200,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0002,0x0202,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0002,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0200,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0002,0x0200,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0202,0x0202,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0002,0x0200,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0002,0x0200,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0002,0x0202,0x0202,0x0200,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0202,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0202,0x0202,0x0202,0x0202,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0202,0x0000,
X 0x0002,0x0202,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0002,0x0200,0x0202,0x0202,0x0002,0x0200,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0202,0x0200,
X 0x0202,0x0202,0x0202,0x0202,0x0202,0x0202,0x0000,0x0000,
X 0x0000,0x0002,0x0000,0x0202,0x0202,0x0000,0x0200,0x0000,
X 0x0000,0x0000,0x0202,0x0202,0x0202,0x0202,0x0202,0x0202,
X 0x0202,0x0202,0x0202,0x0202,0x0202,0x0202,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0202,0x0202,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0202,0x0202,0x0202,0x0202,0x0202,0x0202,
X 0x0002,0x0202,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0202,0x0202,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0202,0x0200,
X 0x0000,0x0202,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0202,0x0202,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0202,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0200,0x0002,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0200,0x0002,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0200,0x0002,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0202,0x0200,0x0002,0x0202,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0202,0x0200,0x0002,0x0202,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0002,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0200,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0202,0x0200,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0002,0x0202,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0002,0x0202,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0202,0x0200,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0202,0x0200,0x0000,
X 0x0000,0x0000,0x0000,0x0002,0x0200,0x0000,0x0000,0x0000,
X 0x0000,0x0002,0x0202,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0002,0x0202,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0002,0x0200,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0202,0x0200,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0002,0x0200,0x0202,0x0200,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0002,0x0200,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0002,0x0202,0x0002,0x0200,0x0000,0x0000,
X 0x0000,0x0000,0x0002,0x0202,0x0202,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0002,0x0200,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0202,0x0202,0x0200,0x0000,0x0000,
X 0x0000,0x0000,0x0002,0x0202,0x0200,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0002,0x0200,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0002,0x0202,0x0200,0x0000,0x0000,
X 0x0000,0x0000,0x0002,0x0202,0x0202,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0002,0x0200,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0202,0x0202,0x0200,0x0000,0x0000,
X 0x0000,0x0000,0x0002,0x0202,0x0202,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0002,0x0200,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0202,0x0202,0x0200,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0002,0x0200,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0002,0x0202,0x0202,0x0200,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0002,0x0202,0x0202,0x0200,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0202,0x0202,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0002,0x0200,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
END_OF_FILE
if test 8429 -ne `wc -c <'pics/human_d8.pic'`; then
echo shar: \"'pics/human_d8.pic'\" unpacked with wrong size!
fi
# end of 'pics/human_d8.pic'
fi
if test -f 'proc.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'proc.c'\"
else
echo shar: Extracting \"'proc.c'\" \(7724 characters\)
sed "s/^X//" >'proc.c' <<'END_OF_FILE'
X/*****************************************************************
X *
X * proc.c - Icon activated processes.
X *
X * Created -- 1/5/90 Kevin Wright
X *
X *****************************************************************/
X
X#include "sunbots.h" /* Robots header file */
X
X/*****************************************************************
X * new_proc() - This procedure is called at the
X * start and whenever reset is pressed.
X * If the human object does not exist,
X * then it is created. The score and
X * level are reset. The first level
X * is created.
X *****************************************************************/
X
Xnew_proc()
X{
X /* Create the human */
X if(!human) {
X human = (ScreenItem) malloc(sizeof(struct screen_item));
X human->image = human_image;
X human->next = NULL;
X }
X
X /* Reset human to alive and looking like a human */
X human->type = HUMAN;
X human->dead = FALSE;
X human->image = human_image;
X human->oldrow = human->oldcol = -1;
X
X /* Reset score, level, and lives. Make first level */
X update_score(-current_score);
X update_level(1 - current_level);
X lives_remaining = 2;
X make_level();
X}
X
X
X/*****************************************************************
X * filer_proc() - Not Implemented Yet
X *****************************************************************/
X
Xfiler_proc()
X{
X}
X
X
X/*****************************************************************
X * teleport_proc() - Teleport the human to a random
X * place on the screen. An empty
X * location is found and the human is
X * moved there. Robots move after a
X * teleportation occurs.
X *****************************************************************/
X
Xteleport_proc()
X{
X int i, j; /* Loop variables */
X
X /* If the human is dead, forget it */
X if(human->dead)
X return;
X
X /* Make some fancy display */
X for(i = 0; i < 10; i++) {
X set_image(human, teleport_image[1], -1, -1);
X for(j = 0; j < TARDIS_BLINK_RATE; j++)
X ;
X set_image(human, teleport_image[0], -1, -1);
X for(j = 0; j < TARDIS_BLINK_RATE; j++)
X ;
X }
X
X /* Find an empty place and put the human there */
X human->oldrow = human->row;
X human->oldcol = human->col;
X find_empty(human, &(human->row), (&human->col));
X place_item(human, -1, -1);
X
X /* Make some more fancy display */
X for(i = 0; i < 10; i++) {
X set_image(human, teleport_image[1], -1, -1);
X for(j = 0; j < TARDIS_BLINK_RATE; j++)
X ;
X set_image(human, teleport_image[0], -1, -1);
X for(j = 0; j < TARDIS_BLINK_RATE; j++)
X ;
X }
X
X /* Put the human back to normal and move the robots */
X set_image(human, human_image, -1, -1);
X move_robots(ALL_ROBOTS);
X}
X
X
X/*****************************************************************
X * sonic_proc() - Activate sonic screwdriver.
X * Draw sonic blast and then remove
X * all robots in blast range.
X * Remove one use from screwdriver.
X *****************************************************************/
X
Xsonic_proc()
X{
X int i, j, k; /* Loop variables */
X
X /* If human is dead or screwdriver is empty, then forget it */
X if(!screwdriver_uses || human->dead)
X return;
X
X /* Decrement uses and draw zap */
X screwdriver_uses--;
X set_image(human, zap_image[0], -1, -1);
X for(i = 0; i < 10; i++) {
X for(j = 1; j < 4; j++) {
X set_image(human, zap_image[j], -1, -1);
X for(k = 1; k < SONIC_CYCLE_RATE; k++)
X ;
X }
X for(j = 2; j >= 0; j--) {
X set_image(human, zap_image[j], -1, -1);
X for(k = 1; k < SONIC_CYCLE_RATE; k++)
X ;
X }
X }
X set_image(human, human_image, -1, -1);
X
X /* Remove robots and let remaining robots move */
X remove_robots(human->col-1, human->row-1,
X human->col+1, human->row+1, LIVE_STATE, TRUE);
X move_robots(ALL_ROBOTS);
X}
X
X
X/*****************************************************************
X * stand_proc() - Let the player make a last stand.
X * Move robots until human is dead or
X * all robots are dead.
X *****************************************************************/
X
Xstand_proc()
X{
X /* If human is dead, then forget it */
X if(human->dead)
X return;
X
X /* Set last stand flag */
X last_stand_set = TRUE;
X
X /* Move the robots */
X while(move_robots(ALL_ROBOTS))
X ;
X}
X
X
X/*****************************************************************
X * quit_proc() - Put up an alert for confirmation
X * of quit. If OK, then destroy
X * the frame, else return to game.
X *****************************************************************/
X
Xquit_proc()
X{
X#ifdef SUNOS3_5
X window_destroy(frame);
X#else
X int result; /* Result from alert */
X Event event; /* Event from alert */
X
X /* Get result from an alert */
X result = alert_prompt(frame, &event,
X ALERT_MESSAGE_STRINGS, "Are you sure you want to Quit?", 0,
X ALERT_BUTTON_YES, "Confirm",
X ALERT_BUTTON_NO, "Cancel",
X 0);
X
X /* Process result */
X switch(result) {
X case ALERT_YES:
X window_destroy(frame);
X break;
X default:
X break;
X }
X#endif
X}
X
X
X/*****************************************************************
X * move_proc() - Get mouse coordinates from playfield
X * and make player move toward the click.
X *****************************************************************/
X
Xmove_proc(canvas, event)
XCanvas canvas;
XEvent *event;
X{
X int level; /* Level activated on */
X int action; /* The event action */
X int row, col; /* Row and column of mouse click */
X
X /* If not right or left mouse click or human is dead, forget it */
X#ifdef SUNOS3_5
X action = event_id(event);
X#else
X action = event_action(event);
X#endif
X if((action != MS_RIGHT && action != MS_LEFT &&
X action != MS_MIDDLE && action != KEY_TOP(1) &&
X action != KEY_TOP(2)) || human->dead)
X return;
X
X /* Convert coordinates to row/col */
X row = event_y(event) / ROW_HEIGHT;
X col = event_x(event) / COL_WIDTH;
X level = current_level;
X
X if(action == KEY_TOP(1)) {
X dump_pic();
X return;
X }
X if(action == KEY_TOP(2)) {
X dump_hs();
X return;
X }
X
X if(action == MS_LEFT)
X move_one(row, col);
X else
X while(TRUE) {
X /* If human dead or robots dead, stop */
X if(level != current_level || human->dead)
X break;
X
X /* If we are doing safe move, then think */
X if(action == MS_MIDDLE && unsafe(row, col))
X teleport_proc();
X
X /* Move once */
X move_one(row, col);
X
X /* If we arrive, then stop */
X if(row == human->row && col == human->col)
X break;
X }
X}
X
X
X/*****************************************************************
X * do_pop_proc() - Add or remove the popup high
X * score window.
X *****************************************************************/
X
Xdo_pop_proc()
X{
X /* If not shown, refresh and display, else remove it */
X if(!window_get(hs_popup_frame, WIN_SHOW)) {
X get_hs();
X update_hs();
X window_set(hs_popup_frame, WIN_SHOW, TRUE, 0);
X } else
X window_set(hs_popup_frame, WIN_SHOW, FALSE, 0);
X}
X
X
X/*
X *
X */
X
Xsetup_proc()
X{
X struct itimerval timer; /* Timer for removing message */
X
X timer.it_interval.tv_usec = 0;
X timer.it_interval.tv_sec = 1;
X timer.it_value.tv_usec = 0;
X timer.it_value.tv_sec = 1;
X
X notify_set_itimer_func(msg_popup_frame, startup_proc,
X ITIMER_REAL, &timer, NULL);
X}
X
X
X/*
X *
X */
X
Xstartup_proc()
X{
X new_proc();
X}
X
X
X/*****************************************************************
X * debug_proc() - For debugging. Teleport one
X * level.
X *****************************************************************/
X
Xdebug_proc()
X{
X /* Go up one level */
X update_level(1);
X make_level();
X}
X
X
X/*****************************************************************
X * live_proc() - For debugging. Bring human back
X * to life.
X *****************************************************************/
X
Xlive_proc()
X{
X ScreenItem temp;
X
X /* Bring human back to life */
X human->dead = FALSE;
X set_image(human, human_image, -1, -1);
X
X /* Refresh the robots */
X temp = robot_list;
X while(temp) {
X refresh_image(temp, 0, 0);
X temp = temp->next;
X }
X
X}
X
X
END_OF_FILE
if test 7724 -ne `wc -c <'proc.c'`; then
echo shar: \"'proc.c'\" unpacked with wrong size!
fi
# end of 'proc.c'
fi
if test -f 'sunbots.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'sunbots.c'\"
else
echo shar: Extracting \"'sunbots.c'\" \(16439 characters\)
sed "s/^X//" >'sunbots.c' <<'END_OF_FILE'
X/*****************************************************************
X *
X * sunbots.c - Robots for SunView
X *
X * Created -- 1/5/90 Kevin Wright
X *
X *****************************************************************/
X
X#include "sunbots.h" /* Robots header file */
X
X/*
X * Global Variables
X */
X
XFrame frame; /* Base frame for window */
XFrame hs_popup_frame; /* High score popup sub-frame */
XFrame msg_popup_frame; /* Message popup sub-frame */
XCanvas playfield; /* Main battlefield for robots */
XPixwin *playfield_pw; /* Pixwin for the battlefield */
XPixwin *window_pw; /* Pixwin for the window */
XPanel msg_window; /* Panel for displaying score */
XPanel cmd_window; /* Panel that contains buttons */
XPanel mov_window; /* Panel containing movement gadgets */
XPanel hs_popup_panel; /* High score popup sub-window */
XPanel msg_popup_panel; /* Message popup sub-window */
XPanel_item score; /* Item to display score and level */
XPanel_item msg_popup_label; /* Label for popup panel */
XPanel_item hs[10] = {0,0,0,0,0,0,0,0,0,0}; /* Top ten score panels */
XScreenItem human = NULL; /* Structure containing human */
XScreenItem robot_list = NULL; /* Linked list of robots */
X
XHiScoreList hs_list; /* High score chart */
X
Xint current_level; /* Current level number */
Xint current_score; /* Current score */
Xint screwdriver_uses; /* How many sonic blasts */
Xint last_stand_set; /* Are we doing a last stand */
Xint lives_remaining; /* Number of lives remaining */
X
X
X/*****************************************************************
X * main() - The base frame is created with title
X * "Robots". The images are initialized.
X * The message, playfield, and command
X * windows are set up and the game is started.
X *****************************************************************/
X
Xvoid main(argc, argv)
Xint argc;
Xchar **argv;
X{
X /* Seed random numbers */
X SEED(time(NULL));
X
X /* Build base frame */
X frame = window_create(NULL, FRAME,
X FRAME_ARGS, argc, argv,
X FRAME_LABEL, "Sunbots v2.0",
X#ifndef SUNOS3_5
X FRAME_NO_CONFIRM, TRUE,
X#endif
X FRAME_ICON, icon_image,
X 0);
X
X /* Init some panels */
X init_msg_window();
X init_playfield();
X
X /* Create the pixrect images */
X make_pics();
X
X /* Init remaining panels */
X init_cmd_window();
X init_hs_popup();
X init_msg_popup();
X
X /* Setup to start a new game */
X setup_proc();
X
X /* Fit the frame and do window loop */
X window_fit(frame);
X window_main_loop(frame);
X
X exit(0);
X}
X
X
X/*****************************************************************
X * init_msg_window() - The message window is
X * created. It contains the
X * level and score.
X *****************************************************************/
X
Xinit_msg_window()
X{
X /* Create message window */
X msg_window = window_create(frame, PANEL,
X WIN_ROWS, 1,
X 0);
X
X /* Create item to display level and score */
X score = panel_create_item(msg_window, PANEL_MESSAGE,
X PANEL_LABEL_STRING, "Level 0 Score 0",
X 0);
X}
X
X
X/*****************************************************************
X * init_playfield() - The playfield is created.
X * There are no margins and
X * no row/col gaps. The
X * only events that are noticed
X * by this window are those
X * from the left mouse button.
X *****************************************************************/
X
Xinit_playfield()
X{
X int i;
X unsigned char red[4], green[4], blue[4];
X
X /* Create playfield window */
X playfield = window_create(frame, CANVAS,
X WIN_ROW_HEIGHT, ROW_HEIGHT,
X WIN_COLUMN_WIDTH, COL_WIDTH,
X WIN_ROW_GAP, 0,
X WIN_COLUMN_GAP, 0,
X WIN_LEFT_MARGIN, 0,
X WIN_RIGHT_MARGIN, 0,
X WIN_TOP_MARGIN, 0,
X WIN_BOTTOM_MARGIN, 0,
X WIN_ROWS, SCRN_ROWS,
X WIN_COLUMNS, SCRN_COLS,
X WIN_BELOW, msg_window,
X WIN_CONSUME_KBD_EVENTS, WIN_NO_EVENTS,
X KEY_TOP(1),
X KEY_TOP(2),
X 0,
X WIN_CONSUME_PICK_EVENTS,WIN_NO_EVENTS,
X MS_LEFT, MS_RIGHT, MS_MIDDLE,
X 0,
X WIN_EVENT_PROC, move_proc,
X CANVAS_RETAINED, FALSE,
X 0);
X
X /* Get pixwin of playfield and window */
X window_pw = (Pixwin *) window_get(playfield, WIN_PIXWIN);
X playfield_pw = canvas_pixwin(playfield);
X
X /* Set color values */
X if(window_pw->pw_pixrect->pr_depth == 1)
X for(i = 0; i < 4; i++) {
X red[i] = (i == 0 ? 255 : 0);
X green[i] = (i == 0 ? 255 : 0);
X blue[i] = (i == 0 ? 255 : 0);
X }
X else
X for(i = 0; i < 4; i++) {
X red[i] = (i == 3 || i == 0 ? 255 : 0);
X green[i] = (i == 2 || i == 0 ? 255 : 0);
X blue[i] = (i == 1 || i == 0 ? 255 : 0);
X }
X
X /* Set color map for WIN_PIXWIN */
X pw_setcmsname(window_pw, "playfield_cm");
X pw_putcolormap(window_pw, 0, 4, red, green, blue);
X
X /* Set color map for CANVAS_PIXWIN */
X pw_setcmsname(playfield_pw, "playfield_cm");
X pw_putcolormap(playfield_pw, 0, 4, red, green, blue);
X
X /* Set canvas to retain */
X window_set(playfield, CANVAS_RETAINED, TRUE, 0);
X}
X
X
X/*****************************************************************
X * init_cmd_window() - The command window is
X * created and buttons are
X * created for each command.
X *****************************************************************/
X
Xinit_cmd_window()
X{
X /* Create command window */
X cmd_window = window_create(frame, PANEL,
X WIN_BELOW, msg_window,
X WIN_RIGHT_OF, playfield,
X WIN_WIDTH, 75,
X WIN_LEFT_MARGIN, 5,
X WIN_RIGHT_MARGIN, 5,
X 0);
X
X /* Create high scores gadget */
X panel_create_item(cmd_window, PANEL_BUTTON,
X PANEL_LABEL_IMAGE, scores_image->picture,
X PANEL_NOTIFY_PROC, do_pop_proc,
X 0);
X
X /* Create reset gadget */
X panel_create_item(cmd_window, PANEL_BUTTON,
X PANEL_LABEL_IMAGE, reset_image->picture,
X PANEL_NOTIFY_PROC, new_proc,
X 0);
X
X /* Create quit gadget */
X panel_create_item(cmd_window, PANEL_BUTTON,
X PANEL_LABEL_IMAGE, quit_image->picture,
X PANEL_NOTIFY_PROC, quit_proc,
X 0);
X
X /* Create last stand gadget */
X panel_create_item(cmd_window, PANEL_BUTTON,
X PANEL_LABEL_IMAGE, stand_image->picture,
X PANEL_NOTIFY_PROC, stand_proc,
X 0);
X
X /* Create sonic screwdriver gadget */
X panel_create_item(cmd_window, PANEL_BUTTON,
X PANEL_LABEL_IMAGE, sonic_image->picture,
X PANEL_NOTIFY_PROC, sonic_proc,
X 0);
X
X /* Create teleportation gadget */
X panel_create_item(cmd_window, PANEL_BUTTON,
X PANEL_LABEL_IMAGE, tardis_image->picture,
X PANEL_NOTIFY_PROC, teleport_proc,
X 0);
X
X /* Create filer gadget */
X panel_create_item(cmd_window, PANEL_BUTTON,
X PANEL_LABEL_IMAGE, filer_image->picture,
X PANEL_NOTIFY_PROC, filer_proc,
X 0);
X
X /* If UID = debugger, then put up debug icon */
X if(getuid() == DEBUG_UID) {
X panel_create_item(cmd_window, PANEL_BUTTON,
X PANEL_LABEL_IMAGE, debug_image->picture,
X PANEL_NOTIFY_PROC, debug_proc,
X 0);
X
X panel_create_item(cmd_window, PANEL_BUTTON,
X PANEL_LABEL_IMAGE, live_image->picture,
X PANEL_NOTIFY_PROC, live_proc,
X 0);
X }
X}
X
X
X/*****************************************************************
X * init_hs_popup() - Create the high score popup
X * window. Get the high scores and
X * add them to the window. Create
X * two DONE gadgets for removing the
X * chart.
X *****************************************************************/
X
Xinit_hs_popup()
X{
X /* Create the popup sub-frame and sub-window */
X hs_popup_frame = window_create(frame, FRAME,
X FRAME_LABEL, " TOP TEN ROBOT HUNTERS",
X FRAME_SHOW_LABEL, TRUE,
X WIN_SHOW, FALSE,
X 0);
X hs_popup_panel = window_create(hs_popup_frame,
X PANEL,
X 0);
X
X /* Get and update the high score list */
X get_hs();
X update_hs();
X
X /* Create two DONE buttons */
X panel_create_item(hs_popup_panel, PANEL_BUTTON,
X PANEL_ITEM_X, ATTR_COL(0),
X PANEL_ITEM_Y, ATTR_ROW(HS_NUM_SCORES + 1),
X PANEL_LABEL_IMAGE, panel_button_image(hs_popup_panel,
X "DONE", 5,
X 0),
X PANEL_NOTIFY_PROC, do_pop_proc,
X 0);
X panel_create_item(hs_popup_panel, PANEL_BUTTON,
X PANEL_ITEM_X, ATTR_COL(30),
X PANEL_ITEM_Y, ATTR_ROW(HS_NUM_SCORES + 1),
X PANEL_LABEL_IMAGE, panel_button_image(hs_popup_panel,
X "DONE", 5,
X 0),
X PANEL_NOTIFY_PROC, do_pop_proc,
X 0);
X
X /* Fit the panel and the frame */
X window_fit(hs_popup_panel);
X window_fit(hs_popup_frame);
X}
X
X
X/*****************************************************************
X * init_msg_popup() - Create a sub-frame and
X * sub-window to display a
X * message in.
X *****************************************************************/
X
Xinit_msg_popup()
X{
X /* Create sub-frame and sub-window */
X msg_popup_frame = window_create(frame, FRAME,
X WIN_SHOW, FALSE,
X 0);
X msg_popup_panel = window_create(msg_popup_frame, PANEL,
X 0);
X
X /* Create message label */
X msg_popup_label = panel_create_item(msg_popup_panel, PANEL_MESSAGE,
X PANEL_LABEL_STRING, " ",
X 0);
X
X /* Size to fit message */
X window_fit(msg_popup_panel);
X window_fit(msg_popup_frame);
X}
X
X
X/*****************************************************************
X * display_msg() - Add a message to the popup window
X * and display it.
X *****************************************************************/
X
Xdisplay_msg(string, time)
Xchar *string;
Xint time;
X{
X int play_x, play_y; /* Start point of playfield */
X int play_width, play_height; /* Width and height of playfield */
X int msg_width, msg_height; /* Width and height of popup msg */
X
X struct itimerval timer; /* Timer for removing message */
X
X /* Change the message string */
X panel_set(msg_popup_label, PANEL_LABEL_STRING, string, 0);
X
X /* Fit the windows again */
X window_fit(msg_popup_panel);
X window_fit(msg_popup_frame);
X
X /* Center frame in center of playfield */
X play_x = (int) window_get(playfield, WIN_X);
X play_y = (int) window_get(playfield, WIN_Y);
X play_width = (int) window_get(playfield, WIN_WIDTH);
X play_height = (int) window_get(playfield, WIN_HEIGHT);
X
X msg_width = (int) window_get(msg_popup_panel, WIN_WIDTH);
X msg_height = (int) window_get(msg_popup_panel, WIN_HEIGHT);
X
X window_set(msg_popup_frame,
X WIN_X, play_x + ((play_width - msg_width) >> 1),
X WIN_Y, play_y + ((play_height - msg_height) >> 1),
X 0);
X
X /* Set up time interval */
X timer.it_interval.tv_usec = 0;
X timer.it_interval.tv_sec = time;
X timer.it_value.tv_usec = 0;
X timer.it_value.tv_sec = time;
X
X /* Show the panel, wait some time, and remove the panel */
X window_set(msg_popup_frame, WIN_SHOW, TRUE, 0);
X notify_set_itimer_func(msg_popup_frame, kill_display,
X ITIMER_REAL, &timer, NULL);
X}
X
X
X/*****************************************************************
X * kill_display() - Remove the message from the screen.
X *****************************************************************/
X
Xkill_display()
X{
X window_set(msg_popup_frame, WIN_SHOW, FALSE, 0);
X notify_set_itimer_func(msg_popup_frame, kill_display,
X ITIMER_REAL, NULL, NULL);
X}
X
X
X/*****************************************************************
X * update_hs() - Update the high score display.
X * If called for the first time, then
X * create the message panels as well.
X *****************************************************************/
X
Xupdate_hs()
X{
X int i; /* Loop variable */
X char tempstr[80]; /* Temporary storage string */
X
X /* If first time, then build the panels. Setup the list */
X for(i = 0; i < HS_NUM_SCORES; i++) {
X if(!hs[i]) {
X hs[i] = panel_create_item(hs_popup_panel,PANEL_MESSAGE,
X PANEL_ITEM_X, ATTR_COL(0),
X PANEL_ITEM_Y, ATTR_ROW(i),
X 0);
X }
X
X sprintf(tempstr, "%2d) %-10s level %2d %6d pts",
X i + 1, hs_list.names[i], hs_list.levels[i],
X hs_list.scores[i]);
X panel_set(hs[i], PANEL_LABEL_STRING, tempstr, 0);
X }
X}
X
X
X/*****************************************************************
X * get_hs() - Get the high scores from the high
X * score file. If open fails, then
X * an error is reported and FALSE is
X * returned. TRUE is returned
X * otherwise.
X *****************************************************************/
X
Xget_hs()
X{
X int i; /* Loop variable */
X FILE *hs_file; /* Pointer to the high score file */
X
X /* Open high score file and report any errors */
X if(!(hs_file = fopen(HSFILE, "r"))) {
X fprintf(stderr, "get_ps: Can't open high score file %s\n",
X HSFILE);
X return(FALSE);
X }
X
X /* Read the high score list and close the file */
X fread((char *) &hs_list, sizeof(hs_list), 1, hs_file);
X fclose(hs_file);
X
X return(TRUE);
X}
X
X
X/*****************************************************************
X * put_hs - Write the new high score list to
X * the high score file. Report any
X * errors in opening the file.
X *****************************************************************/
X
Xput_hs()
X{
X FILE *hs_file; /* Pointer to the high score file */
X
X /* Open the high score file and report any errors */
X if(!(hs_file = fopen(HSFILE, "w"))) {
X fprintf(stderr, "put_hs: Can't open high score file %s\n",
X HSFILE);
X return;
X }
X
X /* Write the high score list and close the file */
X fwrite((char *) &hs_list, sizeof(hs_list), 1, hs_file);
X fclose(hs_file);
X}
X
X
X/*****************************************************************
X * make_hs() - Add a new high score to the high
X * score chart. First lock the chart
X * against access. Get the current
X * score list and add the new score to
X * the list. Write the new list out
X * and unlock the file.
X *****************************************************************/
X
Xmake_hs()
X{
X int obtained; /* Flag indicating successful hs lookup */
X int i, j; /* Loop variables */
X
X /* Lock the high score file and exit if fails */
X if(!lock_hs_file())
X return;
X
X /* Get the high score file and add the new score */
X obtained = get_hs();
X for(i = 0; i < 10; i++)
X if(hs_list.scores[i] < current_score) {
X for(j = 9; j > i; j--) {
X hs_list.scores[j] = hs_list.scores[j - 1];
X hs_list.levels[j] = hs_list.levels[j - 1];
X strcpy(hs_list.names[j], hs_list.names[j - 1]);
X }
X hs_list.scores[i] = current_score;
X hs_list.levels[i] = current_level;
X strcpy(hs_list.names[i], getpwuid(getuid())->pw_name);
X break;
X }
X
X /* If the high score was obtained properly, then write the new list */
X if(obtained) {
X put_hs();
X update_hs();
X }
X
X /* Unlock the high score file */
X unlock_hs_file();
X}
X
X
X/*****************************************************************
X * lock_hs_file() - Lock the high score file against
X * access by another program. Creates
X * a link to the high score file.
X * If the link fails, it will try
X * multiple times (waiting for other
X * process to give it up) and then it
X * will give up and register an error.
X *****************************************************************/
X
Xlock_hs_file()
X{
X int count = 0; /* Counter for number of attempts made */
X
X /* Try to create the link */
X while(link(HSFILE, HSLOCK) == -1 &&
X count < MAX_LOCK_TRIES)
X count++;
X
X /* If failed, then send an error message */
X if(count >= MAX_LOCK_TRIES)
X fprintf(stderr, "Could not create lock %s\n",
X HSLOCK);
X
X return(count < MAX_LOCK_TRIES);
X}
X
X
X/*****************************************************************
X * unlock_hs_file() - Unlock the high score file
X * so that other processes can
X * access it.
X *****************************************************************/
X
Xunlock_hs_file()
X{
X /* Unlink lock file */
X unlink(HSLOCK);
X}
X
X
X/*****************************************************************
X * dump_pic() - Dump the screen to a file.
X *****************************************************************/
X
Xdump_pic()
X{
X char *filename, command[512];
X int x, y, X, Y;
X
X if((filename = tempnam(".", "rdump")) == NULL)
X fprintf(stderr, "Can't make dumpfile!\n");
X else {
X x = (int) window_get(frame, WIN_X);
X y = (int) window_get(frame, WIN_Y);
X X = (int) window_get(frame, WIN_WIDTH);
X Y = (int) window_get(frame, WIN_HEIGHT);
X sprintf(command, "screendump -x%d -y%d -X%d -Y%d %s",
X x, y, X, Y, filename);
X system(command);
X }
X}
X
X
X/*****************************************************************
X * dump_hs() - Dump the high score to a file.
X *****************************************************************/
X
Xdump_hs()
X{
X char *filename, command[512];
X int x, y, X, Y;
X
X if((filename = tempnam(".", "hdump")) == NULL)
X fprintf(stderr, "Can't make dumpfile!\n");
X else {
X x = (int) window_get(hs_popup_frame, WIN_X) +
X (int) window_get(frame, WIN_X);
X y = (int) window_get(hs_popup_frame, WIN_Y) +
X (int) window_get(frame, WIN_Y);
X X = (int) window_get(hs_popup_frame, WIN_WIDTH);
X Y = (int) window_get(hs_popup_frame, WIN_HEIGHT);
X sprintf(command, "screendump -x%d -y%d -X%d -Y%d %s",
X x, y, X, Y, filename);
X system(command);
X }
X}
END_OF_FILE
if test 16439 -ne `wc -c <'sunbots.c'`; then
echo shar: \"'sunbots.c'\" unpacked with wrong size!
fi
# end of 'sunbots.c'
fi
if test -f 'sunbots.h' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'sunbots.h'\"
else
echo shar: Extracting \"'sunbots.h'\" \(5034 characters\)
sed "s/^X//" >'sunbots.h' <<'END_OF_FILE'
X/*****************************************************************
X *
X * sunbots.h - Sunview Robots Header File
X *
X * Created -- 1/5/90 Kevin Wright
X *
X *****************************************************************/
X
X#ifndef SUNBOTS_H
X# define SUNBOTS_H
X
X# include <suntool/sunview.h>
X# include <suntool/canvas.h>
X# include <suntool/panel.h>
X# include <suntool/icon.h>
X# include <suntool/tty.h>
X# include <stdio.h>
X# ifndef SUNOS3_5
X# include <suntool/alert.h>
X# endif
X# include <suntool/seln.h>
X# include <pwd.h>
X# include <sys/time.h>
X# include <sunwindow/notify.h>
X# include "images.h"
X
X/*
X * Defines
X */
X
X# define SEED(x) (srandom(x)) /* Random numbers */
X# define RND(x) ((random() >> 3) % x)
X
X# define NORTH 0 /* North */
X# define NORTH_WEST 1 /* North-west */
X# define NORTH_EAST 2 /* North-east */
X# define SOUTH 3 /* South */
X# define SOUTH_WEST 4 /* South-west */
X# define SOUTH_EAST 5 /* South-east */
X# define EAST 6 /* East */
X# define WEST 7 /* West */
X# define NO_MOVE 8 /* No Direction */
X
X# define COLLISION_HUMAN 1 /* Collision with human */
X# define COLLISION_ROBOT 2 /* Collision with robot */
X# define COLLISION_TRASH 3 /* Collision with trash */
X# define COLLISION_GEM 4 /* Collision with gem */
X# define COLLISION_OTHER 5 /* Unknown collision */
X
X# define LIVE_STATE 1 /* Robot is alive */
X# define DEAD_STATE 2 /* Robot is dead */
X# define ALL_STATES 3 /* Alive or dead */
X
X# define SPEEDER_LEVEL 5 /* Starting speeder level */
X# define SPEEDER_CHANCE 10 /* Chance of being fast */
X
X# define ALL_ROBOTS 1 /* All robots */
X# define NORMAL_ROBOT 2 /* Normal robot */
X# define SPEEDER_ROBOT 3 /* Faster robot */
X# define HUMAN 4 /* Not a robot */
X# define GEM 5 /* A gem */
X
X# define ROW_HEIGHT 16 /* Height of a row */
X# define COL_WIDTH 16 /* Width of a column */
X# define SCRN_ROWS 40 /* Rows per screen */
X# define SCRN_COLS 40 /* Columns per screen */
X# define SCREEN_HEIGHT (SCRN_ROWS * ROW_HEIGHT)
X# define SCREEN_WIDTH (SCRN_COLS * COL_WIDTH)
X
X# define TARDIS_BLINK_RATE 10000 /* Loop for tardis blink */
X# define SONIC_CYCLE_RATE 5000 /* Loop for sonic cycle */
X
X# define HS_NAME_LEN 20 /* Length of high score name */
X# define HS_NUM_SCORES 10 /* Number of high scores */
X# ifndef HSFILE /* Sunbot high score file */
X# define HSFILE "/usr/games/lib/.sunbots.hs"
X# endif
X# ifndef HSLOCK /* Sunbot hs lock file */
X# define HSLOCK "/usr/games/lib/.sunbots.hs.lock"
X# endif
X# define MAX_LOCK_TRIES 50
X
X# define DEBUG_UID 114 /* Uid of debugger */
X
X/*
X * Structures
X */
X
Xtypedef struct screen_item {
X int row, col; /* Row and column of item */
X int oldrow, oldcol; /* Old position of item */
X int type; /* Type of robot */
X int dead; /* Flag indicating death */
X Image image; /* Pointer to panel item */
X struct screen_item *next; /* Pointer to next structure */
X} *ScreenItem;
X
Xtypedef struct {
X char names[HS_NUM_SCORES][HS_NAME_LEN + 1]; /* Names of scorers */
X int scores[HS_NUM_SCORES]; /* High scores */
X int levels[HS_NUM_SCORES]; /* High levels */
X} HiScoreList;
X
X/*
X * Global Variables
X */
X
Xextern Frame frame; /* Base frame for window */
Xextern Frame hs_popup_frame; /* High score popup sub-frame */
Xextern Frame msg_popup_frame;/* Message popup sub-frame */
Xextern Canvas playfield; /* Main battlefield for robots */
Xextern Pixwin *playfield_pw; /* Pixwin for the battlefield */
Xextern Panel msg_window; /* Panel for displaying score */
Xextern Panel cmd_window; /* Panel that contains buttons */
Xextern Panel mov_window; /* Panel containing movement gadgets */
Xextern Panel hs_popup_panel; /* High score popup sub-window */
Xextern Panel msg_popup_panel;/* Message popup sub-window */
Xextern Panel_item score; /* Item to display score and level */
Xextern Panel_item msg_popup_label;/* Label for popup panel */
Xextern Panel_item hs[10]; /* Top ten scores */
Xextern ScreenItem human; /* Structure containing human */
Xextern ScreenItem robot_list; /* Linked list of robots */
X
Xextern HiScoreList hs_list; /* High score chart */
X
Xextern int current_level; /* Current level number */
Xextern int current_score; /* Current score */
Xextern int screwdriver_uses; /* How many sonic blasts */
Xextern int last_stand_set; /* Are we doing a last stand */
Xextern int lives_remaining; /* Number of lives remaining */
X
X
X/*
X * Functions
X */
X
Xint init_msg_window(), init_playfield(), init_cmd_window(), init_hs_popup();
Xint new_proc(), filer_proc(), move_proc(), move_human(), get_hs(), put_hs();
Xint teleport_proc(), sonic_proc(), stand_proc(), quit_proc(), make_level();
Xint destroy_robots(), create_robots(), find_empty(), place_item();
Xint move_robots(), collision(), all_dead(), update_score(), update_level();
Xint do_death(), update_hs(), do_pop_proc(), lock_hs_file(), init_msg_popup();
Xint unlock_hs_file(), make_hs(), debug_proc(), live_proc(), display_msg();
Xint kill_display(), setup_proc(), startup_proc(), set_image();
X
XScreenItem occupied();
X
X#endif /* SUNBOTS_H */
END_OF_FILE
if test 5034 -ne `wc -c <'sunbots.h'`; then
echo shar: \"'sunbots.h'\" unpacked with wrong size!
fi
# end of 'sunbots.h'
fi
echo shar: End of archive 1 \(of 3\).
cp /dev/null ark1isdone
MISSING=""
for I in 1 2 3 ; do
if test ! -f ark${I}isdone ; then
MISSING="${MISSING} ${I}"
fi
done
if test "${MISSING}" = "" ; then
echo You have unpacked all 3 archives.
rm -f ark[1-9]isdone
else
echo You still need to unpack the following archives:
echo " " ${MISSING}
fi
## End of shell archive.
exit 0