home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume4 / xtetris / part03 < prev    next >
Encoding:
Internet Message Format  |  1989-06-15  |  15.3 KB

  1. Path: uunet!island!argv
  2. From: argv@island.uu.net (Dan Heller)
  3. Newsgroups: comp.sources.x
  4. Subject: v04i029: xtetris - X version of tetris, Part03/03
  5. Message-ID: <825@island.uu.net>
  6. Date: 14 Jun 89 12:16:02 GMT
  7. Organization: Island Graphics, Marin County, California
  8. Lines: 397
  9. Approved: island!argv@sun.com
  10.  
  11. Submitted-by: Didier Tallot <Tallot@bdblues.altair.fr>
  12. Posting-number: Volume 4, Issue 29
  13. Archive-name: xtetris/part03
  14.  
  15.  
  16.  
  17. #!/bin/sh
  18. # this is part 3 of a multipart archive
  19. # do not concatenate these parts, unpack them in order with /bin/sh
  20. # file support.c continued
  21. #
  22. CurArch=3
  23. if test ! -r s2_seq_.tmp
  24. then echo "Please unpack part 1 first!"
  25.      exit 1; fi
  26. ( read Scheck
  27.   if test "$Scheck" != $CurArch
  28.   then echo "Please unpack part $Scheck next!"
  29.        exit 1;
  30.   else exit 0; fi
  31. ) < s2_seq_.tmp || exit 1
  32. echo "x - Continuing file support.c"
  33. sed 's/^X//' << 'SHAR_EOF' >> support.c
  34. X        int     shape_no, xpos, ypos, rot;
  35. X{
  36. X        int     x1, c;
  37. X        int     y0, y1, y2, y3;
  38. X        int     t0, t1, t2, t3;
  39. X
  40. X        t0 = shape[shape_no].table[0][rot];     /* Bit map of 1st Row */
  41. X        t1 = shape[shape_no].table[1][rot];     /* Bit map of 2nd Row */
  42. X        t2 = shape[shape_no].table[2][rot];     /* Bit map of 3rd Row */
  43. X        t3 = shape[shape_no].table[3][rot];     /* Bit map of 4th Row */
  44. X
  45. X        y0 = ypos;
  46. X        y1 = ypos + 1;
  47. X        y2 = ypos + 2;
  48. X        y3 = ypos + 3;
  49. X
  50. X        c = 3;
  51. X        while ((c >= 0) && ((t0 & (1 << c)) == 0))
  52. X                c--;
  53. X        x1 = xpos - 1 + (3 - c);
  54. X        if (c != -1)
  55. X                if ((x1 < 0) || ((y0 >= 0) && (grid[x1][y0] != 0)))
  56. X                        return (FALSE);
  57. X
  58. X        c = 3;
  59. X        while ((c >= 0) && ((t1 & (1 << c)) == 0))
  60. X                c--;
  61. X        x1 = xpos - 1 + (3 - c);
  62. X        if (c != -1)
  63. X                if ((x1 < 0) || ((y1 >= 0) && (grid[x1][y1] != 0)))
  64. X                        return (FALSE);
  65. X
  66. X        c = 3;
  67. X        while ((c >= 0) && ((t2 & (1 << c)) == 0))
  68. X                c--;
  69. X        x1 = xpos - 1 + (3 - c);
  70. X        if (c != -1)
  71. X                if ((x1 < 0) || ((y2 >= 0) && (grid[x1][y2] != 0)))
  72. X                        return (FALSE);
  73. X
  74. X        c = 3;
  75. X        while ((c >= 0) && ((t3 & (1 << c)) == 0))
  76. X                c--;
  77. X        x1 = xpos - 1 + (3 - c);
  78. X        if (c != -1)
  79. X                if ((x1 < 0) || ((y3 >= 0) && (grid[x1][y3] != 0)))
  80. X                        return (FALSE);
  81. X
  82. X        return TRUE;
  83. X}
  84. X
  85. Xblock_can_right(shape_no, xpos, ypos, rot)
  86. X        int     shape_no, xpos, ypos, rot;
  87. X{
  88. X        int     x1, c;
  89. X        int     y0, y1, y2, y3;
  90. X        int     t0, t1, t2, t3;
  91. X
  92. X        t0 = shape[shape_no].table[0][rot];     /* Bit map of 1st Row */
  93. X        t1 = shape[shape_no].table[1][rot];     /* Bit map of 2nd Row */
  94. X        t2 = shape[shape_no].table[2][rot];     /* Bit map of 3rd Row */
  95. X        t3 = shape[shape_no].table[3][rot];     /* Bit map of 4th Row */
  96. X
  97. X        y0 = ypos;
  98. X        y1 = ypos + 1;
  99. X        y2 = ypos + 2;
  100. X        y3 = ypos + 3;
  101. X
  102. X        c = 0;
  103. X        while ((c < 4) && ((t0 & (1 << c)) == 0))
  104. X                c++;
  105. X        x1 = xpos + 1 + (3 - c);
  106. X        if ((c != 4) && (x1 >= 0))
  107. X                if ((x1 == UWIDTH) || ((y0 >= 0) && (grid[x1][y0] != 0)))
  108. X                        return (FALSE);
  109. X
  110. X        c = 0;
  111. X        while ((c < 4) && ((t1 & (1 << c)) == 0))
  112. X                c++;
  113. X        x1 = xpos + 1 + (3 - c);
  114. X        if ((c != 4) && (x1 >= 0))
  115. X                if ((x1 == UWIDTH) || ((y1 >= 0) && (grid[x1][y1] != 0)))
  116. X                        return (FALSE);
  117. X
  118. X        c = 0;
  119. X        while ((c < 4) && ((t2 & (1 << c)) == 0))
  120. X                c++;
  121. X        x1 = xpos + 1 + (3 - c);
  122. X        if ((c != 4) && (x1 >= 0))
  123. X                if ((x1 == UWIDTH) || ((y2 >= 0) && (grid[x1][y2] != 0)))
  124. X                        return (FALSE);
  125. X
  126. X        c = 0;
  127. X        while ((c < 4) && ((t3 & (1 << c)) == 0))
  128. X                c++;
  129. X        x1 = xpos + 1 + (3 - c);
  130. X        if ((c != 4) && (x1 >= 0))
  131. X                if ((x1 == UWIDTH) || ((y3 >= 0) && (grid[x1][y3] != 0)))
  132. X                        return (FALSE);
  133. X
  134. X        return TRUE;
  135. X}
  136. X
  137. Xremove_full_lines(y)
  138. X        int     y;
  139. X{
  140. X        int     y1, y2, full_flag, x;
  141. X        int     xsize, ysize;
  142. X
  143. X        xsize = UNIT * UWIDTH;
  144. X        for (y1 = y; y1 < y + 4 && y1 < UHEIGHT; y1++) {
  145. X                full_flag = TRUE;
  146. X                for (x = 0; x < UWIDTH; x++)
  147. X                        if (grid[x][y1] == 0) {
  148. X                                full_flag = FALSE;
  149. X                                break;
  150. X                        }
  151. X                if (full_flag) {
  152. X                        ysize = y1 * UNIT;
  153. X                        for (y2 = y1; y2 > 0; y2--)
  154. X                                for (x = 0; x < UWIDTH; x++)
  155. X                                        grid[x][y2] = grid[x][y2 - 1];
  156. X                        for (x = 0; x < UWIDTH; x++)
  157. X                                grid[x][0] = 0;
  158. X            /* for blinking the line to remove */
  159. X            XSetFunction(XtDisplay(toplevel), gc, GXclear);
  160. X            XFillRectangle(XtDisplay(toplevel),XtWindow(canvas),gc,
  161. X                                       0, ysize, xsize, UNIT);
  162. X            usleep(250000);
  163. X            XFlush(XtDisplay(toplevel));
  164. X            XSetFunction(XtDisplay(toplevel), gc, GXcopy);
  165. X            XFillRectangle(XtDisplay(toplevel),XtWindow(canvas),gc,
  166. X                                       0, ysize, xsize, UNIT);
  167. X            usleep(250000);
  168. X            XFlush(XtDisplay(toplevel));
  169. X            XSetFunction(XtDisplay(toplevel), gc, GXclear);
  170. X            XFillRectangle(XtDisplay(toplevel),XtWindow(canvas),gc,
  171. X                                       0, ysize, xsize, UNIT);
  172. X            usleep(250000);
  173. X            XFlush(XtDisplay(toplevel));
  174. X            XSetFunction(XtDisplay(toplevel), gc, GXcopy);
  175. X            XCopyArea(XtDisplay(toplevel),
  176. X                                  XtWindow(canvas),XtWindow(canvas),gc,
  177. X                                  0,0,xsize,ysize,0, UNIT);
  178. X            XSetFunction(XtDisplay(toplevel), gc, GXclear);
  179. X            XFillRectangle(XtDisplay(toplevel),XtWindow(canvas),gc,
  180. X                                       0, 0, xsize, UNIT);
  181. X                        rows++;
  182. X                }
  183. X        }
  184. X        XFlush(XtDisplay(toplevel));
  185. X}
  186. X
  187. Xcheck_rot(shape_no, xpos, ypos, newrot)
  188. X        int     shape_no, xpos, ypos, newrot;
  189. X{
  190. X        int     i;
  191. X        int     ti;             /* Bit map of i'th row    */
  192. X        int     yi;             /* Y position on i'th row */
  193. X        int     x0, x1, x2, x3;
  194. X
  195. X        x0 = xpos;
  196. X        x1 = xpos + 1;
  197. X        x2 = xpos + 2;
  198. X        x3 = xpos + 3;
  199. X        yi = ypos;
  200. X
  201. X        for (i = 0; i < 4; yi++, i++) {
  202. X                if ((yi) >= 0) {
  203. X                        ti = shape[shape_no].table[i][newrot];
  204. X                        if ((yi >= UHEIGHT) && (ti != 0))
  205. X                                return FALSE;
  206. X                        if (ti & 8)
  207. X                                if ((x0 < 0) || (x0 >= UWIDTH) || (grid[x0][yi] == 1))
  208. X                                        return FALSE;
  209. X                        if (ti & 4)
  210. X                                if ((x1 < 0) || (x1 >= UWIDTH) || (grid[x1][yi] == 1))
  211. X                                        return FALSE;
  212. X                        if (ti & 2)
  213. X                                if ((x2 < 0) || (x2 >= UWIDTH) || (grid[x2][yi] == 1))
  214. X                                        return FALSE;
  215. X                        if (ti & 1)
  216. X                                if ((x3 < 0) || (x3 >= UWIDTH) || (grid[x3][yi] == 1))
  217. X                                        return FALSE;
  218. X                }
  219. X        }
  220. X        return TRUE;
  221. X}
  222. SHAR_EOF
  223. echo "File support.c is complete"
  224. chmod 0644 support.c || echo "restore of support.c fails"
  225. echo "x - extracting tetris.xicon (Text)"
  226. sed 's/^X//' << 'SHAR_EOF' > tetris.xicon &&
  227. X#define tetris_width 64
  228. X#define tetris_height 64
  229. X#define tetris_x_hot -1
  230. X#define tetris_y_hot -1
  231. Xstatic char tetris_bits[] = {
  232. X   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00,
  233. X   0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
  234. X   0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x10, 0x00, 0x00,
  235. X   0x00, 0x00, 0x08, 0x80, 0x01, 0x10, 0x00, 0x00, 0x00, 0x00, 0x08, 0x80,
  236. X   0x01, 0x10, 0x00, 0x00, 0x00, 0x00, 0x08, 0x80, 0x01, 0x10, 0x00, 0x00,
  237. X   0x00, 0x00, 0x08, 0x80, 0x01, 0x10, 0x00, 0xe0, 0x0e, 0x00, 0x08, 0x80,
  238. X   0x01, 0x10, 0x00, 0xb0, 0x0b, 0x00, 0x08, 0x80, 0x01, 0x10, 0x00, 0xd0,
  239. X   0x0d, 0x00, 0x08, 0x80, 0x01, 0x10, 0x00, 0x70, 0x07, 0x00, 0x08, 0x80,
  240. X   0x01, 0x10, 0x00, 0xe0, 0x0e, 0x00, 0x08, 0x80, 0x01, 0x10, 0x00, 0xb0,
  241. X   0x0b, 0x00, 0x08, 0x80, 0x01, 0x10, 0x00, 0xd0, 0x0d, 0x00, 0x08, 0x80,
  242. X   0x01, 0x10, 0x00, 0x70, 0x07, 0x00, 0x08, 0x80, 0x01, 0x10, 0x11, 0xe1,
  243. X   0x5e, 0x55, 0x0d, 0x80, 0x01, 0x10, 0x11, 0xb1, 0xab, 0xaa, 0x0a, 0x80,
  244. X   0x01, 0x50, 0x44, 0xd4, 0x5d, 0x55, 0x0d, 0x80, 0x01, 0x50, 0x44, 0x74,
  245. X   0xa7, 0xaa, 0x0a, 0x80, 0x01, 0x10, 0x11, 0xe1, 0x5e, 0x55, 0x0d, 0x80,
  246. X   0x01, 0x10, 0x11, 0xb1, 0xab, 0xaa, 0x0a, 0x80, 0x01, 0x50, 0x44, 0xd4,
  247. X   0x5d, 0x55, 0x0d, 0x80, 0x01, 0x50, 0x44, 0x74, 0xa7, 0xaa, 0x0a, 0x80,
  248. X   0x01, 0x10, 0x01, 0xe0, 0x5e, 0x15, 0x09, 0x80, 0x01, 0x10, 0x01, 0xb0,
  249. X   0xab, 0x4a, 0x0c, 0x80, 0x01, 0x50, 0x04, 0xd0, 0x5d, 0x25, 0x0a, 0x80,
  250. X   0x01, 0x50, 0x04, 0x70, 0xa7, 0x8a, 0x08, 0x80, 0x01, 0x10, 0x01, 0xe0,
  251. X   0x5e, 0x15, 0x09, 0x80, 0x01, 0x10, 0x01, 0xb0, 0xab, 0x4a, 0x0c, 0x80,
  252. X   0x01, 0x50, 0x04, 0xd0, 0x5d, 0x25, 0x0a, 0x80, 0x01, 0x50, 0x04, 0x70,
  253. X   0xa7, 0x8a, 0x08, 0x80, 0x01, 0x10, 0xf1, 0xef, 0x5e, 0x15, 0x09, 0x80,
  254. X   0x01, 0x10, 0xf1, 0xbf, 0xab, 0x4a, 0x0c, 0x80, 0x01, 0x50, 0xf4, 0xdf,
  255. X   0x5d, 0x25, 0x0a, 0x80, 0x01, 0x50, 0xf4, 0x7f, 0xa7, 0x8a, 0x08, 0x80,
  256. X   0x01, 0x10, 0xf1, 0xef, 0x5e, 0x15, 0x09, 0x80, 0x01, 0x10, 0xf1, 0xbf,
  257. X   0xab, 0x4a, 0x0c, 0x80, 0x01, 0x50, 0xf4, 0xdf, 0x5d, 0x25, 0x0a, 0x80,
  258. X   0x01, 0x50, 0xf4, 0x7f, 0xa7, 0x8a, 0x08, 0x80, 0x01, 0xf0, 0xff, 0xff,
  259. X   0x1f, 0x11, 0x09, 0x80, 0x01, 0xf0, 0xff, 0xff, 0x4f, 0x44, 0x0c, 0x80,
  260. X   0x01, 0xf0, 0xff, 0xff, 0x2f, 0x22, 0x0a, 0x80, 0x01, 0xf0, 0xff, 0xff,
  261. X   0x8f, 0x88, 0x08, 0x80, 0x01, 0xf0, 0xff, 0xff, 0x1f, 0x11, 0x09, 0x80,
  262. X   0x01, 0xf0, 0xff, 0xff, 0x4f, 0x44, 0x0c, 0x80, 0x01, 0xf0, 0xff, 0xff,
  263. X   0x2f, 0x22, 0x0a, 0x80, 0x01, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x80,
  264. X   0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00,
  265. X   0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
  266. X   0x01, 0x7e, 0x00, 0x18, 0x00, 0x18, 0x00, 0x80, 0x01, 0x18, 0x00, 0x18,
  267. X   0x00, 0x00, 0x00, 0x80, 0x01, 0x18, 0x3c, 0x7e, 0x36, 0x1e, 0x3c, 0x80,
  268. X   0x01, 0x18, 0x66, 0x18, 0x6e, 0x18, 0x66, 0x80, 0x01, 0x18, 0x66, 0x18,
  269. X   0x06, 0x18, 0x06, 0x80, 0x01, 0x18, 0x7e, 0x18, 0x06, 0x18, 0x3c, 0x80,
  270. X   0x01, 0x18, 0x06, 0x18, 0x06, 0x18, 0x60, 0x80, 0x01, 0x18, 0x66, 0x58,
  271. X   0x06, 0x18, 0x66, 0x80, 0x01, 0x18, 0x3c, 0x30, 0x06, 0x18, 0x3c, 0x80,
  272. X   0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00,
  273. X   0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
  274. X   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  275. SHAR_EOF
  276. chmod 0664 tetris.xicon || echo "restore of tetris.xicon fails"
  277. echo "x - extracting window.c (Text)"
  278. sed 's/^X//' << 'SHAR_EOF' > window.c &&
  279. X#include "defs.h"
  280. X
  281. Xstatic XtIntervalId timer;
  282. X
  283. Xstart_timer()
  284. X{
  285. X    unsigned long interval;
  286. X        int     level;
  287. X
  288. X        level = 50 - (rows / 10);
  289. X        if (level < 0)
  290. X                level = 0;
  291. X
  292. X    interval = level * 6;
  293. X    timer = XtAddTimeOut(interval, drop_block, NULL);
  294. X}
  295. X
  296. Xstop_timer()
  297. X{
  298. X    XtRemoveTimeOut(timer);
  299. X}
  300. X
  301. Xset_events()
  302. X{
  303. X        XtAddCallback(canvas, XtNselect,canvas_event_proc,NULL);
  304. X        XtAddCallback(canvas, XtNrelease,canvas_event_proc,NULL);
  305. X        XtAddCallback(canvas, XtNkeyDown,canvas_event_proc,NULL);
  306. X}
  307. X
  308. Xclear_events()
  309. X{
  310. X        XtRemoveCallback(canvas, XtNselect,canvas_event_proc,NULL);
  311. X        XtRemoveCallback(canvas, XtNrelease,canvas_event_proc,NULL);
  312. X        XtRemoveCallback(canvas, XtNkeyDown,canvas_event_proc,NULL);
  313. X}
  314. X
  315. Xvoid
  316. Xrestore_canvas(w, client_data, call_data)
  317. X    Widget w;
  318. X    caddr_t client_data;
  319. X    caddr_t call_data;
  320. X{
  321. X    int x, y;
  322. X
  323. X        XSetFunction(XtDisplay(toplevel), gc, GXclear);
  324. X        XFillRectangle(XtDisplay(toplevel), XtWindow(canvas), gc,
  325. X                       0, 0, UNIT * UWIDTH, UNIT * UHEIGHT);
  326. X        XSetFunction(XtDisplay(toplevel), gc, GXcopy);
  327. X        XSetLineAttributes(XtDisplay(toplevel), gc,
  328. X                           1, LineSolid, CapButt, JoinMiter);
  329. X        XDrawLine(XtDisplay(toplevel), XtWindow(canvas), gc,
  330. X                  0, UHEIGHT * UNIT, UWIDTH * UNIT, UHEIGHT * UNIT);
  331. X        XDrawLine(XtDisplay(toplevel), XtWindow(canvas), gc,
  332. X                  0, UHEIGHT * UNIT + SHADOW_HEIGHT,
  333. X                  UWIDTH * UNIT, UHEIGHT * UNIT + SHADOW_HEIGHT);
  334. X        XDrawLine(XtDisplay(toplevel), XtWindow(canvas), gc,
  335. X                  UWIDTH * UNIT, 0,
  336. X                  UWIDTH * UNIT, UHEIGHT * UNIT + SHADOW_HEIGHT + NEXT_HEIGHT);
  337. X    for(x=0; x<UWIDTH; x++)
  338. X        for(y=0; y<UHEIGHT; y++)
  339. X        if (grid[x][y] == 1) {
  340. X                XFillRectangle(XtDisplay(toplevel),XtWindow(canvas),gc,
  341. X                           x * UNIT, y * UNIT, UNIT, UNIT);
  342. X                XSetFillStyle(XtDisplay(toplevel), gc, FillTiled);
  343. X                XFillRectangle(XtDisplay(toplevel),XtWindow(canvas),gc,
  344. X                          (x * UNIT)+1, (y * UNIT)+1, UNIT-2, UNIT-2);
  345. X            XSetFillStyle(XtDisplay(toplevel), gc, FillSolid);
  346. X        }
  347. X
  348. X    XFlush(XtDisplay(toplevel));
  349. X        print_shape(shape_no, xpos, ypos, rot, shape[shape_no].color);
  350. X        draw_shadow(shape_no, xpos, ypos, rot, shape[shape_no].color);
  351. X    show_next();
  352. X}
  353. SHAR_EOF
  354. chmod 0644 window.c || echo "restore of window.c fails"
  355. echo "x - extracting xtetris.6 (Text)"
  356. sed 's/^X//' << 'SHAR_EOF' > xtetris.6 &&
  357. X.TH XTETRIS 6 "11st May 1989"
  358. X.SH NAME
  359. Xxtetris \- X Window block dropping game
  360. X.SH SYNOPSIS
  361. X.B xtetris
  362. X[
  363. X.B "X options"
  364. X]
  365. X.SH DESCRIPTION
  366. X.I Xtetris
  367. Xis a game involving dropping blocks. As they drop you can move them to
  368. Xthe left or to the right by clicking the left or right mouse buttons
  369. Xrespectively. Pressing the shift key while clicking the button causes
  370. Xthe falling shape to rotate anti-clockwise (left mouse button) or
  371. Xclockwise (right mouse button). Pressing the middle mouse button causes
  372. Xthe shape to quickly drop. Note that the mouse must be in the window in
  373. Xwhich the shapes are dropping for these actions to work correctly.
  374. X.PP
  375. XYou can also use the keyboard: j for moving to the left, l for moving to 
  376. Xthe right, k to rotate anti-clockwise and space for dropping quickly..
  377. X.PP
  378. XPoints are scored for each block that comes to rest on the gradually
  379. Xbuilding up pile of blocks. Different blocks in different orientations
  380. Xhave different point values. When the pile reaches the top of the
  381. Xscreen and no further blocks can be dropped the game ends. Whenever a
  382. Xfull row of blocks across the screen is all completely filled in that
  383. Xrow is removed and all the blocks above it drop down a further row.
  384. XAs more rows are deleted the blocks drop faster.
  385. X.PP
  386. XA high score table is kept which is retained between separate executions
  387. Xof the game.
  388. X.SH OPTIONS
  389. X.I Xtetris
  390. Xtakes standard
  391. X.I X
  392. Xoptions. (see 
  393. X.I X (1)
  394. X)
  395. X.SH FILES
  396. X.IP /usr/games/lib/tetris_scores
  397. XTop 10 high scores.
  398. X.SH "ENVIRONMENT VARIABLES"
  399. X.IP TETRIS
  400. XIf set, your desired name for the high score table.
  401. X.SH "SEE ALSO"
  402. X.BI X (1)
  403. SHAR_EOF
  404. chmod 0644 xtetris.6 || echo "restore of xtetris.6 fails"
  405. rm -f s2_seq_.tmp
  406. echo "You have unpacked the last part"
  407. exit 0
  408.