home *** CD-ROM | disk | FTP | other *** search
- Path: uunet!island!argv
- From: argv@island.uu.net (Dan Heller)
- Newsgroups: comp.sources.x
- Subject: v04i029: xtetris - X version of tetris, Part03/03
- Message-ID: <825@island.uu.net>
- Date: 14 Jun 89 12:16:02 GMT
- Organization: Island Graphics, Marin County, California
- Lines: 397
- Approved: island!argv@sun.com
-
- Submitted-by: Didier Tallot <Tallot@bdblues.altair.fr>
- Posting-number: Volume 4, Issue 29
- Archive-name: xtetris/part03
-
-
-
- #!/bin/sh
- # this is part 3 of a multipart archive
- # do not concatenate these parts, unpack them in order with /bin/sh
- # file support.c continued
- #
- CurArch=3
- if test ! -r s2_seq_.tmp
- then echo "Please unpack part 1 first!"
- exit 1; fi
- ( read Scheck
- if test "$Scheck" != $CurArch
- then echo "Please unpack part $Scheck next!"
- exit 1;
- else exit 0; fi
- ) < s2_seq_.tmp || exit 1
- echo "x - Continuing file support.c"
- sed 's/^X//' << 'SHAR_EOF' >> support.c
- 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 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 /* for blinking the line to remove */
- X XSetFunction(XtDisplay(toplevel), gc, GXclear);
- X XFillRectangle(XtDisplay(toplevel),XtWindow(canvas),gc,
- X 0, ysize, xsize, UNIT);
- X usleep(250000);
- X XFlush(XtDisplay(toplevel));
- X XSetFunction(XtDisplay(toplevel), gc, GXcopy);
- X XFillRectangle(XtDisplay(toplevel),XtWindow(canvas),gc,
- X 0, ysize, xsize, UNIT);
- X usleep(250000);
- X XFlush(XtDisplay(toplevel));
- X XSetFunction(XtDisplay(toplevel), gc, GXclear);
- X XFillRectangle(XtDisplay(toplevel),XtWindow(canvas),gc,
- X 0, ysize, xsize, UNIT);
- X usleep(250000);
- X XFlush(XtDisplay(toplevel));
- X XSetFunction(XtDisplay(toplevel), gc, GXcopy);
- X XCopyArea(XtDisplay(toplevel),
- X XtWindow(canvas),XtWindow(canvas),gc,
- X 0,0,xsize,ysize,0, UNIT);
- X XSetFunction(XtDisplay(toplevel), gc, GXclear);
- X XFillRectangle(XtDisplay(toplevel),XtWindow(canvas),gc,
- X 0, 0, xsize, UNIT);
- X rows++;
- X }
- X }
- X XFlush(XtDisplay(toplevel));
- 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 ((yi >= UHEIGHT) && (ti != 0))
- X return FALSE;
- 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}
- SHAR_EOF
- echo "File support.c is complete"
- chmod 0644 support.c || echo "restore of support.c fails"
- echo "x - extracting tetris.xicon (Text)"
- sed 's/^X//' << 'SHAR_EOF' > tetris.xicon &&
- X#define tetris_width 64
- X#define tetris_height 64
- X#define tetris_x_hot -1
- X#define tetris_y_hot -1
- Xstatic char tetris_bits[] = {
- X 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00,
- X 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
- X 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x10, 0x00, 0x00,
- X 0x00, 0x00, 0x08, 0x80, 0x01, 0x10, 0x00, 0x00, 0x00, 0x00, 0x08, 0x80,
- X 0x01, 0x10, 0x00, 0x00, 0x00, 0x00, 0x08, 0x80, 0x01, 0x10, 0x00, 0x00,
- X 0x00, 0x00, 0x08, 0x80, 0x01, 0x10, 0x00, 0xe0, 0x0e, 0x00, 0x08, 0x80,
- X 0x01, 0x10, 0x00, 0xb0, 0x0b, 0x00, 0x08, 0x80, 0x01, 0x10, 0x00, 0xd0,
- X 0x0d, 0x00, 0x08, 0x80, 0x01, 0x10, 0x00, 0x70, 0x07, 0x00, 0x08, 0x80,
- X 0x01, 0x10, 0x00, 0xe0, 0x0e, 0x00, 0x08, 0x80, 0x01, 0x10, 0x00, 0xb0,
- X 0x0b, 0x00, 0x08, 0x80, 0x01, 0x10, 0x00, 0xd0, 0x0d, 0x00, 0x08, 0x80,
- X 0x01, 0x10, 0x00, 0x70, 0x07, 0x00, 0x08, 0x80, 0x01, 0x10, 0x11, 0xe1,
- X 0x5e, 0x55, 0x0d, 0x80, 0x01, 0x10, 0x11, 0xb1, 0xab, 0xaa, 0x0a, 0x80,
- X 0x01, 0x50, 0x44, 0xd4, 0x5d, 0x55, 0x0d, 0x80, 0x01, 0x50, 0x44, 0x74,
- X 0xa7, 0xaa, 0x0a, 0x80, 0x01, 0x10, 0x11, 0xe1, 0x5e, 0x55, 0x0d, 0x80,
- X 0x01, 0x10, 0x11, 0xb1, 0xab, 0xaa, 0x0a, 0x80, 0x01, 0x50, 0x44, 0xd4,
- X 0x5d, 0x55, 0x0d, 0x80, 0x01, 0x50, 0x44, 0x74, 0xa7, 0xaa, 0x0a, 0x80,
- X 0x01, 0x10, 0x01, 0xe0, 0x5e, 0x15, 0x09, 0x80, 0x01, 0x10, 0x01, 0xb0,
- X 0xab, 0x4a, 0x0c, 0x80, 0x01, 0x50, 0x04, 0xd0, 0x5d, 0x25, 0x0a, 0x80,
- X 0x01, 0x50, 0x04, 0x70, 0xa7, 0x8a, 0x08, 0x80, 0x01, 0x10, 0x01, 0xe0,
- X 0x5e, 0x15, 0x09, 0x80, 0x01, 0x10, 0x01, 0xb0, 0xab, 0x4a, 0x0c, 0x80,
- X 0x01, 0x50, 0x04, 0xd0, 0x5d, 0x25, 0x0a, 0x80, 0x01, 0x50, 0x04, 0x70,
- X 0xa7, 0x8a, 0x08, 0x80, 0x01, 0x10, 0xf1, 0xef, 0x5e, 0x15, 0x09, 0x80,
- X 0x01, 0x10, 0xf1, 0xbf, 0xab, 0x4a, 0x0c, 0x80, 0x01, 0x50, 0xf4, 0xdf,
- X 0x5d, 0x25, 0x0a, 0x80, 0x01, 0x50, 0xf4, 0x7f, 0xa7, 0x8a, 0x08, 0x80,
- X 0x01, 0x10, 0xf1, 0xef, 0x5e, 0x15, 0x09, 0x80, 0x01, 0x10, 0xf1, 0xbf,
- X 0xab, 0x4a, 0x0c, 0x80, 0x01, 0x50, 0xf4, 0xdf, 0x5d, 0x25, 0x0a, 0x80,
- X 0x01, 0x50, 0xf4, 0x7f, 0xa7, 0x8a, 0x08, 0x80, 0x01, 0xf0, 0xff, 0xff,
- X 0x1f, 0x11, 0x09, 0x80, 0x01, 0xf0, 0xff, 0xff, 0x4f, 0x44, 0x0c, 0x80,
- X 0x01, 0xf0, 0xff, 0xff, 0x2f, 0x22, 0x0a, 0x80, 0x01, 0xf0, 0xff, 0xff,
- X 0x8f, 0x88, 0x08, 0x80, 0x01, 0xf0, 0xff, 0xff, 0x1f, 0x11, 0x09, 0x80,
- X 0x01, 0xf0, 0xff, 0xff, 0x4f, 0x44, 0x0c, 0x80, 0x01, 0xf0, 0xff, 0xff,
- X 0x2f, 0x22, 0x0a, 0x80, 0x01, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x80,
- X 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00,
- X 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
- X 0x01, 0x7e, 0x00, 0x18, 0x00, 0x18, 0x00, 0x80, 0x01, 0x18, 0x00, 0x18,
- X 0x00, 0x00, 0x00, 0x80, 0x01, 0x18, 0x3c, 0x7e, 0x36, 0x1e, 0x3c, 0x80,
- X 0x01, 0x18, 0x66, 0x18, 0x6e, 0x18, 0x66, 0x80, 0x01, 0x18, 0x66, 0x18,
- X 0x06, 0x18, 0x06, 0x80, 0x01, 0x18, 0x7e, 0x18, 0x06, 0x18, 0x3c, 0x80,
- X 0x01, 0x18, 0x06, 0x18, 0x06, 0x18, 0x60, 0x80, 0x01, 0x18, 0x66, 0x58,
- X 0x06, 0x18, 0x66, 0x80, 0x01, 0x18, 0x3c, 0x30, 0x06, 0x18, 0x3c, 0x80,
- X 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00,
- X 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
- X 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
- SHAR_EOF
- chmod 0664 tetris.xicon || echo "restore of tetris.xicon fails"
- echo "x - extracting window.c (Text)"
- sed 's/^X//' << 'SHAR_EOF' > window.c &&
- X#include "defs.h"
- X
- Xstatic XtIntervalId timer;
- X
- Xstart_timer()
- X{
- X unsigned long interval;
- X int level;
- X
- X level = 50 - (rows / 10);
- X if (level < 0)
- X level = 0;
- X
- X interval = level * 6;
- X timer = XtAddTimeOut(interval, drop_block, NULL);
- X}
- X
- Xstop_timer()
- X{
- X XtRemoveTimeOut(timer);
- X}
- X
- Xset_events()
- X{
- X XtAddCallback(canvas, XtNselect,canvas_event_proc,NULL);
- X XtAddCallback(canvas, XtNrelease,canvas_event_proc,NULL);
- X XtAddCallback(canvas, XtNkeyDown,canvas_event_proc,NULL);
- X}
- X
- Xclear_events()
- X{
- X XtRemoveCallback(canvas, XtNselect,canvas_event_proc,NULL);
- X XtRemoveCallback(canvas, XtNrelease,canvas_event_proc,NULL);
- X XtRemoveCallback(canvas, XtNkeyDown,canvas_event_proc,NULL);
- X}
- X
- Xvoid
- Xrestore_canvas(w, client_data, call_data)
- X Widget w;
- X caddr_t client_data;
- X caddr_t call_data;
- X{
- X int x, y;
- X
- X XSetFunction(XtDisplay(toplevel), gc, GXclear);
- X XFillRectangle(XtDisplay(toplevel), XtWindow(canvas), gc,
- X 0, 0, UNIT * UWIDTH, UNIT * UHEIGHT);
- X XSetFunction(XtDisplay(toplevel), gc, GXcopy);
- X XSetLineAttributes(XtDisplay(toplevel), gc,
- X 1, LineSolid, CapButt, JoinMiter);
- X XDrawLine(XtDisplay(toplevel), XtWindow(canvas), gc,
- X 0, UHEIGHT * UNIT, UWIDTH * UNIT, UHEIGHT * UNIT);
- X XDrawLine(XtDisplay(toplevel), XtWindow(canvas), gc,
- X 0, UHEIGHT * UNIT + SHADOW_HEIGHT,
- X UWIDTH * UNIT, UHEIGHT * UNIT + SHADOW_HEIGHT);
- X XDrawLine(XtDisplay(toplevel), XtWindow(canvas), gc,
- X UWIDTH * UNIT, 0,
- X UWIDTH * UNIT, UHEIGHT * UNIT + SHADOW_HEIGHT + NEXT_HEIGHT);
- X for(x=0; x<UWIDTH; x++)
- X for(y=0; y<UHEIGHT; y++)
- X if (grid[x][y] == 1) {
- X XFillRectangle(XtDisplay(toplevel),XtWindow(canvas),gc,
- X x * UNIT, y * UNIT, UNIT, UNIT);
- X XSetFillStyle(XtDisplay(toplevel), gc, FillTiled);
- X XFillRectangle(XtDisplay(toplevel),XtWindow(canvas),gc,
- X (x * UNIT)+1, (y * UNIT)+1, UNIT-2, UNIT-2);
- X XSetFillStyle(XtDisplay(toplevel), gc, FillSolid);
- X }
- X
- X XFlush(XtDisplay(toplevel));
- 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 show_next();
- X}
- SHAR_EOF
- chmod 0644 window.c || echo "restore of window.c fails"
- echo "x - extracting xtetris.6 (Text)"
- sed 's/^X//' << 'SHAR_EOF' > xtetris.6 &&
- X.TH XTETRIS 6 "11st May 1989"
- X.SH NAME
- Xxtetris \- X Window block dropping game
- X.SH SYNOPSIS
- X.B xtetris
- X[
- X.B "X options"
- X]
- X.SH DESCRIPTION
- X.I Xtetris
- 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
- XYou can also use the keyboard: j for moving to the left, l for moving to
- Xthe right, k to rotate anti-clockwise and space for dropping quickly..
- 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.SH OPTIONS
- X.I Xtetris
- Xtakes standard
- X.I X
- Xoptions. (see
- X.I X (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 X (1)
- SHAR_EOF
- chmod 0644 xtetris.6 || echo "restore of xtetris.6 fails"
- rm -f s2_seq_.tmp
- echo "You have unpacked the last part"
- exit 0
-