games@tekred.CNA.TEK.COM (04/04/89)
Submitted-by: phill%med-image.compsci.bristol.ac.uk@nss.cs.ucl.ac.uk Posting-number: Volume 6, Issue 43 Archive-name: sun-tetris2 [The other day I received two implementations of tetris under SunView. This is the second one. They both use color (colour) on machines that support it. I have tested them both on a B&W Sun 3/60, SunOS 3.5. Be sure you reference the correct one when posting comments, bugfixes, etc. -br] #! /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 1)." # Contents: README MANIFEST COPYRIGHT Makefile colours.c defs.h draw.c # event.c init.c main.c notify.c score.c shape.c support.c tetris.6 # tetris.icon window.c # Wrapped by billr@saab on Mon Apr 3 12:45:55 1989 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'\" \(775 characters\) sed "s/^X//" >'README' <<'END_OF_FILE' XSunview Based Tetris X XThis version of tetris is based on the version posted to Xcomp.sources.games by Adam Marguilies <vespa@ssyx.ucsc.edu> in early XMarch, 1989. We have only used the routine define_shapes() from his Xcode together with the basic shape data structure. X XThis was developed under SunOS4.01 running on a Sun3. X XTo install: X X Set HIGH_SCORE_TABLE in defs.h to the pathname of your high X scores table. (If you do not want tetris to be installed setuid X (the default) this file will have to be globally X read/writable). The high score file will be created the first X time tetris is executed. X X Set BINDIR in Makefile to be the desired location of the X compiled binary. X X type "make install" X XPhill Everson & Martyn Shortley XBristol University, UK X X31st March, 1989 END_OF_FILE if test 775 -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'\" \(641 characters\) sed "s/^X//" >'MANIFEST' <<'END_OF_FILE' X File Name Archive # Description X----------------------------------------------------------- X COPYRIGHT 1 X MANIFEST 1 This shipping list X Makefile 1 X README 1 X colours.c 1 X defs.h 1 X draw.c 1 X event.c 1 X init.c 1 X main.c 1 X notify.c 1 X score.c 1 X shape.c 1 X support.c 1 X tetris.6 1 X tetris.icon 1 X window.c 1 END_OF_FILE if test 641 -ne `wc -c <'MANIFEST'`; then echo shar: \"'MANIFEST'\" unpacked with wrong size! fi # end of 'MANIFEST' fi if test -f 'COPYRIGHT' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'COPYRIGHT'\" else echo shar: Extracting \"'COPYRIGHT'\" \(1143 characters\) sed "s/^X//" >'COPYRIGHT' <<'END_OF_FILE' XCopyright 1989 Phill Everson & Martyn Shortley X XThis notice and any statement of authorship must be reproduced Xon all copies. The authors do not make any warranty expressed Xor implied, or assume any liability or responsiblity for the Xuse of this software. X XAny distributor of copies of this software shall grant the Xrecipient permission for further redistribution as permitted Xby this notice. Any distributor must distribute this software Xwithout any fee or other monetary gains, unless expressed written Xpermission is granted by the authors. X XThis software or its use shall not be: sold, rented, leased, Xtraded, or otherwise marketed without the expressed written Xpermission of the authors. X XIf the software is modified in a manner creating derivative Xcopyrights, appropriate legends may be placed on derivative Xwork in addition to that set forth above. X XPermission is hereby granted to copy, reproduce, redistribute or Xotherwise use this software as long as the conditions above Xare met. X XAll rights not granted by this notice are reserved. X XAuthors: Phill Everson <everson@cs.bris.ac.uk> X Martyn Shortley <shortley@cs.bris.ac.uk> END_OF_FILE if test 1143 -ne `wc -c <'COPYRIGHT'`; then echo shar: \"'COPYRIGHT'\" unpacked with wrong size! fi # end of 'COPYRIGHT' fi if test -f 'Makefile' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'Makefile'\" else echo shar: Extracting \"'Makefile'\" \(652 characters\) sed "s/^X//" >'Makefile' <<'END_OF_FILE' XBINDIR=/usr/doc1/phill/bin XCFLAGS=-O X#CFLAGS=-g X XPROG=tetris XCFILES=main.c event.c init.c shape.c support.c notify.c colours.c window.c \ X score.c draw.c XOFILES=main.o event.o init.o shape.o support.o notify.o colours.o window.o \ X score.o draw.o X X$(PROG): $(OFILES) X cc $(CFLAGS) -o $(PROG) $(OFILES) -lsuntool -lsunwindow -lpixrect X X$(OFILES): defs.h X X# tetris needs to be setuid so that the high scores file can be updated. X# if you don't like setuid programs on your system then just make sure X# that the high score file is globally read/writable. Xinstall: $(PROG) X install -s $(PROG) $(BINDIR) X chmod u+s $(BINDIR)/$(PROG) X Xclean: X rm *.o core END_OF_FILE if test 652 -ne `wc -c <'Makefile'`; then echo shar: \"'Makefile'\" unpacked with wrong size! fi # end of 'Makefile' fi if test -f 'colours.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'colours.c'\" else echo shar: Extracting \"'colours.c'\" \(888 characters\) sed "s/^X//" >'colours.c' <<'END_OF_FILE' X#include "defs.h" X Xsetup_colours(pw) XPixrect *pw; X{ X unsigned char red[NO_COLS], green[NO_COLS], blue[NO_COLS]; X int i; X X pw_setcmsname(pw, "TETRIS"); X X for (i=0; i < NO_COLS; i++) X red[i] = green[i] = blue[i] = 255; X pw_putcolormap(pw, 0, NO_COLS, red, green, blue); X X red[WHITE] = 255; green[WHITE] = 255; blue[WHITE] = 255; X red[RED] = 255; green[RED] = 0; blue[RED] = 0; X red[ORANGE] = 255; green[ORANGE] = 120; blue[ORANGE] = 50; X red[YELLOW] = 245; green[YELLOW] = 245; blue[YELLOW] = 0; X red[GREEN] = 0; green[GREEN] = 255; blue[GREEN] = 0; X red[BLUE] = 0; green[BLUE] = 0; blue[BLUE] = 255; X red[CYAN] = 0; green[CYAN] = 245; blue[CYAN] = 245; X red[VIOLET] = 128; green[VIOLET] = 0; blue[VIOLET] = 178; X red[BLACK] = 0; green[BLACK] = 0; blue[BLACK] = 0; X X pw_putcolormap(pw, 0, NO_COLS, red, green, blue); X} X END_OF_FILE if test 888 -ne `wc -c <'colours.c'`; then echo shar: \"'colours.c'\" unpacked with wrong size! fi # end of 'colours.c' fi if test -f 'defs.h' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'defs.h'\" else echo shar: Extracting \"'defs.h'\" \(2314 characters\) sed "s/^X//" >'defs.h' <<'END_OF_FILE' X#include <stdio.h> X#include <sys/time.h> X#include <suntool/sunview.h> X#include <suntool/panel.h> X#include <suntool/canvas.h> X#include <sunwindow/notify.h> X#include <pixrect/pixrect_hs.h> X X#define UWIDTH 10 /* canvas size in units */ X#define UHEIGHT 30 X X#define UNIT 20 /* pixels in a unit */ X#define SHADOW_OFFSET UNIT X#define SHADOW_HEIGHT (UNIT+SHADOW_OFFSET) /* shadow area height in X * pixels */ X#define NEXT_HEIGHT (UNIT*5) /* Height for next block */ X X#define HIGH_TABLE_SIZE 10 /* size of high score table */ X#ifndef HIGH_SCORE_TABLE X# define HIGH_SCORE_TABLE "/usr/games/lib/tetris_scores" X#endif X X#define ITIMER_NULL ((struct itimerval *)0) X X#define NO_COLS 16 X X#define WHITE 0 X#define RED 1 X#define ORANGE 2 X#define YELLOW 3 X#define GREEN 4 X#define BLUE 5 X#define CYAN 6 X#define VIOLET 7 X#define BLACK 8 X X#define OP (PIX_SRC | PIX_COLOR(col)) X#define CLR (PIX_SRC | PIX_COLOR(WHITE)) X X XFrame frame, score_frame; XPanel panel, score_panel; XCanvas canvas; XPixwin *pw; XPanel_item high_score_item[HIGH_TABLE_SIZE+1], score_item, level_item, rows_item, game_over; XPixrect *pr; X Xint end_of_game, score_position; Xint shape_no, xpos, ypos, rot, score, rows; Xint next_no, next_rot; Xchar *name; Xint monochrome; Xunsigned char grid[UWIDTH][UHEIGHT]; X Xstruct score_table { X char name[BUFSIZ]; X int score; X int rows; X int level; X char hostname[BUFSIZ]; X char date[BUFSIZ]; X} high_scores[HIGH_TABLE_SIZE]; X Xstruct shape_table { X int table[4][4]; X int width; X int height; X int offset; X int pointv[4]; X char color; X} shape[7]; X Xstruct shape { X int shape; X int rot; X int width; X int height; X int offset; X int pointv; X char color; X int was_shown; X int was_shadowed; X} *current, *next; X Xint my_client_object; XNotify_client *me; X Xvoid print_high_scores(), done_proc(), quit_proc(), start_proc(), pause_proc(), restart_proc(); Xvoid canvas_event_proc(); XNotify_value drop_block(); END_OF_FILE if test 2314 -ne `wc -c <'defs.h'`; then echo shar: \"'defs.h'\" unpacked with wrong size! fi # end of 'defs.h' fi if test -f 'draw.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'draw.c'\" else echo shar: Extracting \"'draw.c'\" \(4604 characters\) sed "s/^X//" >'draw.c' <<'END_OF_FILE' X#include "defs.h" X Xdraw_shadow(shape_no, xpos, ypos, rot, col) X int shape_no, xpos, ypos, rot, col; X{ X int y1; X int x1, x2, x3, x4; X int t0, t1, t2, t3; X int xsize; X X t0 = shape[shape_no].table[0][rot]; /* Bit map of 1st Row */ X t1 = shape[shape_no].table[1][rot]; /* Bit map of 2nd Row */ X t2 = shape[shape_no].table[2][rot]; /* Bit map of 3rd Row */ X t3 = shape[shape_no].table[3][rot]; /* Bit map of 4th Row */ X X x1 = xpos * UNIT; /* Position of 1st column of block grid */ X x2 = x1 + UNIT; /* Position of 2nd column of block grid */ X x3 = x2 + UNIT; /* Position of 3rd column of block grid */ X x4 = x3 + UNIT; /* Position of 4th column of block grid */ X X y1 = UHEIGHT * UNIT + SHADOW_OFFSET / 2; X xsize = UWIDTH * UNIT; X X pw_batch_on(pw); X pw_rop(pw, 0, y1, xsize, UNIT, CLR, NULL, 0, 0); X if (t0 & 8 || t1 & 8 || t2 & 8 || t3 & 8) X pw_rop(pw, x1, y1, UNIT, UNIT, OP, NULL, 0, 0); X if (t0 & 4 || t1 & 4 || t2 & 4 || t3 & 4) X pw_rop(pw, x2, y1, UNIT, UNIT, OP, NULL, 0, 0); X if (t0 & 2 || t1 & 2 || t2 & 2 || t3 & 2) X pw_rop(pw, x3, y1, UNIT, UNIT, OP, NULL, 0, 0); X if (t0 & 1 || t1 & 1 || t2 & 1 || t3 & 1) X pw_rop(pw, x4, y1, UNIT, UNIT, OP, NULL, 0, 0); X pw_batch_off(pw); X} X Xshow_next() X{ X int y, y1, xsize; X X y = UHEIGHT * UNIT + SHADOW_HEIGHT; X xsize = UNIT * UWIDTH; X X pw_batch_on(pw); X pw_rop(pw, 0, y + UNIT, xsize, NEXT_HEIGHT - UNIT, CLR, NULL, 0, 0); X X pw_text(pw, 5, y + UNIT, PIX_SRC, NULL, "Next block"); X X y1 = y / UNIT + 1; X print_shape(next_no, 5, y1, next_rot, shape[next_no].color); X X pw_batch_off(pw); X} X Xprint_shape(shape_no, x, y, rot, col) X int shape_no, x, y, rot, col; X{ X int x1, x2, x3, x4, y1; X int t0, t1, t2, t3; X X t0 = shape[shape_no].table[0][rot]; /* Bit map of 1st Row */ X t1 = shape[shape_no].table[1][rot]; /* Bit map of 2nd Row */ X t2 = shape[shape_no].table[2][rot]; /* Bit map of 3rd Row */ X t3 = shape[shape_no].table[3][rot]; /* Bit map of 4th Row */ X X x1 = x * UNIT; /* Position of 1st column of block grid */ X x2 = x1 + UNIT; /* Position of 2nd column of block grid */ X x3 = x2 + UNIT; /* Position of 3rd column of block grid */ X x4 = x3 + UNIT; /* Position of 4th column of block grid */ X y1 = y * UNIT; /* Position of 1st row of block grid */ X X if (y > -1) { X if (t0 & 8) X pw_rop(pw, x1, y1, UNIT, UNIT, OP, NULL, 0, 0); X if (t0 & 4) X pw_rop(pw, x2, y1, UNIT, UNIT, OP, NULL, 0, 0); X if (t0 & 2) X pw_rop(pw, x3, y1, UNIT, UNIT, OP, NULL, 0, 0); X if (t0 & 1) X pw_rop(pw, x4, y1, UNIT, UNIT, OP, NULL, 0, 0); X } X y1 += UNIT; /* Position of next row */ X if (y > -2) { X if (t1 & 8) X pw_rop(pw, x1, y1, UNIT, UNIT, OP, NULL, 0, 0); X if (t1 & 4) X pw_rop(pw, x2, y1, UNIT, UNIT, OP, NULL, 0, 0); X if (t1 & 2) X pw_rop(pw, x3, y1, UNIT, UNIT, OP, NULL, 0, 0); X if (t1 & 1) X pw_rop(pw, x4, y1, UNIT, UNIT, OP, NULL, 0, 0); X } X y1 += UNIT; /* Position of next row */ X if (y > -3) { X if (t2 & 8) X pw_rop(pw, x1, y1, UNIT, UNIT, OP, NULL, 0, 0); X if (t2 & 4) X pw_rop(pw, x2, y1, UNIT, UNIT, OP, NULL, 0, 0); X if (t2 & 2) X pw_rop(pw, x3, y1, UNIT, UNIT, OP, NULL, 0, 0); X if (t2 & 1) X pw_rop(pw, x4, y1, UNIT, UNIT, OP, NULL, 0, 0); X } X y1 += UNIT; /* Position of next row */ X if (y > -4) { X if (t3 & 8) X pw_rop(pw, x1, y1, UNIT, UNIT, OP, NULL, 0, 0); X if (t3 & 4) X pw_rop(pw, x2, y1, UNIT, UNIT, OP, NULL, 0, 0); X if (t3 & 2) X pw_rop(pw, x3, y1, UNIT, UNIT, OP, NULL, 0, 0); X if (t3 & 1) X pw_rop(pw, x4, y1, UNIT, UNIT, OP, NULL, 0, 0); X } X} END_OF_FILE if test 4604 -ne `wc -c <'draw.c'`; then echo shar: \"'draw.c'\" unpacked with wrong size! fi # end of 'draw.c' fi if test -f 'event.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'event.c'\" else echo shar: Extracting \"'event.c'\" \(749 characters\) sed "s/^X//" >'event.c' <<'END_OF_FILE' X#include "defs.h" X Xvoid Xcanvas_event_proc(canvas, event, arg) X Canvas canvas; X Event *event; X caddr_t arg; X{ X if (event_is_up(event)) X return; X X switch (event_id(event)) { X case MS_LEFT: X if (event_shift_is_down(event)) X anti_proc(); X else X left_proc(); X break; X case MS_RIGHT: X if (event_shift_is_down(event)) X clock_proc(); X else X right_proc(); X break; X X case MS_MIDDLE: X if (!event_shift_is_down(event)) X fast_proc(); X break; X } X} END_OF_FILE if test 749 -ne `wc -c <'event.c'`; then echo shar: \"'event.c'\" unpacked with wrong size! fi # end of 'event.c' fi if test -f 'init.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'init.c'\" else echo shar: Extracting \"'init.c'\" \(1670 characters\) sed "s/^X//" >'init.c' <<'END_OF_FILE' X#include "defs.h" X#include <sys/types.h> X#include <sys/timeb.h> X#include <pwd.h> X Xinitialise() X{ X struct passwd *who; X int depth; X Pixrect *mem_create(); X char *getenv(); X X srand((int) time((time_t *) 0)); X define_shapes(); X depth = pw->pw_prretained->pr_depth; X monochrome = 0; X if (depth == 1) X monochrome = 1; X if ((pr = mem_create(UNIT * UWIDTH, UNIT * UHEIGHT, depth)) == NULL) { X fprintf(stderr, "mem_create() returned NULL\n"); X exit(-1); X } X if ((name = getenv("TETRIS")) == NULL) { X who = getpwuid(getuid()); X name = who->pw_name; X } X print_authors(); X init_all(); X read_high_scores(); X} X Xinit_all() X{ X int i, j; X X score_position = -1; X end_of_game = 0; X rows = score = shape_no = rot = xpos = ypos = 0; X for (i = 0; i < UWIDTH; i++) X for (j = 0; j < UHEIGHT; j++) X grid[i][j] = 0; X create_shape(); /* Set up 1st shape */ X create_shape(); /* Set up next shape */ X pw_rop(pw, 0, 0, UNIT * UWIDTH, UNIT * UHEIGHT, PIX_SRC | PIX_COLOR(WHITE), NULL, 0, 0); X pw_vector(pw, 0, UHEIGHT * UNIT, UWIDTH * UNIT, UHEIGHT * UNIT, PIX_SRC | PIX_COLOR(BLACK), 0); X pw_vector(pw, 0, UHEIGHT * UNIT + SHADOW_HEIGHT, UWIDTH * UNIT, UHEIGHT * UNIT + SHADOW_HEIGHT, PIX_SRC | PIX_COLOR(BLACK), 0); X panel_set(game_over, PANEL_SHOW_ITEM, FALSE, 0); X show_score(); X show_next(); X draw_shadow(shape_no, xpos, ypos, rot, shape[shape_no].color); X} END_OF_FILE if test 1670 -ne `wc -c <'init.c'`; then echo shar: \"'init.c'\" unpacked with wrong size! fi # end of 'init.c' fi if test -f 'main.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'main.c'\" else echo shar: Extracting \"'main.c'\" \(5543 characters\) sed "s/^X//" >'main.c' <<'END_OF_FILE' X#include "defs.h" X Xstatic short icon_image[] = { X#include "tetris.icon" X}; X Xmpr_static(tetris_icon, 64, 64, 1, icon_image); X Xmain(argc, argv) X int argc; X char **argv; X{ X int i; X Icon icon; X X icon = icon_create(ICON_IMAGE, &tetris_icon, 0); X frame = window_create(NULL, FRAME, X FRAME_LABEL, "tetris", X FRAME_ICON, icon, X FRAME_ARGS, argc, argv, X 0); X panel = window_create(frame, PANEL, X WIN_WIDTH, UWIDTH * UNIT, X 0); X score_item = panel_create_item(panel, PANEL_MESSAGE, X PANEL_ITEM_X, ATTR_COL(0), X PANEL_ITEM_Y, ATTR_ROW(0), X PANEL_LABEL_STRING, "Score: 0", X 0); X level_item = panel_create_item(panel, PANEL_MESSAGE, X PANEL_ITEM_X, ATTR_COL(0), X PANEL_ITEM_Y, ATTR_ROW(1), X PANEL_LABEL_STRING, "Level: 0", X 0); X rows_item = panel_create_item(panel, PANEL_MESSAGE, X PANEL_ITEM_X, ATTR_COL(0), X PANEL_ITEM_Y, ATTR_ROW(2), X PANEL_LABEL_STRING, "Rows : 0", X 0); X game_over = panel_create_item(panel, PANEL_MESSAGE, X PANEL_ITEM_X, ATTR_COL(0), X PANEL_ITEM_Y, ATTR_ROW(3), X PANEL_LABEL_STRING, "Game Over", X PANEL_SHOW_ITEM, FALSE, X 0); X panel_create_item(panel, PANEL_BUTTON, X PANEL_ITEM_X, ATTR_COL(13), X PANEL_ITEM_Y, ATTR_ROW(0), X PANEL_LABEL_IMAGE, panel_button_image(panel, "Start", 0, 0), X PANEL_NOTIFY_PROC, start_proc, X 0); X panel_create_item(panel, PANEL_BUTTON, X PANEL_ITEM_X, ATTR_COL(13), X PANEL_ITEM_Y, ATTR_ROW(1), X PANEL_LABEL_IMAGE, panel_button_image(panel, "Pause", 0, 0), X PANEL_NOTIFY_PROC, pause_proc, X 0); X panel_create_item(panel, PANEL_BUTTON, X PANEL_ITEM_X, ATTR_COL(13), X PANEL_ITEM_Y, ATTR_ROW(2), X PANEL_LABEL_IMAGE, panel_button_image(panel, "New Game", 0, 0), X PANEL_NOTIFY_PROC, restart_proc, X 0); X panel_create_item(panel, PANEL_BUTTON, X PANEL_ITEM_X, ATTR_COL(13), X PANEL_ITEM_Y, ATTR_ROW(3), X PANEL_LABEL_IMAGE, panel_button_image(panel, "Scores", 0, 0), X PANEL_NOTIFY_PROC, print_high_scores, X 0); X X panel_create_item(panel, PANEL_BUTTON, X PANEL_ITEM_X, ATTR_COL(13), X PANEL_ITEM_Y, ATTR_ROW(4), X PANEL_LABEL_IMAGE, panel_button_image(panel, "Quit", 0, 0), X PANEL_NOTIFY_PROC, quit_proc, X 0); X window_fit_height(panel); X canvas = window_create(frame, CANVAS, X WIN_X, 0, X WIN_BELOW, panel, X WIN_WIDTH, UWIDTH * UNIT, X WIN_HEIGHT, UHEIGHT * UNIT + SHADOW_HEIGHT + NEXT_HEIGHT, X WIN_EVENT_PROC, canvas_event_proc, X 0); X X X pw = canvas_pixwin(canvas); X setup_colours(pw); X window_fit(frame); X X initialise(); X X score_frame = window_create(frame, FRAME, X WIN_SHOW, FALSE, X 0); X score_panel = window_create(score_frame, PANEL, X WIN_WIDTH, ATTR_COLS(80), X WIN_HEIGHT, ATTR_ROWS(HIGH_TABLE_SIZE + 1), X 0); X for (i = 0; i < HIGH_TABLE_SIZE + 1; i++) X high_score_item[i] = panel_create_item(score_panel, PANEL_MESSAGE, X PANEL_ITEM_X, ATTR_COL(0), X PANEL_ITEM_Y, ATTR_ROW(i), X PANEL_LABEL_STRING, " ", X 0); X panel_set(high_score_item[0], PANEL_LABEL_BOLD, TRUE, PANEL_LABEL_STRING, "Pos Name Score Rows Lev Machine When", 0); X panel_create_item(score_panel, PANEL_BUTTON, X PANEL_LABEL_IMAGE, panel_button_image(score_panel, "done", 0, 0), X PANEL_NOTIFY_PROC, done_proc, X PANEL_ITEM_X, ATTR_COL(76), X PANEL_ITEM_Y, ATTR_ROW(0), X 0); X window_fit(score_panel); X window_fit(score_frame); X init_timer(); X window_main_loop(frame); X exit(0); X} END_OF_FILE if test 5543 -ne `wc -c <'main.c'`; then echo shar: \"'main.c'\" unpacked with wrong size! fi # end of 'main.c' fi if test -f 'notify.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'notify.c'\" else echo shar: Extracting \"'notify.c'\" \(3552 characters\) sed "s/^X//" >'notify.c' <<'END_OF_FILE' X#include "defs.h" X XNotify_value Xdrop_block(me, which) X Notify_client me; X int which; X{ X X if (block_can_drop(shape_no, xpos, ypos, rot)) X print_shape(shape_no, xpos, ypos++, rot, WHITE); X else { X if (ypos < 0) X end_game(); X else { X score += shape[shape_no].pointv[rot]; X store_shape(shape_no, xpos, ypos, rot); X remove_full_lines(ypos); X create_shape(); X show_score(); X show_next(); X } X } X print_shape(shape_no, xpos, ypos, rot, shape[shape_no].color); X draw_shadow(shape_no, xpos, ypos, rot, shape[shape_no].color); X return (NOTIFY_DONE); X} X Xshow_score() X{ X char buf[BUFSIZ], buf1[BUFSIZ], buf2[BUFSIZ]; X X sprintf(buf, "Score: %d", score); X panel_set(score_item, PANEL_LABEL_STRING, buf, 0); X sprintf(buf1, "Level: %d", rows / 10); X panel_set(level_item, PANEL_LABEL_STRING, buf1, 0); X sprintf(buf2, "Rows : %d", rows); X panel_set(rows_item, PANEL_LABEL_STRING, buf2, 0); X} X Xvoid Xquit_proc() X{ X clear_events(); X stop_timer(); X window_destroy(frame); X} X Xend_game() X{ X end_of_game = 1; X clear_events(); X stop_timer(); X panel_set(game_over, PANEL_SHOW_ITEM, TRUE, 0); X update_highscore_table(); X print_high_scores(); X} X Xvoid Xrestart_proc() X{ X clear_events(); X stop_timer(); X init_all(); X} X Xvoid Xstart_proc() X{ X if (end_of_game) X return; X set_events(); X start_timer(); X} X Xvoid Xpause_proc() X{ X clear_events(); X stop_timer(); X} X Xleft_proc() X{ X if (block_can_left(shape_no, xpos, ypos, rot)) { X print_shape(shape_no, xpos, ypos, rot, WHITE); X xpos--; X print_shape(shape_no, xpos, ypos, rot, shape[shape_no].color); X draw_shadow(shape_no, xpos, ypos, rot, shape[shape_no].color); X } X} X Xright_proc() X{ X if (block_can_right(shape_no, xpos, ypos, rot)) { X print_shape(shape_no, xpos, ypos, rot, WHITE); X xpos++; X print_shape(shape_no, xpos, ypos, rot, shape[shape_no].color); X draw_shadow(shape_no, xpos, ypos, rot, shape[shape_no].color); X } X} X Xanti_proc() X{ X int newrot; X X newrot = (rot + 3) % 4; X if (check_rot(shape_no, xpos, ypos, newrot)) { X print_shape(shape_no, xpos, ypos, rot, WHITE); X rot = newrot; X print_shape(shape_no, xpos, ypos, rot, shape[shape_no].color); X draw_shadow(shape_no, xpos, ypos, rot, shape[shape_no].color); X } X} X Xclock_proc() X{ X int newrot; X X newrot = (rot + 1) % 4; X if (check_rot(shape_no, xpos, ypos, newrot)) { X print_shape(shape_no, xpos, ypos, rot, WHITE); X rot = newrot; X print_shape(shape_no, xpos, ypos, rot, shape[shape_no].color); X draw_shadow(shape_no, xpos, ypos, rot, shape[shape_no].color); X } X} X Xfast_proc() X{ X while (block_can_drop(shape_no, xpos, ypos, rot)) { X print_shape(shape_no, xpos, ypos, rot, WHITE); X ypos++; X print_shape(shape_no, xpos, ypos, rot, shape[shape_no].color); X } X} X Xvoid Xdone_proc() X{ X window_set(score_frame, WIN_SHOW, FALSE, 0); X} END_OF_FILE if test 3552 -ne `wc -c <'notify.c'`; then echo shar: \"'notify.c'\" unpacked with wrong size! fi # end of 'notify.c' fi if test -f 'score.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'score.c'\" else echo shar: Extracting \"'score.c'\" \(5207 characters\) sed "s/^X//" >'score.c' <<'END_OF_FILE' X#include "defs.h" X Xupdate_highscore_table() X{ X int i, j; X long when; X extern char *ctime(); X extern long time(); X char hostname[20]; X char buf[BUFSIZ]; X X /* re-read high-score table in case someone else on the network is X * playing at the same time */ X read_high_scores(); X X /* Next line finds score greater than current one */ X for (i = 0; ((i < HIGH_TABLE_SIZE) && (score >= high_scores[i].score)); i++); X i--; X score_position = i; X if (i >= 0) { X for (j = 0; j < i; j++) X high_scores[j] = high_scores[j + 1]; X strcpy(high_scores[i].name, name); X high_scores[i].score = score; X high_scores[i].rows = rows; X high_scores[i].level = rows / 10; X if (gethostname(hostname, BUFSIZ) == -1) X strcpy(high_scores[i].hostname, "unknown-host"); X else X strcpy(high_scores[i].hostname, hostname); X time(&when); X strcpy(buf, ctime(&when)); /* ctime() adds a newline X * char */ X strip_eoln(buf);/* so remove it */ X strcpy(high_scores[i].date, buf); X write_high_scores(); X } X} X Xread_high_scores() X{ X FILE *fp; X int i; X char *c, buf[BUFSIZ]; X X for (i = 0; i < HIGH_TABLE_SIZE; i++) { X strcpy(high_scores[i].name, " "); X high_scores[i].score = 0; X high_scores[i].rows = 0; X high_scores[i].level = 0; X strcpy(high_scores[i].hostname, " "); X strcpy(high_scores[i].date, " "); X } X if ((fp = fopen(HIGH_SCORE_TABLE, "r")) == NULL) { X fprintf(stderr, "tetris: No High score file\n"); X return; X } X for (i = 0; i < HIGH_TABLE_SIZE; i++) { X fgets(buf, BUFSIZ, fp); X strip_eoln(buf); X strcpy(high_scores[i].name, buf); X fgets(buf, BUFSIZ, fp); X strip_eoln(buf); X high_scores[i].score = atoi(buf); X fgets(buf, BUFSIZ, fp); X strip_eoln(buf); X high_scores[i].rows = atoi(buf); X fgets(buf, BUFSIZ, fp); X strip_eoln(buf); X high_scores[i].level = atoi(buf); X fgets(buf, BUFSIZ, fp); X strip_eoln(buf); X strcpy(high_scores[i].hostname, buf); X fgets(buf, BUFSIZ, fp); X strip_eoln(buf); X strcpy(high_scores[i].date, buf); X } X fclose(fp); X} X Xstrip_eoln(s) X char *s; X{ X char *s1; X X while (*s != '\0') { X if (*s == '\n') { /* End of line char */ X s1 = s; X do { X *s1 = *(s1 + 1); /* Copy rest of string */ X s1++; X } while (*s1 != '\0'); X } else X s++; X } X} X Xwrite_high_scores() X{ X FILE *fp; X int i; X X if ((fp = fopen(HIGH_SCORE_TABLE, "w")) == NULL) { X fprintf(stderr, "tetris: Couldn't open high score file %s\n", HIGH_SCORE_TABLE); X return; X } X for (i = 0; i < HIGH_TABLE_SIZE; i++) X fprintf(fp, "%s\n%d\n%d\n%d\n%s\n%s\n", X high_scores[i].name, X high_scores[i].score, X high_scores[i].rows, X high_scores[i].level, X high_scores[i].hostname, X high_scores[i].date); X fclose(fp); X} X Xvoid Xprint_high_scores() X{ X int i; X char buf[BUFSIZ]; X X /* re-read high-score table in case someone else on the network is X * playing at the same time */ X read_high_scores(); X X for (i = HIGH_TABLE_SIZE - 1; i >= 0; i--) { X sprintf(buf, "%3d) %-15s %6d %5d %3d %-10s %s\n", X HIGH_TABLE_SIZE - i, X high_scores[i].name, X high_scores[i].score, X high_scores[i].rows, X high_scores[i].level, X high_scores[i].hostname, X high_scores[i].date); X panel_set(high_score_item[HIGH_TABLE_SIZE - i], PANEL_LABEL_BOLD, FALSE, PANEL_LABEL_STRING, buf, 0); X } X if (score_position != -1) X panel_set(high_score_item[HIGH_TABLE_SIZE - score_position], PANEL_LABEL_BOLD, TRUE, 0); X window_set(score_frame, WIN_SHOW, TRUE, 0); X} X Xprint_authors() X{ X printf("This version of tetris was written by Phill Everson <everson@cs.bris.ac.uk>\nand Martyn Shortley <shortley@cs.bris.ac.uk>, "); X printf("Based on the version posted\nto comp.sources.games by Adam Marguilies <vespa@ssyx.ucsc.edu>\n\nLet us know if you like it.\n31st March 1989 \n"); X} END_OF_FILE if test 5207 -ne `wc -c <'score.c'`; then echo shar: \"'score.c'\" unpacked with wrong size! fi # end of 'score.c' fi if test -f 'shape.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'shape.c'\" else echo shar: Extracting \"'shape.c'\" \(7330 characters\) sed "s/^X//" >'shape.c' <<'END_OF_FILE' X#include "defs.h" X Xvoid define_shapes() X{ X X /* begin shape 0 definition, four rotations */ X X shape[0].table[0][0] = 0; X shape[0].table[1][0] = 15; /* #### */ X shape[0].table[2][0] = 0; X shape[0].table[3][0] = 0; X shape[0].pointv[0] = 5; X X shape[0].table[0][1] = 4; /* # */ X shape[0].table[1][1] = 4; /* # */ X shape[0].table[2][1] = 4; /* # */ X shape[0].table[3][1] = 4; /* # */ X shape[0].pointv[1] = 8; X X shape[0].table[0][2] = 0; X shape[0].table[1][2] = 15; /* #### */ X shape[0].table[2][2] = 0; X shape[0].table[3][2] = 0; X shape[0].pointv[2] = 5; X X shape[0].table[0][3] = 4; /* # */ X shape[0].table[1][3] = 4; /* # */ X shape[0].table[2][3] = 4; /* # */ X shape[0].table[3][3] = 4; /* # */ X shape[0].pointv[2] = 8; X X shape[0].width = 4; X shape[0].height = 1; X shape[0].offset = 153; X shape[0].color = RED; X X /* begin shape 1 definition, four rotations */ X X shape[1].table[0][0] = 12; /* ## */ X shape[1].table[1][0] = 12; /* ## */ X shape[1].table[2][0] = 0; /* */ X shape[1].table[3][0] = 0; /* */ X shape[1].pointv[0] = 6; X X shape[1].table[0][1] = 12; /* ## */ X shape[1].table[1][1] = 12; /* ## */ X shape[1].table[2][1] = 0; /* */ X shape[1].table[3][1] = 0; /* */ X shape[1].pointv[1] = 6; X X shape[1].table[0][2] = 12; /* ## */ X shape[1].table[1][2] = 12; /* ## */ X shape[1].table[2][2] = 0; /* */ X shape[1].table[3][2] = 0; /* */ X shape[1].pointv[2] = 6; X X shape[1].table[0][3] = 12; /* ## */ X shape[1].table[1][3] = 12; /* ## */ X shape[1].table[2][3] = 0; /* */ X shape[1].table[3][3] = 0; /* */ X shape[1].pointv[3] = 6; X X shape[1].width = 2; X shape[1].height = 2; X shape[1].offset = 0; X shape[1].color = ORANGE; X X /* begin shape 2 definition, four rotations */ X X shape[2].table[0][0] = 4; /* # */ X shape[2].table[1][0] = 14; /* ### */ X shape[2].table[2][0] = 0; /* */ X shape[2].table[3][0] = 0; /* */ X shape[2].pointv[0] = 5; X X shape[2].table[0][1] = 4; /* # */ X shape[2].table[1][1] = 6; /* ## */ X shape[2].table[2][1] = 4; /* # */ X shape[2].table[3][1] = 0; /* */ X shape[2].pointv[0] = 5; X X shape[2].table[0][2] = 0; /* */ X shape[2].table[1][2] = 14; /* ### */ X shape[2].table[2][2] = 4; /* # */ X shape[2].table[3][2] = 0; /* */ X shape[2].pointv[2] = 6; X X shape[2].table[0][3] = 4; /* # */ X shape[2].table[1][3] = 12; /* ## */ X shape[2].table[2][3] = 4; /* # */ X shape[2].table[3][3] = 0; /* */ X shape[2].pointv[3] = 5; X X shape[2].width = 3; X shape[2].height = 2; X shape[2].offset = 24; X shape[2].color = YELLOW; X X /* begin shape 3 definition, four rotations */ X X shape[3].table[0][0] = 12; /* ## */ X shape[3].table[1][0] = 6; /* ## */ X shape[3].table[2][0] = 0; /* */ X shape[3].table[3][0] = 0; /* */ X shape[3].pointv[0] = 6; X X shape[3].table[0][1] = 4; /* # */ X shape[3].table[1][1] = 12; /* ## */ X shape[3].table[2][1] = 8; /* # */ X shape[3].table[3][1] = 0; /* */ X shape[3].pointv[1] = 7; X X shape[3].table[0][2] = 12; /* ## */ X shape[3].table[1][2] = 6; /* ## */ X shape[3].table[2][2] = 0; /* */ X shape[3].table[3][2] = 0; /* */ X shape[3].pointv[2] = 6; X X shape[3].table[0][3] = 4; /* # */ X shape[3].table[1][3] = 12; /* ## */ X shape[3].table[2][3] = 8; /* # */ X shape[3].table[3][3] = 0; /* */ X shape[3].pointv[3] = 7; X X shape[3].width = 3; X shape[3].height = 2; X shape[3].offset = 0; X shape[3].color = GREEN; X X /* begin shape 4 definition, four rotations */ X X shape[4].table[0][0] = 6; /* ## */ X shape[4].table[1][0] = 12; /* ## */ X shape[4].table[2][0] = 0; /* */ X shape[4].table[3][0] = 0; /* */ X shape[4].pointv[0] = 6; X X shape[4].table[0][1] = 8; /* # */ X shape[4].table[1][1] = 12; /* ## */ X shape[4].table[2][1] = 4; /* # */ X shape[4].table[3][1] = 0; /* */ X shape[4].pointv[1] = 7; X X shape[4].table[0][2] = 6; /* ## */ X shape[4].table[1][2] = 12; /* ## */ X shape[4].table[2][2] = 0; /* */ X shape[4].table[3][2] = 0; /* */ X shape[4].pointv[2] = 6; X X shape[4].table[0][3] = 8; /* # */ X shape[4].table[1][3] = 12; /* ## */ X shape[4].table[2][3] = 4; /* # */ X shape[4].table[3][3] = 0; /* */ X shape[4].pointv[3] = 7; X X shape[4].width = 3; X shape[4].height = 2; X shape[4].offset = 0; X shape[4].color = BLUE; X X /* begin shape 5 definition, four rotations */ X X shape[5].table[0][0] = 2; /* # */ X shape[5].table[1][0] = 14; /* ### */ X shape[5].table[2][0] = 0; /* */ X shape[5].table[3][0] = 0; /* */ X shape[5].pointv[0] = 6; X X shape[5].table[0][1] = 8; /* # */ X shape[5].table[1][1] = 8; /* # */ X shape[5].table[2][1] = 12; /* ## */ X shape[5].table[3][1] = 0; /* */ X shape[5].pointv[1] = 7; X X shape[5].table[0][2] = 14; /* ### */ X shape[5].table[1][2] = 8; /* # */ X shape[5].table[2][2] = 0; /* */ X shape[5].table[3][2] = 0; /* */ X shape[5].pointv[2] = 6; X X shape[5].table[0][3] = 12; /* ## */ X shape[5].table[1][3] = 4; /* # */ X shape[5].table[2][3] = 4; /* # */ X shape[5].table[3][3] = 0; /* */ X shape[5].pointv[3] = 7; X X shape[5].width = 3; X shape[5].height = 2; X shape[5].offset = 0; X shape[5].color = CYAN; X X /* begin shape 6 definition, four rotations */ X X shape[6].table[0][0] = 14; /* ### */ X shape[6].table[1][0] = 2; /* # */ X shape[6].table[2][0] = 0; /* */ X shape[6].table[3][0] = 0; /* */ X shape[6].pointv[0] = 6; X X shape[6].table[0][1] = 4; /* # */ X shape[6].table[1][1] = 4; /* # */ X shape[6].table[2][1] = 12; /* ## */ X shape[6].table[3][1] = 0; /* */ X shape[6].pointv[1] = 7; X X shape[6].table[0][2] = 8; /* # */ X shape[6].table[1][2] = 14; /* ### */ X shape[6].table[2][2] = 0; /* */ X shape[6].table[3][2] = 0; /* */ X shape[6].pointv[2] = 6; X X shape[6].table[0][3] = 12; /* ## */ X shape[6].table[1][3] = 8; /* # */ X shape[6].table[2][3] = 8; /* # */ X shape[6].table[3][3] = 0; /* */ X shape[6].pointv[3] = 7; X X shape[6].width = 3; X shape[6].height = 2; X shape[6].offset = 0; X shape[6].color = VIOLET; X} X Xstore_shape(shape_no, xpos, ypos, rot) X int shape_no, xpos, ypos, rot; X{ X int i; X X for (i = 0; i < 4; i++) { X if (shape[shape_no].table[i][rot] & 8) X grid[xpos][ypos + i] = 1; X if (shape[shape_no].table[i][rot] & 4) X grid[xpos + 1][ypos + i] = 1; X if (shape[shape_no].table[i][rot] & 2) X grid[xpos + 2][ypos + i] = 1; X if (shape[shape_no].table[i][rot] & 1) X grid[xpos + 3][ypos + i] = 1; X } X} X Xcreate_shape() X{ X shape_no = next_no; X rot = next_rot; X next_no = rand() % 7; X next_rot = rand() % 4; X xpos = (UWIDTH / 2) - 1; X ypos = -4; X} X END_OF_FILE if test 7330 -ne `wc -c <'shape.c'`; then echo shar: \"'shape.c'\" unpacked with wrong size! fi # end of 'shape.c' fi if test -f 'support.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'support.c'\" else echo shar: Extracting \"'support.c'\" \(7000 characters\) sed "s/^X//" >'support.c' <<'END_OF_FILE' X#include "defs.h" X Xblock_can_drop(shape_no, xpos, ypos, rot) X int shape_no, xpos, ypos, rot; X{ X int y1, c; X X c = 3; X X while ((c >= 0) && ((shape[shape_no].table[c][rot] & 8) == 0)) X c--; X y1 = ypos + c + 1; X if ((c != -1) && (y1 >= 0)) X if ((y1 == UHEIGHT) || (grid[xpos][y1] != 0)) X return (FALSE); X X c = 3; X while ((c >= 0) && ((shape[shape_no].table[c][rot] & 4) == 0)) X c--; X y1 = ypos + c + 1; X if ((c != -1) && (y1 >= 0)) X if ((y1 == UHEIGHT) || (grid[xpos + 1][y1] != 0)) X return (FALSE); X X c = 3; X while ((c >= 0) && ((shape[shape_no].table[c][rot] & 2) == 0)) X c--; X y1 = ypos + c + 1; X if ((c != -1) && (y1 >= 0)) X if ((y1 == UHEIGHT) || (grid[xpos + 2][y1] != 0)) X return (FALSE); X X c = 3; X while ((c >= 0) && ((shape[shape_no].table[c][rot] & 1) == 0)) X c--; X y1 = ypos + c + 1; X if ((c != -1) && (y1 >= 0)) X if ((y1 == UHEIGHT) || (grid[xpos + 3][y1] != 0)) X return (FALSE); X X return TRUE; X} X Xblock_can_left(shape_no, xpos, ypos, rot) X int shape_no, xpos, ypos, rot; X{ X int x1, c; X int y0, y1, y2, y3; X int t0, t1, t2, t3; X X t0 = shape[shape_no].table[0][rot]; /* Bit map of 1st Row */ X t1 = shape[shape_no].table[1][rot]; /* Bit map of 2nd Row */ X t2 = shape[shape_no].table[2][rot]; /* Bit map of 3rd Row */ X t3 = shape[shape_no].table[3][rot]; /* Bit map of 4th Row */ X X y0 = ypos; X y1 = ypos + 1; X y2 = ypos + 2; X y3 = ypos + 3; X X c = 3; X while ((c >= 0) && ((t0 & (1 << c)) == 0)) X c--; X x1 = xpos - 1 + (3 - c); X if (c != -1) X if ((x1 < 0) || ((y0 >= 0) && (grid[x1][y0] != 0))) X return (FALSE); X X c = 3; X while ((c >= 0) && ((t1 & (1 << c)) == 0)) X c--; X x1 = xpos - 1 + (3 - c); X if (c != -1) X if ((x1 < 0) || ((y1 >= 0) && (grid[x1][y1] != 0))) X return (FALSE); X X c = 3; X while ((c >= 0) && ((t2 & (1 << c)) == 0)) X c--; X x1 = xpos - 1 + (3 - c); X if (c != -1) X if ((x1 < 0) || ((y2 >= 0) && (grid[x1][y2] != 0))) X return (FALSE); X X c = 3; X while ((c >= 0) && ((t3 & (1 << c)) == 0)) X c--; X x1 = xpos - 1 + (3 - c); X if (c != -1) X if ((x1 < 0) || ((y3 >= 0) && (grid[x1][y3] != 0))) X return (FALSE); X X return TRUE; X} X Xblock_can_right(shape_no, xpos, ypos, rot) X int shape_no, xpos, ypos, rot; X{ X int x1, c; X int y0, y1, y2, y3; X int t0, t1, t2, t3; X X t0 = shape[shape_no].table[0][rot]; /* Bit map of 1st Row */ X t1 = shape[shape_no].table[1][rot]; /* Bit map of 2nd Row */ X t2 = shape[shape_no].table[2][rot]; /* Bit map of 3rd Row */ X t3 = shape[shape_no].table[3][rot]; /* Bit map of 4th Row */ X X y0 = ypos; X y1 = ypos + 1; X y2 = ypos + 2; X y3 = ypos + 3; X X c = 0; X while ((c < 4) && ((t0 & (1 << c)) == 0)) X c++; X x1 = xpos + 1 + (3 - c); X if ((c != 4) && (x1 >= 0)) X if ((x1 == UWIDTH) || ((y0 >= 0) && (grid[x1][y0] != 0))) X return (FALSE); X X c = 0; X while ((c < 4) && ((t1 & (1 << c)) == 0)) X c++; X x1 = xpos + 1 + (3 - c); X if ((c != 4) && (x1 >= 0)) X if ((x1 == UWIDTH) || ((y1 >= 0) && (grid[x1][y1] != 0))) X return (FALSE); X X c = 0; X while ((c < 4) && ((t2 & (1 << c)) == 0)) X c++; X x1 = xpos + 1 + (3 - c); X if ((c != 4) && (x1 >= 0)) X if ((x1 == UWIDTH) || ((y2 >= 0) && (grid[x1][y2] != 0))) X return (FALSE); X X c = 0; X while ((c < 4) && ((t3 & (1 << c)) == 0)) X c++; X x1 = xpos + 1 + (3 - c); X if ((c != 4) && (x1 >= 0)) X if ((x1 == UWIDTH) || ((y3 >= 0) && (grid[x1][y3] != 0))) X return (FALSE); X X return TRUE; X} X Xremove_full_lines(y) X int y; X{ X int y1, y2, full_flag, x; X int xsize, ysize; X X xsize = UNIT * UWIDTH; X pw_batch_on(pw); X for (y1 = y; y1 < y + 4 && y1 < UHEIGHT; y1++) { X full_flag = TRUE; X for (x = 0; x < UWIDTH; x++) X if (grid[x][y1] == 0) { X full_flag = FALSE; X break; X } X if (full_flag) { X ysize = y1 * UNIT; X for (y2 = y1; y2 > 0; y2--) X for (x = 0; x < UWIDTH; x++) X grid[x][y2] = grid[x][y2 - 1]; X for (x = 0; x < UWIDTH; x++) X grid[x][0] = 0; X pr_rop(pr, 0, 0, xsize, ysize, PIX_SRC, pw->pw_prretained, 0, 0); X pw_rop(pw, 0, UNIT, xsize, ysize, PIX_SRC, NULL, 0, 0); X pw_rop(pw, 0, UNIT, xsize, ysize, PIX_SRC, pr, 0, 0); X pw_rop(pw, 0, 0, xsize, UNIT, CLR, NULL, 0, 0); X rows++; X } X } X pw_batch_off(pw); X} X Xcheck_rot(shape_no, xpos, ypos, newrot) X int shape_no, xpos, ypos, newrot; X{ X int i; X int ti; /* Bit map of i'th row */ X int yi; /* Y position on i'th row */ X int x0, x1, x2, x3; X X x0 = xpos; X x1 = xpos + 1; X x2 = xpos + 2; X x3 = xpos + 3; X yi = ypos; X X for (i = 0; i < 4; yi++, i++) { X if ((yi) >= 0) { X ti = shape[shape_no].table[i][newrot]; X if (ti & 8) X if ((x0 < 0) || (x0 >= UWIDTH) || (grid[x0][yi] == 1)) X return FALSE; X if (ti & 4) X if ((x1 < 0) || (x1 >= UWIDTH) || (grid[x1][yi] == 1)) X return FALSE; X if (ti & 2) X if ((x2 < 0) || (x2 >= UWIDTH) || (grid[x2][yi] == 1)) X return FALSE; X if (ti & 1) X if ((x3 < 0) || (x3 >= UWIDTH) || (grid[x3][yi] == 1)) X return FALSE; X } X } X return TRUE; X} END_OF_FILE if test 7000 -ne `wc -c <'support.c'`; then echo shar: \"'support.c'\" unpacked with wrong size! fi # end of 'support.c' fi if test -f 'tetris.6' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'tetris.6'\" else echo shar: Extracting \"'tetris.6'\" \(1579 characters\) sed "s/^X//" >'tetris.6' <<'END_OF_FILE' X.TH TETRIS 6 "31st March 1989" X.SH NAME Xtetris \- SunView block dropping game X.SH SYNOPSIS X.B tetris X[ X.B "Sunview options" X] X.SH DESCRIPTION X.I Tetris Xis a game involving dropping blocks. As they drop you can move them to Xthe left or to the right by clicking the left or right mouse buttons Xrespectively. Pressing the shift key while clicking the button causes Xthe falling shape to rotate anti-clockwise (left mouse button) or Xclockwise (right mouse button). Pressing the middle mouse button causes Xthe shape to quickly drop. Note that the mouse must be in the window in Xwhich the shapes are dropping for these actions to work correctly. X.PP XPoints are scored for each block that comes to rest on the gradually Xbuilding up pile of blocks. Different blocks in different orientations Xhave different point values. When the pile reaches the top of the Xscreen and no further blocks can be dropped the game ends. Whenever a Xfull row of blocks across the screen is all completely filled in that Xrow is removed and all the blocks above it drop down a further row. XAs more rows are deleted the blocks drop faster. X.PP XA high score table is kept which is retained between separate executions Xof the game. X.PP XIt looks better when run on a colour machine. X.SH OPTIONS X.I Tetris Xtakes standard X.I Sunview Xoptions. (see X.I suntools (1) X) X.SH FILES X.IP /usr/games/lib/tetris_scores XTop 10 high scores. X.SH "ENVIRONMENT VARIABLES" X.IP TETRIS XIf set, your desired name for the high score table. X.SH "SEE ALSO" X.BI suntools (1) X.SH "BUGS" XThe first rotation/fast-drop event in each game fails. END_OF_FILE if test 1579 -ne `wc -c <'tetris.6'`; then echo shar: \"'tetris.6'\" unpacked with wrong size! fi # end of 'tetris.6' fi if test -f 'tetris.icon' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'tetris.icon'\" else echo shar: Extracting \"'tetris.icon'\" \(1933 characters\) sed "s/^X//" >'tetris.icon' <<'END_OF_FILE' X/* Format_version=1, Width=64, Height=64, Depth=1, Valid_bits_per_item=16 X */ X 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0x8000,0x0000,0x0000,0x0001, X 0x8000,0x0000,0x0000,0x0001,0x8000,0x0000,0x0000,0x0001, X 0x8008,0x0000,0x0000,0x1001,0x8008,0x0000,0x0000,0x1001, X 0x8008,0x0000,0x0000,0x1001,0x8008,0x0000,0x0000,0x1001, X 0x8008,0x0007,0x7000,0x1001,0x8008,0x000D,0xD000,0x1001, X 0x8008,0x000B,0xB000,0x1001,0x8008,0x000E,0xE000,0x1001, X 0x8008,0x0007,0x7000,0x1001,0x8008,0x000D,0xD000,0x1001, X 0x8008,0x000B,0xB000,0x1001,0x8008,0x000E,0xE000,0x1001, X 0x8008,0x8887,0x7AAA,0xB001,0x8008,0x888D,0xD555,0x5001, X 0x800A,0x222B,0xBAAA,0xB001,0x800A,0x222E,0xE555,0x5001, X 0x8008,0x8887,0x7AAA,0xB001,0x8008,0x888D,0xD555,0x5001, X 0x800A,0x222B,0xBAAA,0xB001,0x800A,0x222E,0xE555,0x5001, X 0x8008,0x8007,0x7AA8,0x9001,0x8008,0x800D,0xD552,0x3001, X 0x800A,0x200B,0xBAA4,0x5001,0x800A,0x200E,0xE551,0x1001, X 0x8008,0x8007,0x7AA8,0x9001,0x8008,0x800D,0xD552,0x3001, X 0x800A,0x200B,0xBAA4,0x5001,0x800A,0x200E,0xE551,0x1001, X 0x8008,0x8FF7,0x7AA8,0x9001,0x8008,0x8FFD,0xD552,0x3001, X 0x800A,0x2FFB,0xBAA4,0x5001,0x800A,0x2FFE,0xE551,0x1001, X 0x8008,0x8FF7,0x7AA8,0x9001,0x8008,0x8FFD,0xD552,0x3001, X 0x800A,0x2FFB,0xBAA4,0x5001,0x800A,0x2FFE,0xE551,0x1001, X 0x800F,0xFFFF,0xF888,0x9001,0x800F,0xFFFF,0xF222,0x3001, X 0x800F,0xFFFF,0xF444,0x5001,0x800F,0xFFFF,0xF111,0x1001, X 0x800F,0xFFFF,0xF888,0x9001,0x800F,0xFFFF,0xF222,0x3001, X 0x800F,0xFFFF,0xF444,0x5001,0x800F,0xFFFF,0xFFFF,0xF001, X 0x8000,0x0000,0x0000,0x0001,0x8000,0x0000,0x0000,0x0001, X 0x8000,0x0000,0x0000,0x0001,0x807E,0x0018,0x0018,0x0001, X 0x8018,0x0018,0x0000,0x0001,0x8018,0x3C7E,0x6C78,0x3C01, X 0x8018,0x6618,0x7618,0x6601,0x8018,0x6618,0x6018,0x6001, X 0x8018,0x7E18,0x6018,0x3C01,0x8018,0x6018,0x6018,0x0601, X 0x8018,0x661A,0x6018,0x6601,0x8018,0x3C0C,0x6018,0x3C01, X 0x8000,0x0000,0x0000,0x0001,0x8000,0x0000,0x0000,0x0001, X 0x8000,0x0000,0x0000,0x0001,0xFFFF,0xFFFF,0xFFFF,0xFFFF END_OF_FILE if test 1933 -ne `wc -c <'tetris.icon'`; then echo shar: \"'tetris.icon'\" unpacked with wrong size! fi # end of 'tetris.icon' fi if test -f 'window.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'window.c'\" else echo shar: Extracting \"'window.c'\" \(931 characters\) sed "s/^X//" >'window.c' <<'END_OF_FILE' X#include "defs.h" X#include <sys/types.h> X#include <sys/timeb.h> X Xinit_timer() X{ X me = (Notify_client *) & my_client_object; X} X Xstart_timer() X{ X struct itimerval drop_time; X int level; X X level = 50 - (rows / 10); X if (level < 0) X level = 0; X drop_time.it_interval.tv_usec = 100000 + level * 2000; X drop_time.it_interval.tv_sec = 0; X X drop_time.it_value.tv_usec = 10; X drop_time.it_value.tv_sec = 0; X X notify_set_itimer_func(me, drop_block, ITIMER_REAL, &drop_time, ITIMER_NULL); X} X Xstop_timer() X{ X notify_set_itimer_func(me, drop_block, ITIMER_REAL, ITIMER_NULL, ITIMER_NULL); X} X Xset_events() X{ X window_set(canvas, WIN_CONSUME_PICK_EVENTS, X WIN_NO_EVENTS, WIN_MOUSE_BUTTONS, WIN_ASCII_EVENTS, 0, 0); X} X Xclear_events() X{ X window_set(canvas, WIN_CONSUME_PICK_EVENT, X WIN_NO_EVENTS, 0); X} END_OF_FILE if test 931 -ne `wc -c <'window.c'`; then echo shar: \"'window.c'\" unpacked with wrong size! fi # end of 'window.c' fi echo shar: End of archive 1 \(of 1\). cp /dev/null ark1isdone MISSING="" for I in 1 ; do if test ! -f ark${I}isdone ; then MISSING="${MISSING} ${I}" fi done if test "${MISSING}" = "" ; then echo You have the archive. 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