home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / games / volume18 / threedee / part02 < prev    next >
Encoding:
Internet Message Format  |  1993-09-13  |  56.3 KB

  1. Path: uunet!news.tek.com!news.cna.tek.com!not-for-mail
  2. From: billr@saab.cna.tek.com (Bill Randle)
  3. Newsgroups: comp.sources.games
  4. Subject: v18i057:  threedee - two 3d tetris games for X, Part02/04
  5. Date: 30 Aug 1993 08:34:59 -0700
  6. Organization: Tektronix, Inc., Redmond, OR
  7. Lines: 2982
  8. Approved: billr@saab.CNA.TEK.COM
  9. Message-ID: <25t6n3$fm4@saab.cna.tek.com>
  10. NNTP-Posting-Host: saab.cna.tek.com
  11. Xref: uunet comp.sources.games:1857
  12.  
  13. Submitted-by: "Andrew C. Plotkin" <ap1i+@andrew.cmu.edu>
  14. Posting-number: Volume 18, Issue 57
  15. Archive-name: threedee/part02
  16. Environment: X11, Xlib
  17.  
  18.  
  19.  
  20. #! /bin/sh
  21. # This is a shell archive.  Remove anything before this line, then unpack
  22. # it by saving it into a file and typing "sh file".  To overwrite existing
  23. # files, type "sh file -c".  You can also feed this as standard input via
  24. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  25. # will see the following message at the end:
  26. #        "End of archive 2 (of 4)."
  27. # Contents:  spatial/game.c spatial/intro.c spatial/spatial.shp
  28. #   spheral/disp.c spheral/game.c spheral/patchlevel.h spheral/score.c
  29. #   spheral/spheral.6
  30. # Wrapped by billr@saab on Mon Aug 30 08:05:07 1993
  31. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  32. if test -f 'spatial/game.c' -a "${1}" != "-c" ; then 
  33.   echo shar: Will not clobber existing file \"'spatial/game.c'\"
  34. else
  35. echo shar: Extracting \"'spatial/game.c'\" \(8859 characters\)
  36. sed "s/^X//" >'spatial/game.c' <<'END_OF_FILE'
  37. X/* (C) Copyright 1991 Andrew Plotkin. Permission is
  38. X given to copy and use, as long as this copyright
  39. X notice is retained. */
  40. X
  41. X#include <stdio.h>
  42. X#include <sys/time.h>
  43. X#include <X11/Xlib.h>
  44. X#include <X11/keysym.h>
  45. X#include "spatial.h"
  46. X
  47. X#define TICKLENGTH (25000)
  48. X#define GLIDELENGTH (8)
  49. X#define TURNLENGTH (8)
  50. X#define PLUMLENGTH (3)
  51. X#define FALLLENGTH (8)
  52. X#define PI (3.141593)
  53. X
  54. Xint stereo;
  55. X
  56. Xint meterx, meterx2, metery, metersize, meterlev, meteroldlev,
  57. Xmeter_f_b, meter_b_d; /* oldlev is level on fieldpm */
  58. X
  59. Xunsigned char field[MAXFIELDXY][MAXFIELDXY][MAXFIELDZ];
  60. Xshort fieldx, fieldy, fieldz;
  61. Xdouble fieldoffx, fieldoffx2, fieldoffy, fieldoffz;
  62. Xextern double offx, offy, offz;
  63. Xlong score=(-1), dropticks;
  64. X
  65. Xextern void plop_piece(), setup_cubies(), redo_board_globals();
  66. Xextern void setup_fieldpm(), clearfield(),
  67. Xback_to_disp(), setup_backpm();
  68. Xextern void startpiece(), rotate_piece(),
  69. Xupdatetemp_tra(), updatepiece(), round_piece();
  70. Xextern void pauseloop();
  71. Xextern int collision();
  72. X
  73. Xvoid clearfield()
  74. X{
  75. X    int ix, iy, iz;
  76. X    for (ix=0; ix<fieldx; ix++)
  77. X    for (iy=0; iy<fieldy; iy++)
  78. X        for (iz=0; iz<fieldz; iz++) 
  79. X        field[ix][iy][iz] = 0;
  80. X}
  81. X
  82. Xvoid initgame()
  83. X{
  84. X    curpiece = -1;
  85. X    score = 0;
  86. X    dropticks = 80;
  87. X    meterlev = 0;
  88. X    clearfield();
  89. X    setup_cubies();
  90. X    setup_fieldpm();
  91. X}
  92. X
  93. Xvoid gameloop()
  94. X{
  95. X#define ST_STILL (0)
  96. X#define ST_FALL (1)
  97. X#define ST_TURN (2)
  98. X#define ST_GLIDE (3)
  99. X#define ST_PLUMMET (4)
  100. X#define ST_SPACEHIT (5)
  101. X#define ST_PAUSE (6)
  102. X
  103. X    short status, res, aighhmode=0;
  104. X    short droptimer=0, stattick;
  105. X    Bool eventp;
  106. X    XEvent event, nextevent;
  107. X    long evmasks;
  108. X    char key;
  109. X    KeySym ksym;
  110. X    long lasttime;
  111. X    int toffx, toffy, toffz;
  112. X    int taxis; /* 1=x, 2=y, 3=z */
  113. X    int tdir;
  114. X    struct timeval tv;
  115. X    fd_set readbits;
  116. X    int gotit;
  117. X
  118. X    status = ST_PAUSE;
  119. X    /*lasttime = current_usec();*/
  120. X
  121. X    while (1) {
  122. X    if (curpiece==(-1)) {
  123. X        startpiece();
  124. X        if (curpiece==(-2)) break;
  125. X        setup_backpm();
  126. X        draw_score(backpm);
  127. X        draw_score(win);
  128. X        back_to_disp(0);
  129. X        droptimer = 0;
  130. X
  131. X        do {
  132. X        eventp = XCheckWindowEvent(dpy,
  133. X            win, KeyPressMask, &event);
  134. X        }
  135. X        while (eventp);
  136. X    };
  137. X
  138. X    XFlush(dpy);
  139. X
  140. X    tv.tv_sec = 0;
  141. X    tv.tv_usec = TICKLENGTH;
  142. X    FD_ZERO(&readbits);
  143. X    FD_SET(ConnectionNumber(dpy), &readbits);
  144. X    (void)select(1+ConnectionNumber(dpy), &readbits, 0, 0, &tv);
  145. X
  146. X    if (status == ST_STILL)
  147. X        evmasks = (KeyPressMask | ExposureMask |
  148. X               StructureNotifyMask);
  149. X    else
  150. X        evmasks = (ExposureMask | StructureNotifyMask);
  151. X
  152. X    if (eventp = XCheckWindowEvent(dpy, win, evmasks, &event))
  153. X      switch (event.type) {
  154. X        case Expose:
  155. X        do {
  156. X            gotit = XCheckWindowEvent(dpy, win,
  157. X            ExposureMask, &nextevent);
  158. X        } while (gotit);
  159. X        back_to_disp(1);
  160. X        break;
  161. X        case KeyPress:
  162. X        XLookupString(&event, &key, 1, &ksym, NULL);
  163. X        switch (ksym) {
  164. X            case XK_Q:
  165. X            case XK_q:
  166. X            return;
  167. X            break;
  168. X            case XK_Escape:
  169. X            pauseloop();
  170. X            setup_fieldpm();
  171. X            redraw_cubies();   
  172. X            setup_backpm();
  173. X            draw_score(backpm);
  174. X            draw_score(win);
  175. X            back_to_disp(1);            
  176. X            break;
  177. X            case XK_asciitilde:
  178. X            aighhmode = (!aighhmode);
  179. X            break;
  180. X            case XK_h:
  181. X            case XK_j:
  182. X            case XK_k:
  183. X            case XK_l:
  184. X            case XK_i:
  185. X            case XK_m:
  186. X            if (status != ST_STILL) break;
  187. X            if (ksym==XK_i || ksym==XK_m) taxis=1;
  188. X            if (ksym==XK_h || ksym==XK_l) taxis=2;
  189. X            if (ksym==XK_j || ksym==XK_k) taxis=3;
  190. X            if (ksym==XK_i || ksym==XK_h || ksym==XK_k)
  191. X                tdir=1;
  192. X            else tdir=(-1);
  193. X            toffx = 0;
  194. X            toffy = 0;
  195. X            toffz = 0;
  196. X            updatetemp_tra(toffx, toffy, toffz, taxis,
  197. X                       tdir);
  198. X            res = collision(1);
  199. X            while (res==1 || (res>=3 && res <=6)) {
  200. X                switch (res) {
  201. X                case 1:
  202. X                    toffz--;
  203. X                    break;
  204. X                case 3:
  205. X                    toffy++;
  206. X                    break;
  207. X                case 4:
  208. X                    toffy--;
  209. X                    break;
  210. X                case 5:
  211. X                    toffx--;
  212. X                    break;
  213. X                case 6:
  214. X                    toffx++;
  215. X                    break;
  216. X                }
  217. X                updatetemp_tra(toffx, toffy, toffz,
  218. X                       taxis, tdir);
  219. X                res = collision(1);
  220. X            };
  221. X            if (res==0) {
  222. X                status = ST_TURN;
  223. X                stattick = 0;
  224. X            };
  225. X            break;
  226. X            case XK_p:
  227. X            if (status != ST_STILL) break;
  228. X            droptimer = dropticks+100;
  229. X            break;
  230. X            case XK_space:
  231. X            if (status != ST_STILL) break;
  232. X            status = ST_SPACEHIT;
  233. X            break;
  234. X            case XK_Left:
  235. X            case XK_Right:
  236. X            case XK_Up:
  237. X            case XK_Down:
  238. X            if (status != ST_STILL) break;
  239. X            toffx = 0;
  240. X            toffy = 0;
  241. X            if (ksym==XK_Left) toffx = -1;
  242. X            if (ksym==XK_Right) toffx = 1;
  243. X            if (ksym==XK_Up) toffy = -1;
  244. X            if (ksym==XK_Down) toffy = 1;
  245. X            updatetemp_tra(toffx, toffy, 0, 0, 0);
  246. X            if (collision(1)==0) {
  247. X                status = ST_GLIDE;
  248. X                stattick = 0;
  249. X            };
  250. X            break;
  251. X        };
  252. X        break;
  253. X        case ConfigureNotify:
  254. X        if (event.xconfigure.width != dispx || event.xconfigure.height != dispy) {
  255. X            dispx = event.xconfigure.width;
  256. X            dispy = event.xconfigure.height;
  257. X            XFreePixmap(dpy, backpm);
  258. X            XFreePixmap(dpy, fieldpm);
  259. X            backpm = XCreatePixmap(dpy, win,
  260. X            dispx, dispy, scndepth);   
  261. X            fieldpm = XCreatePixmap(dpy, win,
  262. X            dispx, dispy, scndepth);   
  263. X            redo_board_globals();
  264. X            setup_cubies();
  265. X            setup_fieldpm();
  266. X            redraw_cubies();   
  267. X            setup_backpm();
  268. X            draw_score(backpm);
  269. X            draw_score(win);
  270. X            back_to_disp(1);            
  271. X        }
  272. X        break;
  273. X        default:
  274. X        break;
  275. X    }
  276. X
  277. X    {
  278. X        if (status==ST_PAUSE) status=ST_STILL;
  279. X        switch (status) {
  280. X        case ST_STILL:
  281. X            droptimer++;
  282. X            if (droptimer>dropticks) {
  283. X            droptimer=0;
  284. X            updatetemp_tra(0, 0, -1, 0, 0);
  285. X            if (collision(1)==0) {  
  286. X                stattick=0;
  287. X                status = ST_FALL;
  288. X            }
  289. X            else {
  290. X                plop_piece();
  291. X                curpiece = -1;
  292. X            }
  293. X            }
  294. X            break;
  295. X        case ST_SPACEHIT:
  296. X            updatetemp_tra(0, 0, -1, 0, 0);
  297. X            if (aighhmode || collision(1)==0) {  
  298. X            score++;
  299. X            stattick=1;
  300. X            status = ST_PLUMMET;
  301. X            offz -= 1.0/PLUMLENGTH;
  302. X            if (offz < -(fieldz+300.0)) {
  303. X                fprintf(stderr,
  304. X                "Vanishing point error\nSegmentation fault\n");
  305. X                exit(-1);
  306. X            }
  307. X            updatepiece();
  308. X            setup_backpm();
  309. X            back_to_disp(0);
  310. X            }
  311. X            else {
  312. X            plop_piece();
  313. X            curpiece = -1;
  314. X            status = ST_PAUSE;
  315. X            }
  316. X            break;
  317. X        case ST_GLIDE:
  318. X            stattick++;
  319. X            offx += (double)toffx/GLIDELENGTH;
  320. X            offy += (double)toffy/GLIDELENGTH;
  321. X            if (stattick==GLIDELENGTH) {
  322. X            round_piece(); 
  323. X            };
  324. X            updatepiece();
  325. X            setup_backpm();
  326. X            back_to_disp(0);
  327. X            if (stattick==GLIDELENGTH) {
  328. X            status = ST_PAUSE;
  329. X            };
  330. X            break;
  331. X        case ST_FALL:
  332. X            stattick++;
  333. X            offz -= 1.0/FALLLENGTH;
  334. X            if (stattick==FALLLENGTH) {
  335. X            round_piece(); 
  336. X            };
  337. X            updatepiece();
  338. X            setup_backpm();
  339. X            back_to_disp(0);
  340. X            if (stattick==FALLLENGTH) {
  341. X            status = ST_PAUSE;
  342. X            };
  343. X            break;
  344. X        case ST_PLUMMET:
  345. X            stattick++;
  346. X            offz -= 1.0/PLUMLENGTH;
  347. X            if (stattick==PLUMLENGTH) {
  348. X            round_piece(); 
  349. X            };
  350. X            updatepiece();
  351. X            setup_backpm();
  352. X            back_to_disp(0);
  353. X            if (stattick==PLUMLENGTH) {
  354. X            status = ST_SPACEHIT;
  355. X            };
  356. X            break;
  357. X        case ST_TURN:
  358. X            stattick++;
  359. X            rotate_piece(taxis, tdir*0.5*PI/TURNLENGTH);
  360. X            offx += (double)toffx/TURNLENGTH;
  361. X            offy += (double)toffy/TURNLENGTH;
  362. X            offz += (double)toffz/TURNLENGTH;
  363. X            if (stattick==TURNLENGTH) {
  364. X            round_piece(); 
  365. X            };
  366. X            updatepiece();
  367. X            setup_backpm();
  368. X            back_to_disp(0);
  369. X            if (stattick==TURNLENGTH) {
  370. X            status = ST_PAUSE;
  371. X            };
  372. X            break;
  373. X        }
  374. X        /*lasttime = current_usec();*/        
  375. X    }
  376. X    }
  377. X}
  378. X
  379. Xvoid redo_board_globals()  /* using dispx, dispy */
  380. X{
  381. X    if (!stereo) {
  382. X    if (dispy-40<dispx-20) 
  383. X        boardscale = (double)(dispy - 40);
  384. X    else
  385. X        boardscale = (double)(dispx - 20);
  386. X    halfboard = (int)boardscale/2;
  387. X    }
  388. X    else {
  389. X    if (dispy-40<(dispx-20)/2)
  390. X        boardscale = (double)(dispy - 40);
  391. X    else
  392. X        boardscale = (double)((dispx - 20)/2);
  393. X    halfboard = (int)boardscale/2;
  394. X    halfboard2 = (3.0+(fieldoffx+2.5)/1.5)*halfboard;
  395. X    }
  396. X    if (dispy-(int)boardscale > 60) {
  397. X    meterx = 32;
  398. X    metery = boardscale+30;
  399. X    }
  400. X    else {
  401. X    meterx = 176;
  402. X    metery = boardscale+10;
  403. X    }
  404. X    metersize = (((int)boardscale) - meterx) / fieldz;
  405. X    if (metersize<1) metersize = 1;
  406. X    if (stereo) {
  407. X    meterx2 = meterx + (halfboard2 - halfboard);
  408. X    /*meterx2 = meterx2 & (~7);*/
  409. X    }
  410. X}
  411. X
  412. Xlong current_usec() /* returns the current
  413. X time in microseconds */ 
  414. X{
  415. X    struct timeval tv;
  416. X
  417. X    gettimeofday(&tv, (struct timezone *)NULL);
  418. X    return tv.tv_usec + 1000000*(tv.tv_sec%100);
  419. X}
  420. X
  421. Xint elapsed(start, length) /* returns whether
  422. X length microseconds have elapsed since start.
  423. X Not reliable when length is more than 10^8 usec
  424. X (100 seconds) */
  425. Xlong start, length;
  426. X{
  427. X    long now;
  428. X
  429. X    now = current_usec();
  430. X    if (start <= now) {
  431. X    if (now-start > length) return 1;
  432. X    else return 0;
  433. X    }
  434. X    else {  /* the current time has rolled
  435. X     over; add 10^8 to it */
  436. X    if (now+100000000-start > length) return 1;
  437. X    else return 0;
  438. X    }
  439. X}
  440. END_OF_FILE
  441. if test 8859 -ne `wc -c <'spatial/game.c'`; then
  442.     echo shar: \"'spatial/game.c'\" unpacked with wrong size!
  443. fi
  444. # end of 'spatial/game.c'
  445. fi
  446. if test -f 'spatial/intro.c' -a "${1}" != "-c" ; then 
  447.   echo shar: Will not clobber existing file \"'spatial/intro.c'\"
  448. else
  449. echo shar: Extracting \"'spatial/intro.c'\" \(4908 characters\)
  450. sed "s/^X//" >'spatial/intro.c' <<'END_OF_FILE'
  451. X/* (C) Copyright 1991 Andrew Plotkin. Permission is
  452. X given to copy and use, as long as this copyright
  453. X notice is retained. */
  454. X
  455. X#include <stdio.h>
  456. X#include <sys/time.h>
  457. X#include <X11/Xlib.h>
  458. X#include <X11/keysym.h>
  459. X#include "spatial.h"
  460. X
  461. X#define TICKLENGTH (50000)
  462. X#define xputs(x, y, str)  \
  463. XXDrawImageString(dpy, win, gcwhite, x, y, str, strlen(str))
  464. X
  465. X#define xline(x1, y1, x2, y2)  \
  466. XXDrawLine(dpy, win, gcwhite, x1, y1, x2, y2) 
  467. X
  468. Xextern GC gcblack, gcwhite, gcinv, gccopy, gcline,
  469. Xgcfield, gccubes[];
  470. X
  471. Xextern void intro_redraw(), redo_board_globals();
  472. X
  473. Xvoid initintro()
  474. X{
  475. X    intro_redraw();
  476. X}
  477. X
  478. Xvoid introloop()
  479. X{
  480. X    short status, res;
  481. X    Bool eventp;
  482. X    XEvent event, nextevent;
  483. X    long evmasks;
  484. X    char key;
  485. X    KeySym ksym;
  486. X    long lasttime;
  487. X    struct timeval tv;
  488. X    fd_set readbits;
  489. X
  490. X    while (1) {
  491. X    tv.tv_sec = 0;
  492. X    tv.tv_usec = TICKLENGTH;
  493. X    FD_ZERO(&readbits);
  494. X    FD_SET(ConnectionNumber(dpy), &readbits);
  495. X    (void)select(1+ConnectionNumber(dpy), &readbits, 0, 0, &tv);
  496. X
  497. X    evmasks = (KeyPressMask | ExposureMask | StructureNotifyMask);
  498. X    eventp = XCheckWindowEvent(dpy, win, evmasks, &event);
  499. X    if (eventp) switch (event.type) {
  500. X        case Expose:
  501. X        eventp = XCheckWindowEvent(dpy, win, evmasks,
  502. X            &nextevent);
  503. X        while (eventp && nextevent.type == Expose) {
  504. X            eventp = XCheckWindowEvent(dpy, win, evmasks,
  505. X            &nextevent);
  506. X        };
  507. X        if (eventp) {
  508. X            XPutBackEvent(dpy, &nextevent);
  509. X        };
  510. X        intro_redraw();
  511. X        break;
  512. X        case KeyPress:
  513. X        XLookupString(&event, &key, 1, &ksym, NULL);
  514. X        /*printf("got '%s'\n", XKeysymToString(ksym));*/
  515. X        switch (ksym) {
  516. X            case XK_q:
  517. X            case XK_Q:
  518. X            exit(0);
  519. X            break;
  520. X            case XK_c:
  521. X            case XK_C:
  522. X            if (!stereo) {
  523. X                stereo = 1;
  524. X                fieldoffx = -2.65;
  525. X                fieldoffx2 = -2.35;
  526. X            }
  527. X            else if (fieldoffx < -2.5) {
  528. X                fieldoffx = -2.35;
  529. X                fieldoffx2 = -2.65;
  530. X            }
  531. X            else {
  532. X                stereo = 0;
  533. X                fieldoffx = -2.5;
  534. X            };
  535. X            redo_board_globals();
  536. X            intro_redraw();
  537. X            break;
  538. X            case XK_s:
  539. X            case XK_S:
  540. X            return;
  541. X        };
  542. X        break;
  543. X        case ConfigureNotify:
  544. X        if (event.xconfigure.width != dispx || event.xconfigure.height != dispy) {
  545. X            dispx = event.xconfigure.width;
  546. X            dispy = event.xconfigure.height;
  547. X            redo_board_globals();
  548. X            XFreePixmap(dpy, backpm);
  549. X            XFreePixmap(dpy, fieldpm);
  550. X            backpm = XCreatePixmap(dpy, win, dispx,
  551. X                       dispy, scndepth);   
  552. X            fieldpm = XCreatePixmap(dpy, win, dispx,
  553. X                        dispy, scndepth);   
  554. X        }
  555. X        break;
  556. X    }
  557. X    }
  558. X}
  559. X
  560. Xvoid intro_redraw()
  561. X{
  562. X    register int ix;
  563. X    char buf[255];
  564. X
  565. X    XFillRectangle(dpy, win, gcblack, 0, 0, dispx, dispy);
  566. X    xputs(50, 180, "Spatial");
  567. X    xputs(50, 200, "A Sadistic Software Production");
  568. X    xputs(50, 220, "(C) Copyright 1991-3 Andrew Plotkin");
  569. X    xputs(50, 240, " (ap1i@andrew.cmu.edu)");
  570. X    if (score!=(-1)) {
  571. X    sprintf(buf, "Your score: %d", score);
  572. X    xputs(50, 260, buf);
  573. X    }
  574. X
  575. X    xputs(50, 280, "Commands:");
  576. X    xputs(70, 300, "s: start game");
  577. X    if (!stereo) xputs(70, 320, "c: change display (normal)");
  578. X    else if (fieldoffx < -2.5)
  579. X    xputs(70, 320, "c: change display (reversed stereoscopic)");
  580. X    else
  581. X    xputs(70, 320, "c: change display (normal stereoscopic)");
  582. X    xputs(70, 340, "Escape: pause");
  583. X    xputs(70, 360, "q: quit program");
  584. X
  585. X    xputs(50, 400, "Game controls:");
  586. X
  587. X    XDrawArc(dpy, win, gcfield, 50, 410, 140, 140, 0, 23040);
  588. X    XDrawArc(dpy, win, gcfield, 100, 410, 40, 140, 0, 23040);
  589. X    XDrawArc(dpy, win, gcfield, 50, 460, 140, 40, 0, 23040);
  590. X    XDrawArc(dpy, win, gcfield, 102, 410, 40, 140, 5760, 11520);
  591. X    XDrawArc(dpy, win, gcfield, 50, 462, 140, 40, 11520, 11520);
  592. X    XDrawArc(dpy, win, gcwhite, 101, 410, 40, 140, 8000, 3000);
  593. X    XDrawArc(dpy, win, gcwhite, 101, 410, 40, 140, 14000, 2000);
  594. X    XDrawArc(dpy, win, gcwhite, 50, 461, 140, 40, 13000, 2000);
  595. X    XDrawArc(dpy, win, gcwhite, 50, 461, 140, 40, 17800, 3000);
  596. X    XDrawArc(dpy, win, gcwhite, 51, 411, 138, 138, 1920, 1920);
  597. X    XDrawArc(dpy, win, gcwhite, 51, 411, 138, 138, 7680, 1920);
  598. X    xline(110, 421, 114, 430);
  599. X    xline(110, 421, 100, 427);
  600. X    xline(179, 492, 170, 488);
  601. X    xline(179, 492, 173, 502);
  602. X    xline(57, 489, 60, 498);
  603. X    xline(57, 489, 60, 484);
  604. X    xline(114, 546, 105, 543);
  605. X    xline(114, 546, 119, 543);
  606. X    xline(182, 448, 172, 445);
  607. X    xline(58, 448, 68, 445);
  608. X
  609. X    xputs(83, 501, "h");
  610. X    xputs(120, 503, "l");
  611. X    xputs(99, 483, "i");
  612. X    xputs(102, 518, "m");
  613. X    xputs(91, 418, "k");
  614. X    xputs(144, 416, "j");
  615. X
  616. X    xputs(70, 570, "rotation keys as shown above");
  617. X    xputs(70, 590, "arrow keys: move piece sideways");
  618. X    xputs(70, 610, "p: drop piece by 1");
  619. X    xputs(70, 630, "space: drop piece to bottom");
  620. X    xputs(70, 650, "q: quit game and return to this menu");
  621. X
  622. X    xputs(350, 250, "High Scores:");
  623. X    for (ix=0; ix<NUMGAMERS; ix++) {
  624. X    xputs(390, 270+20*ix, hscores[ix].name);
  625. X    xputs(490, 270+20*ix, hscores[ix].userid);
  626. X    xputs(590, 270+20*ix, hscores[ix].scoret);
  627. X    }
  628. X}
  629. END_OF_FILE
  630. if test 4908 -ne `wc -c <'spatial/intro.c'`; then
  631.     echo shar: \"'spatial/intro.c'\" unpacked with wrong size!
  632. fi
  633. # end of 'spatial/intro.c'
  634. fi
  635. if test -f 'spatial/spatial.shp' -a "${1}" != "-c" ; then 
  636.   echo shar: Will not clobber existing file \"'spatial/spatial.shp'\"
  637. else
  638. echo shar: Extracting \"'spatial/spatial.shp'\" \(8168 characters\)
  639. sed "s/^X//" >'spatial/spatial.shp' <<'END_OF_FILE'
  640. X25
  641. X
  642. X3, 8, 12
  643. X.5, -.5, -.5
  644. X.5, .5, -.5
  645. X.5, 1.5, -.5
  646. X0, -1, 0
  647. X1, -1, 0
  648. X1, 2, 0
  649. X0, 2, 0
  650. X0, -1, -1
  651. X1, -1, -1
  652. X1, 2, -1
  653. X0, 2, -1
  654. X0,1
  655. X1,2
  656. X2,3
  657. X3,0
  658. X4,5
  659. X5,6
  660. X6,7
  661. X7,4
  662. X0,4
  663. X1,5
  664. X2,6
  665. X3,7
  666. X
  667. X3, 12, 18
  668. X-.5, -.5, -.5
  669. X-.5, .5, -.5
  670. X.5, .5, -.5
  671. X0, 0, 0
  672. X1, 0, 0
  673. X1, 1, 0
  674. X-1, 1, 0
  675. X-1, -1, 0
  676. X0, -1, 0
  677. X0, 0, -1
  678. X1, 0, -1
  679. X1, 1, -1
  680. X-1, 1, -1
  681. X-1, -1, -1
  682. X0, -1, -1
  683. X0,1
  684. X1,2
  685. X2,3
  686. X3,4
  687. X4,5
  688. X5,0
  689. X6,7
  690. X7,8
  691. X8,9
  692. X9,10
  693. X10,11
  694. X11,6
  695. X0,6
  696. X1,7
  697. X2,8
  698. X3,9
  699. X4,10
  700. X5,11
  701. X
  702. X5, 14, 21
  703. X-.5, -.5, .5
  704. X-.5, -.5, -.5
  705. X-.5, .5, -.5
  706. X.5, .5, -.5
  707. X1.5, .5, -.5
  708. X-1, -1, 1
  709. X0, -1, 1
  710. X-1, 0, 1
  711. X0, 0, 1
  712. X-1, -1, -1
  713. X0, -1, -1
  714. X-1, 0, 0
  715. X2, 0, 0
  716. X2, 0, -1
  717. X2, 1, 0
  718. X2, 1, -1
  719. X-1, 1, 0
  720. X-1, 1, -1
  721. X0, 0, -1
  722. X0,1
  723. X1,3
  724. X3,2
  725. X2,0
  726. X6,7
  727. X7,9
  728. X9,11
  729. X11,6
  730. X4,5
  731. X5,13
  732. X13,8
  733. X8,10
  734. X10,12
  735. X12,4
  736. X0,4
  737. X1,5
  738. X3,13
  739. X7,8
  740. X9,10
  741. X11,12
  742. X2,6
  743. X
  744. X5, 17, 24
  745. X-.5, .5, .5
  746. X-.5, -.5, -.5
  747. X-.5, .5, -.5
  748. X.5, .5, -.5
  749. X1.5, .5, -.5
  750. X-1, 0, 1
  751. X0, 0, 1
  752. X-1, 1, 1
  753. X0, 1, 1
  754. X-1, -1, 0
  755. X0, -1, 0
  756. X0, 0, 0
  757. X2, 0, 0
  758. X2, 1, 0
  759. X0, 1, 0
  760. X-1, 0, 0
  761. X-1, -1, -1
  762. X0, -1, -1
  763. X0, 0, -1
  764. X2, 0, -1
  765. X2, 1, -1
  766. X-1, 1, -1
  767. X0,10
  768. X1,13
  769. X7,14
  770. X8,15
  771. X3,9
  772. X2,16
  773. X4,11
  774. X5,12
  775. X0,1
  776. X1,3
  777. X3,2
  778. X2,0
  779. X10,4
  780. X4,5
  781. X5,9
  782. X10,7
  783. X7,8
  784. X8,9
  785. X11,12
  786. X12,13
  787. X13,14
  788. X14,15
  789. X15,16
  790. X16,11
  791. X
  792. X5, 18, 27
  793. X.5, .5, .5
  794. X-.5, -.5, -.5
  795. X-.5, .5, -.5
  796. X.5, .5, -.5
  797. X1.5, .5, -.5
  798. X0, 0, 1
  799. X1, 0, 1
  800. X1, 1, 1
  801. X0, 1, 1
  802. X-1, -1, 0
  803. X0, -1, 0
  804. X2, 0, 0
  805. X2, 1, 0
  806. X1, 0, 0
  807. X1, 1, 0
  808. X0, 1, 0
  809. X-1, 1, 0
  810. X-1, -1, -1
  811. X0, -1, -1
  812. X0, 0, -1
  813. X2, 0, -1
  814. X2, 1, -1
  815. X-1, 1, -1
  816. X0,1
  817. X1,2
  818. X2,3
  819. X3,0
  820. X4,5
  821. X5,10
  822. X8,6
  823. X6,7
  824. X7,9
  825. X10,11
  826. X11,4
  827. X12,13
  828. X13,14
  829. X14,15
  830. X15,16
  831. X16,17
  832. X17,12
  833. X4,12
  834. X5,13
  835. X0,14
  836. X1,8
  837. X6,15
  838. X7,16
  839. X2,9
  840. X3,10
  841. X11,17
  842. X8,9
  843. X
  844. X5, 16, 24
  845. X1.5, .5, .5
  846. X-.5, -.5, -.5
  847. X-.5, .5, -.5
  848. X.5, .5, -.5
  849. X1.5, .5, -.5
  850. X1, 0, 1
  851. X2, 0, 1
  852. X1, 1, 1
  853. X2, 1, 1
  854. X-1, -1, 0
  855. X0, -1, 0
  856. X0, 0, 0
  857. X1, 0, 0
  858. X1, 1, 0
  859. X-1, 1, 0
  860. X-1, -1, -1
  861. X0, -1, -1
  862. X0, 0, -1
  863. X2, 0, -1
  864. X2, 1, -1
  865. X-1, 1, -1
  866. X0,1
  867. X1,3
  868. X3,2
  869. X2,0
  870. X4,5
  871. X5,6
  872. X6,7
  873. X7,8
  874. X8,9
  875. X9,4
  876. X10,11
  877. X11,12
  878. X12,13
  879. X13,14
  880. X14,15
  881. X15,10
  882. X4,10
  883. X5,11
  884. X6,12
  885. X0,7
  886. X1,13
  887. X3,14
  888. X2,8
  889. X9,15
  890. X
  891. X5, 16, 24
  892. X.5, -.5, .5
  893. X.5, -.5, -.5
  894. X-.5, .5, -.5
  895. X.5, .5, -.5
  896. X1.5, .5, -.5
  897. X0, -1, 1
  898. X1, -1, 1
  899. X1, 0, 1
  900. X0, 0, 1
  901. X-1, 0, 0
  902. X2, 0, 0
  903. X2, 1, 0
  904. X-1, 1, 0
  905. X-1, 0, -1
  906. X0, 0, -1
  907. X0, -1, -1
  908. X1, -1, -1
  909. X1, 0, -1
  910. X2, 0, -1
  911. X2, 1, -1
  912. X-1, 1, -1
  913. X0,1
  914. X1,2
  915. X2,3
  916. X3,0
  917. X4,5
  918. X5,6
  919. X6,7
  920. X7,4
  921. X8,9
  922. X9,10
  923. X10,11
  924. X11,12
  925. X12,13
  926. X13,14
  927. X14,15
  928. X15,8
  929. X0,10
  930. X1,11
  931. X2,12
  932. X3,9
  933. X5,13
  934. X6,14
  935. X7,15
  936. X4,8
  937. X
  938. X5, 20, 30
  939. X.5, -.5, .5
  940. X-.5, -.5, -.5
  941. X.5, -.5, -.5
  942. X1.5, -.5, -.5
  943. X.5, .5, -.5
  944. X0, -1, 1
  945. X1, -1, 1
  946. X1, 0, 1
  947. X0, 0, 1
  948. X-1, -1, 0
  949. X0, -1, 0
  950. X1, -1, 0
  951. X2, -1, 0
  952. X2, 0, 0
  953. X-1, 0, 0
  954. X-1, -1, -1
  955. X2, -1, -1
  956. X2, 0, -1
  957. X1, 0, -1
  958. X1, 1, -1
  959. X0, 1, -1
  960. X0, 0, -1
  961. X-1, 0, -1
  962. X0, 1, 0
  963. X1, 1, 0
  964. X0,1
  965. X1,2
  966. X2,3
  967. X3,0
  968. X6,7
  969. X7,8
  970. X8,9
  971. X9,4
  972. X4,5
  973. X10,11
  974. X11,12
  975. X12,13
  976. X13,14
  977. X14,15
  978. X15,16
  979. X16,17
  980. X17,10
  981. X0,5
  982. X1,6
  983. X7,11
  984. X8,12
  985. X2,13
  986. X3,16
  987. X19,14
  988. X18,15
  989. X9,17
  990. X4,10
  991. X5,18
  992. X6,19
  993. X18,19
  994. X
  995. X5, 14, 21
  996. X-.5, .5, .5
  997. X-.5, .5, -.5
  998. X-.5, -.5, -.5
  999. X.5, -.5, -.5
  1000. X.5, .5, -.5
  1001. X-1, 0, 1
  1002. X0, 0, 1
  1003. X0, 1, 1
  1004. X-1, 1, 1
  1005. X-1, 0, 0
  1006. X0, 0, 0
  1007. X0, 1, 0
  1008. X1, 1, 0
  1009. X1, -1, 0
  1010. X-1, -1, 0
  1011. X-1, 1, -1
  1012. X1, 1, -1
  1013. X1, -1, -1
  1014. X-1, -1, -1
  1015. X0,1
  1016. X1,2
  1017. X2,3
  1018. X3,0
  1019. X4,5
  1020. X5,6
  1021. X6,7
  1022. X7,8
  1023. X8,9
  1024. X9,4
  1025. X10,11
  1026. X11,12
  1027. X12,13
  1028. X13,10
  1029. X0,4
  1030. X1,5
  1031. X2,6
  1032. X3,10
  1033. X9,13
  1034. X8,12
  1035. X7,11
  1036. X
  1037. X5, 17, 24
  1038. X-.5, -.5, .5
  1039. X.5, .5, .5
  1040. X-.5, -.5, -.5
  1041. X-.5, .5, -.5
  1042. X.5, .5, -.5
  1043. X0, 0, 1
  1044. X1, 0, 1
  1045. X1, 1, 1
  1046. X0, 1, 1
  1047. X0, -1, 1
  1048. X-1, -1, 1
  1049. X-1, 0, 1
  1050. X0, 0, 0
  1051. X0, 1, 0
  1052. X-1, 1, 0
  1053. X-1, 0, 0
  1054. X0, 0, -1
  1055. X1, 0, -1
  1056. X1, 1, -1
  1057. X-1, 1, -1
  1058. X-1, -1, -1
  1059. X0, -1, -1
  1060. X1,2
  1061. X2,3
  1062. X3,4
  1063. X4,5
  1064. X5,6
  1065. X6,1
  1066. X7,8
  1067. X8,9
  1068. X9,10
  1069. X10,7
  1070. X11,12
  1071. X12,13
  1072. X13,14
  1073. X14,15
  1074. X15,16
  1075. X16,11
  1076. X0,11
  1077. X1,12
  1078. X2,13
  1079. X3,8
  1080. X9,14
  1081. X6,10
  1082. X5,15
  1083. X4,16
  1084. X
  1085. X5, 18, 27
  1086. X-.5, -.5, .5
  1087. X-.5, -.5, -.5
  1088. X-.5, .5, -.5
  1089. X.5, .5, -.5
  1090. X.5, 1.5, -.5
  1091. X0, 0, 1
  1092. X-1, 0, 1
  1093. X-1, -1, 1
  1094. X0, -1, 1
  1095. X-1, 0, 0
  1096. X1, 0, 0
  1097. X1, 2, 0
  1098. X0, 2, 0
  1099. X0, 1, 0
  1100. X-1, 1, 0
  1101. X-1, -1, -1
  1102. X0, -1, -1
  1103. X0, 0, -1
  1104. X1, 0, -1
  1105. X1, 2, -1
  1106. X0, 2, -1
  1107. X0, 1, -1
  1108. X-1, 1, -1
  1109. X0,1
  1110. X1,2
  1111. X2,3
  1112. X3,0
  1113. X4,5
  1114. X5,6
  1115. X6,7
  1116. X7,8
  1117. X8,9
  1118. X9,4
  1119. X10,11
  1120. X11,12
  1121. X12,13
  1122. X13,14
  1123. X14,15
  1124. X15,16
  1125. X16,17
  1126. X17,10
  1127. X0,12
  1128. X1,4
  1129. X2,10
  1130. X3,11
  1131. X5,13
  1132. X6,14
  1133. X7,15
  1134. X8,16
  1135. X9,17
  1136. X
  1137. X5, 18, 27
  1138. X.5, .5, .5
  1139. X-.5, -.5, -.5
  1140. X-.5, .5, -.5
  1141. X.5, .5, -.5
  1142. X.5, 1.5, -.5
  1143. X0, 0, 1
  1144. X1, 0, 1
  1145. X1, 1, 1
  1146. X0, 1, 1
  1147. X-1, -1, 0
  1148. X0, -1, 0
  1149. X1, 1, 0
  1150. X1, 2, 0
  1151. X0, 2, 0
  1152. X-1, 1, 0
  1153. X-1, -1, -1
  1154. X0, -1, -1
  1155. X0, 0, -1
  1156. X1, 0, -1
  1157. X1, 2, -1
  1158. X0, 2, -1
  1159. X0, 1, -1
  1160. X-1, 1, -1
  1161. X0,1
  1162. X1,2
  1163. X2,3
  1164. X3,0
  1165. X4,5
  1166. X5,8
  1167. X8,7
  1168. X7,6
  1169. X6,9
  1170. X9,4
  1171. X10,11
  1172. X11,12
  1173. X12,13
  1174. X13,14
  1175. X14,15
  1176. X15,16
  1177. X16,17
  1178. X17,10
  1179. X0,12
  1180. X1,13
  1181. X2,6
  1182. X7,14
  1183. X8,15
  1184. X3,16
  1185. X9,17
  1186. X4,10
  1187. X5,11
  1188. X
  1189. X5, 16, 24
  1190. X-.5, .5, -.5
  1191. X.5, .5, -.5
  1192. X.5, -.5, -.5
  1193. X.5, -.5, .5
  1194. X1.5, -.5, .5
  1195. X0, -1, 1
  1196. X2, -1, 1
  1197. X2, 0, 1
  1198. X0, 0, 1
  1199. X1, -1, 0
  1200. X2, -1, 0
  1201. X2, 0, 0
  1202. X-1, 0, 0
  1203. X-1, 1, 0
  1204. X1, 1, 0
  1205. X0, -1, -1
  1206. X1, -1, -1
  1207. X1, 1, -1
  1208. X-1, 1, -1
  1209. X-1, 0, -1
  1210. X0, 0, -1
  1211. X0,1
  1212. X1,2
  1213. X2,3
  1214. X3,0
  1215. X4,5
  1216. X5,6
  1217. X6,7
  1218. X7,8
  1219. X8,9
  1220. X9,4
  1221. X10,11
  1222. X11,12
  1223. X12,13
  1224. X13,14
  1225. X14,15
  1226. X15,10
  1227. X0,10
  1228. X4,11
  1229. X1,5
  1230. X2,6
  1231. X3,15
  1232. X9,12
  1233. X8,13
  1234. X7,14
  1235. X
  1236. X5, 24, 36
  1237. X.5, .5, -.5
  1238. X-.5, .5, -.5
  1239. X.5, -.5, -.5
  1240. X1.5, .5, -.5
  1241. X.5, 1.5, -.5
  1242. X0, 0, 0
  1243. X0, -1, 0
  1244. X1, -1, 0
  1245. X1, 0, 0
  1246. X2, 0, 0
  1247. X2, 1, 0
  1248. X1, 1, 0
  1249. X1, 2, 0
  1250. X0, 2, 0
  1251. X0, 1, 0
  1252. X-1, 1, 0
  1253. X-1, 0, 0
  1254. X0, 0, -1
  1255. X0, -1, -1
  1256. X1, -1, -1
  1257. X1, 0, -1
  1258. X2, 0, -1
  1259. X2, 1, -1
  1260. X1, 1, -1
  1261. X1, 2, -1
  1262. X0, 2, -1
  1263. X0, 1, -1
  1264. X-1, 1, -1
  1265. X-1, 0, -1
  1266. X0,1
  1267. X1,2
  1268. X2,3
  1269. X3,4
  1270. X4,5
  1271. X5,6
  1272. X6,7
  1273. X7,8
  1274. X8,9
  1275. X9,10
  1276. X10,11
  1277. X11,0
  1278. X12,13
  1279. X13,14
  1280. X14,15
  1281. X15,16
  1282. X16,17
  1283. X17,18
  1284. X18,19
  1285. X19,20
  1286. X20,21
  1287. X21,22
  1288. X22,23
  1289. X23,12
  1290. X0,12
  1291. X1,13
  1292. X2,14
  1293. X3,15
  1294. X4,16
  1295. X5,17
  1296. X6,18
  1297. X7,19
  1298. X8,20
  1299. X9,21
  1300. X10,22
  1301. X11,23
  1302. X
  1303. X5, 12, 18
  1304. X-.5, -.5, -.5
  1305. X-.5, .5, -.5
  1306. X.5, .5, -.5
  1307. X1.5, .5, -.5
  1308. X2.5, .5, -.5
  1309. X0, 0, 0
  1310. X3, 0, 0
  1311. X3, 1, 0
  1312. X-1, 1, 0
  1313. X-1, -1, 0
  1314. X0, -1, 0
  1315. X0, 0, -1
  1316. X3, 0, -1
  1317. X3, 1, -1
  1318. X-1, 1, -1
  1319. X-1, -1, -1
  1320. X0, -1, -1
  1321. X0,1
  1322. X1,2
  1323. X2,3
  1324. X3,4
  1325. X4,5
  1326. X5,0
  1327. X6,7
  1328. X7,8
  1329. X8,9
  1330. X9,10
  1331. X10,11
  1332. X11,6
  1333. X0,6
  1334. X1,7
  1335. X2,8
  1336. X3,9
  1337. X4,10
  1338. X5,11
  1339. X
  1340. X5, 8, 12
  1341. X.5, -1.5, -.5
  1342. X.5, -.5, -.5
  1343. X.5, .5, -.5
  1344. X.5, 1.5, -.5
  1345. X.5, 2.5, -.5
  1346. X0, -2, 0
  1347. X1, -2, 0
  1348. X1, 3, 0
  1349. X0, 3, 0
  1350. X0, -2, -1
  1351. X1, -2, -1
  1352. X1, 3, -1
  1353. X0, 3, -1
  1354. X0,1
  1355. X1,2
  1356. X2,3
  1357. X3,0
  1358. X4,5
  1359. X5,6
  1360. X6,7
  1361. X7,4
  1362. X0,4
  1363. X1,5
  1364. X2,6
  1365. X3,7
  1366. X
  1367. X5, 16, 24
  1368. X-.5, -.5, -.5
  1369. X-.5, .5, -.5
  1370. X.5, .5, -.5
  1371. X1.5, .5, -.5
  1372. X1.5, 1.5, -.5
  1373. X0, 0, 0
  1374. X2, 0, 0
  1375. X2, 2, 0
  1376. X1, 2, 0
  1377. X1, 1, 0
  1378. X-1, 1, 0
  1379. X-1, -1, 0
  1380. X0, -1, 0
  1381. X0, 0, -1
  1382. X2, 0, -1
  1383. X2, 2, -1
  1384. X1, 2, -1
  1385. X1, 1, -1
  1386. X-1, 1, -1
  1387. X-1, -1, -1
  1388. X0, -1, -1
  1389. X0,1
  1390. X1,2
  1391. X2,3
  1392. X3,4
  1393. X4,5
  1394. X5,6
  1395. X6,7
  1396. X7,0
  1397. X8,9
  1398. X9,10
  1399. X10,11
  1400. X11,12
  1401. X12,13
  1402. X13,14
  1403. X14,15
  1404. X15,8
  1405. X0,8
  1406. X1,9
  1407. X2,10
  1408. X3,11
  1409. X4,12
  1410. X5,13
  1411. X6,14
  1412. X7,15
  1413. X
  1414. X5, 16, 24
  1415. X-.5, -1.5, -.5
  1416. X-.5, -.5, -.5
  1417. X.5, -.5, -.5
  1418. X.5, .5, -.5
  1419. X.5, 1.5, -.5
  1420. X0, 0, 0
  1421. X-1, 0, 0
  1422. X-1, -2, 0
  1423. X0, -2, 0
  1424. X0, -1, 0
  1425. X1, -1, 0
  1426. X1, 2, 0
  1427. X0, 2, 0
  1428. X0, 0, -1
  1429. X-1, 0, -1
  1430. X-1, -2, -1
  1431. X0, -2, -1
  1432. X0, -1, -1
  1433. X1, -1, -1
  1434. X1, 2, -1
  1435. X0, 2, -1
  1436. X0,1
  1437. X1,2
  1438. X2,3
  1439. X3,4
  1440. X4,5
  1441. X5,6
  1442. X6,7
  1443. X7,0
  1444. X8,9
  1445. X9,10
  1446. X10,11
  1447. X11,12
  1448. X12,13
  1449. X13,14
  1450. X14,15
  1451. X15,8
  1452. X0,8
  1453. X1,9
  1454. X2,10
  1455. X3,11
  1456. X4,12
  1457. X5,13
  1458. X6,14
  1459. X7,15
  1460. X
  1461. X5, 16, 24
  1462. X-.5, -1.5, -.5
  1463. X-.5, -.5, -.5
  1464. X-.5, .5, -.5
  1465. X-.5, 1.5, -.5
  1466. X.5, -.5, -.5
  1467. X0, 0, 0
  1468. X0, 2, 0
  1469. X-1, 2, 0
  1470. X-1, -2, 0
  1471. X0, -2, 0
  1472. X0, -1, 0
  1473. X1, -1, 0
  1474. X1, 0, 0
  1475. X0, 0, -1
  1476. X0, 2, -1
  1477. X-1, 2, -1
  1478. X-1, -2, -1
  1479. X0, -2, -1
  1480. X0, -1, -1
  1481. X1, -1, -1
  1482. X1, 0, -1
  1483. X0,1
  1484. X1,2
  1485. X2,3
  1486. X3,4
  1487. X4,5
  1488. X5,6
  1489. X6,7
  1490. X7,0
  1491. X8,9
  1492. X9,10
  1493. X10,11
  1494. X11,12
  1495. X12,13
  1496. X13,14
  1497. X14,15
  1498. X15,8
  1499. X0,8
  1500. X1,9
  1501. X2,10
  1502. X3,11
  1503. X4,12
  1504. X5,13
  1505. X6,14
  1506. X7,15
  1507. X
  1508. X5, 20, 30
  1509. X.5, .5, -.5
  1510. X-.5, .5, -.5
  1511. X.5, -.5, -.5
  1512. X1.5, -.5, -.5
  1513. X.5, 1.5, -.5
  1514. X0, 0, 0
  1515. X0, -1, 0
  1516. X2, -1, 0
  1517. X2, 0, 0
  1518. X1, 0, 0
  1519. X1, 2, 0
  1520. X0, 2, 0
  1521. X0, 1, 0
  1522. X-1, 1, 0
  1523. X-1, 0, 0
  1524. X0, 0, -1
  1525. X0, -1, -1
  1526. X2, -1, -1
  1527. X2, 0, -1
  1528. X1, 0, -1
  1529. X1, 2, -1
  1530. X0, 2, -1
  1531. X0, 1, -1
  1532. X-1, 1, -1
  1533. X-1, 0, -1
  1534. X0,1
  1535. X1,2
  1536. X2,3
  1537. X3,4
  1538. X4,5
  1539. X5,6
  1540. X6,7
  1541. X7,8
  1542. X8,9
  1543. X9,0
  1544. X10,11
  1545. X11,12
  1546. X12,13
  1547. X13,14
  1548. X14,15
  1549. X15,16
  1550. X16,17
  1551. X17,18
  1552. X18,19
  1553. X19,10
  1554. X0,10
  1555. X1,11
  1556. X2,12
  1557. X3,13
  1558. X4,14
  1559. X5,15
  1560. X6,16
  1561. X7,17
  1562. X8,18
  1563. X9,19
  1564. X
  1565. X5, 16, 24
  1566. X-.5, -.5, -.5
  1567. X.5, -.5, -.5
  1568. X1.5, -.5, -.5
  1569. X.5, .5, -.5
  1570. X.5, 1.5, -.5
  1571. X0, 0, 0
  1572. X-1, 0, 0
  1573. X-1, -1, 0
  1574. X2, -1, 0
  1575. X2, 0, 0
  1576. X1, 0, 0
  1577. X1, 2, 0
  1578. X0, 2, 0
  1579. X0, 0, -1
  1580. X-1, 0, -1
  1581. X-1, -1, -1
  1582. X2, -1, -1
  1583. X2, 0, -1
  1584. X1, 0, -1
  1585. X1, 2, -1
  1586. X0, 2, -1
  1587. X0,1
  1588. X1,2
  1589. X2,3
  1590. X3,4
  1591. X4,5
  1592. X5,6
  1593. X6,7
  1594. X7,0
  1595. X8,9
  1596. X9,10
  1597. X10,11
  1598. X11,12
  1599. X12,13
  1600. X13,14
  1601. X14,15
  1602. X15,8
  1603. X0,8
  1604. X1,9
  1605. X2,10
  1606. X3,11
  1607. X4,12
  1608. X5,13
  1609. X6,14
  1610. X7,15
  1611. X
  1612. X5, 12, 18
  1613. X.5, .5, -.5
  1614. X-.5, -.5, -.5
  1615. X.5, -.5, -.5
  1616. X-.5, .5, -.5
  1617. X1.5, -.5, -.5
  1618. X-1, -1, 0
  1619. X2, -1, 0
  1620. X2, 0, 0
  1621. X1, 0, 0
  1622. X1, 1, 0
  1623. X-1, 1, 0
  1624. X-1, -1, -1
  1625. X2, -1, -1
  1626. X2, 0, -1
  1627. X1, 0, -1
  1628. X1, 1, -1
  1629. X-1, 1, -1
  1630. X0,1
  1631. X1,2
  1632. X2,3
  1633. X3,4
  1634. X4,5
  1635. X5,0
  1636. X6,7
  1637. X7,8
  1638. X8,9
  1639. X9,10
  1640. X10,11
  1641. X11,6
  1642. X0,6
  1643. X1,7
  1644. X2,8
  1645. X3,9
  1646. X4,10
  1647. X5,11
  1648. X
  1649. X5, 20, 30
  1650. X-1.5, -.5, -.5
  1651. X-1.5, .5, -.5
  1652. X-.5, .5, -.5
  1653. X-.5, 1.5, -.5
  1654. X.5, 1.5, -.5
  1655. X0, 0, 0
  1656. X0, 1, 0
  1657. X1, 1, 0
  1658. X1, 2, 0
  1659. X-1, 2, 0
  1660. X-1, 1, 0
  1661. X-2, 1, 0
  1662. X-2, -1, 0
  1663. X-1, -1, 0
  1664. X-1, 0, 0
  1665. X0, 0, -1
  1666. X0, 1, -1
  1667. X1, 1, -1
  1668. X1, 2, -1
  1669. X-1, 2, -1
  1670. X-1, 1, -1
  1671. X-2, 1, -1
  1672. X-2, -1, -1
  1673. X-1, -1, -1
  1674. X-1, 0, -1
  1675. X0,1
  1676. X1,2
  1677. X2,3
  1678. X3,4
  1679. X4,5
  1680. X5,6
  1681. X6,7
  1682. X7,8
  1683. X8,9
  1684. X9,0
  1685. X10,11
  1686. X11,12
  1687. X12,13
  1688. X13,14
  1689. X14,15
  1690. X15,16
  1691. X16,17
  1692. X17,18
  1693. X18,19
  1694. X19,10
  1695. X0,10
  1696. X1,11
  1697. X2,12
  1698. X3,13
  1699. X4,14
  1700. X5,15
  1701. X6,16
  1702. X7,17
  1703. X8,18
  1704. X9,19
  1705. X
  1706. X5, 12, 18
  1707. X-.5, -1.5, -.5
  1708. X-.5, -.5, -.5
  1709. X-.5, .5, -.5
  1710. X.5, .5, -.5
  1711. X1.5, .5, -.5
  1712. X0, 0, 0
  1713. X2, 0, 0
  1714. X2, 1, 0
  1715. X-1, 1, 0
  1716. X-1, -2, 0
  1717. X0, -2, 0
  1718. X0, 0, -1
  1719. X2, 0, -1
  1720. X2, 1, -1
  1721. X-1, 1, -1
  1722. X-1, -2, -1
  1723. X0, -2, -1
  1724. X0,1
  1725. X1,2
  1726. X2,3
  1727. X3,4
  1728. X4,5
  1729. X5,0
  1730. X6,7
  1731. X7,8
  1732. X8,9
  1733. X9,10
  1734. X10,11
  1735. X11,6
  1736. X0,6
  1737. X1,7
  1738. X2,8
  1739. X3,9
  1740. X4,10
  1741. X5,11
  1742. X
  1743. X5, 16, 24
  1744. X-.5, -.5, -.5
  1745. X-.5, .5, -.5
  1746. X.5, .5, -.5
  1747. X1.5, .5, -.5
  1748. X1.5, -.5, -.5
  1749. X0, 0, 0
  1750. X1, 0, 0
  1751. X1, -1, 0
  1752. X2, -1, 0
  1753. X2, 1, 0
  1754. X-1, 1, 0
  1755. X-1, -1, 0
  1756. X0, -1, 0
  1757. X0, 0, -1
  1758. X1, 0, -1
  1759. X1, -1, -1
  1760. X2, -1, -1
  1761. X2, 1, -1
  1762. X-1, 1, -1
  1763. X-1, -1, -1
  1764. X0, -1, -1
  1765. X0,1
  1766. X1,2
  1767. X2,3
  1768. X3,4
  1769. X4,5
  1770. X5,6
  1771. X6,7
  1772. X7,0
  1773. X8,9
  1774. X9,10
  1775. X10,11
  1776. X11,12
  1777. X12,13
  1778. X13,14
  1779. X14,15
  1780. X15,8
  1781. X0,8
  1782. X1,9
  1783. X2,10
  1784. X3,11
  1785. X4,12
  1786. X5,13
  1787. X6,14
  1788. X7,15
  1789. END_OF_FILE
  1790. if test 8168 -ne `wc -c <'spatial/spatial.shp'`; then
  1791.     echo shar: \"'spatial/spatial.shp'\" unpacked with wrong size!
  1792. fi
  1793. # end of 'spatial/spatial.shp'
  1794. fi
  1795. if test -f 'spheral/disp.c' -a "${1}" != "-c" ; then 
  1796.   echo shar: Will not clobber existing file \"'spheral/disp.c'\"
  1797. else
  1798. echo shar: Extracting \"'spheral/disp.c'\" \(11465 characters\)
  1799. sed "s/^X//" >'spheral/disp.c' <<'END_OF_FILE'
  1800. X/* (C) Copyright 1991 Andrew Plotkin. Permission is
  1801. X given to copy and use, as long as this copyright
  1802. X notice is retained. */
  1803. X
  1804. X#include <stdio.h>
  1805. X#include <X11/Xlib.h>
  1806. X#include <X11/Xutil.h>
  1807. X#include "spheral.h"
  1808. X
  1809. XDisplay *dpy;
  1810. XWindow win;
  1811. XPixmap backpm, fieldpm, piecepm;
  1812. XGC gcblack, gcwhite, gcinv, gccopy, gcline,
  1813. X  gcfield, gcocto, gcadd, gcballs[16],
  1814. X  gcpiece1, gcpiece0, gcpieceadd;
  1815. Xint scn;
  1816. Xint scndepth;
  1817. X
  1818. Xpiecelist pieces[MAXPIECES];
  1819. X
  1820. Xshort numpieces;
  1821. Xshort curpiece;
  1822. X
  1823. Xint dispx, dispy; /* size of window */
  1824. Xint sshapx1, sshapx2, sshapy1, sshapy2;
  1825. X/* size of rectangle that contains current shape */
  1826. Xint bbackx1, bbackx2, bbacky1, bbacky2;
  1827. X/* coords of rectangle of backpm that is usable */
  1828. Xint ddispx1, ddispx2, ddispy1, ddispy2;
  1829. X/* coords of rectangle of display that is
  1830. X different from fieldpm */
  1831. X
  1832. Xextern void draw_curpiece(), measure_curpiece(), setup_grey();
  1833. X
  1834. Xvoid xinit() /* using dispx, dispy */
  1835. X{
  1836. X    register int ix;
  1837. X    XSetWindowAttributes attr;
  1838. X    XGCValues gcvalues;
  1839. X    static char dashes[2] = {1, 1};
  1840. X    static char widedashes[2] = {1, 3};
  1841. X    XSizeHints hints;
  1842. X
  1843. X    dpy = XOpenDisplay((char *) NULL);
  1844. X    if ((Display *) NULL == dpy) {
  1845. X    fprintf(stderr, "spheral: could not open display.\n");
  1846. X    exit(-1);
  1847. X    }
  1848. X
  1849. X    scn = DefaultScreen(dpy);
  1850. X    scndepth = DefaultDepth(dpy, scn);
  1851. X    if (scndepth==1) monomode = 1;
  1852. X
  1853. X    win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy),
  1854. X    100, 100, dispx, dispy, 1,
  1855. X    BlackPixel(dpy, scn), WhitePixel(dpy, scn));
  1856. X
  1857. X    hints.min_width = 100;
  1858. X    hints.min_height = 100;
  1859. X    hints.width = dispx;
  1860. X    hints.height = dispy;
  1861. X    hints.flags = PMinSize | PSize;
  1862. X    XSetWMNormalHints(dpy, win, &hints);
  1863. X    {
  1864. X    XWMHints wmhints;
  1865. X    wmhints.flags = InputHint;
  1866. X    wmhints.input = True;
  1867. X    XSetWMHints(dpy, win, &wmhints);
  1868. X    }
  1869. X
  1870. X    XStoreName(dpy, win, "Spheral");
  1871. X
  1872. X    attr.event_mask = (KeyPressMask | ExposureMask
  1873. X               | StructureNotifyMask);
  1874. X    XChangeWindowAttributes(dpy, win, CWEventMask, &attr);
  1875. X
  1876. X    XSetWindowBackground(dpy, win, BlackPixel(dpy, scn));
  1877. X
  1878. X    XMapWindow(dpy, win);
  1879. X
  1880. X    gcvalues.foreground = WhitePixel(dpy, scn);
  1881. X    gcvalues.background = BlackPixel(dpy, scn);
  1882. X    gcwhite = XCreateGC(dpy, win, GCForeground|GCBackground,
  1883. X            &gcvalues);
  1884. X
  1885. X    gcvalues.line_style = LineOnOffDash;
  1886. X    gcfield = XCreateGC(dpy, win, GCForeground|GCLineStyle,
  1887. X            &gcvalues);
  1888. X    XSetDashes(dpy, gcfield, 0, dashes, 2);
  1889. X    gcocto = XCreateGC(dpy, win, GCForeground|GCLineStyle,
  1890. X               &gcvalues);
  1891. X    XSetDashes(dpy, gcocto, 0, widedashes, 2);
  1892. X
  1893. X    gcvalues.line_width = 2;
  1894. X    gcline = XCreateGC(dpy, win, GCForeground|GCLineWidth,
  1895. X               &gcvalues);
  1896. X
  1897. X    if (WhitePixel(dpy, scn))
  1898. X    gcvalues.function = GXor;
  1899. X    else
  1900. X    gcvalues.function = GXand;
  1901. X    gcadd = XCreateGC(dpy, win, GCForeground|GCBackground|GCFunction,
  1902. X              &gcvalues);
  1903. X    XSetGraphicsExposures(dpy, gcadd, 0);
  1904. X
  1905. X    gcvalues.function = GXinvert;
  1906. X    gcinv = XCreateGC(dpy, win, GCForeground|GCFunction,
  1907. X              &gcvalues);
  1908. X
  1909. X    gcvalues.foreground = BlackPixel(dpy, scn);
  1910. X    gcblack = XCreateGC(dpy, win, GCForeground, &gcvalues);
  1911. X
  1912. X    gcvalues.background = WhitePixel(dpy, scn);
  1913. X    gccopy = XCreateGC(dpy, win, GCForeground|GCBackground,
  1914. X               &gcvalues);
  1915. X    XSetGraphicsExposures(dpy, gccopy, 0);
  1916. X
  1917. X    setup_grey();
  1918. X
  1919. X    backpm = XCreatePixmap(dpy, win, dispx, dispy, scndepth);   
  1920. X    fieldpm = XCreatePixmap(dpy, win, dispx, dispy, scndepth);
  1921. X    if (monomode) {
  1922. X    piecepm = NULL;
  1923. X    gcpiece0 = NULL;
  1924. X    gcpiece1 = NULL;
  1925. X    gcpieceadd = NULL;
  1926. X    }
  1927. X    else {
  1928. X    piecepm = XCreatePixmap(dpy, win, dispx, dispy, 1);
  1929. X    gcvalues.foreground = 0;
  1930. X    gcpiece0 = XCreateGC(dpy, piecepm, GCForeground,
  1931. X        &gcvalues);
  1932. X    gcvalues.foreground = 1;
  1933. X    gcpiece1 = XCreateGC(dpy, piecepm, GCForeground,
  1934. X        &gcvalues);
  1935. X    gcvalues.foreground = WhitePixel(dpy, scn);
  1936. X    gcvalues.background = BlackPixel(dpy, scn);
  1937. X    gcvalues.function = GXand;
  1938. X    gcpieceadd = XCreateGC(dpy, win,
  1939. X        GCForeground|GCBackground|GCFunction,
  1940. X        &gcvalues);
  1941. X    XSetGraphicsExposures(dpy, gcpieceadd, 0);
  1942. X    }
  1943. X}
  1944. X
  1945. Xvoid setup_fieldpm() /* clear, draw field box and side text.
  1946. X Also set bback{x,y}{1,2} to window size */
  1947. X{
  1948. X    register int ix, iz;
  1949. X
  1950. X    XFillRectangle(dpy, fieldpm, gcblack, 0, 0, dispx, dispy);
  1951. X    XDrawImageString(dpy, fieldpm, gcwhite, 20, 20, "Score: ", 7); 
  1952. X
  1953. X    /* draw triangles (sort of) parallel to screen */
  1954. X    for (iz=fieldz-1; iz<fieldz; iz++) {
  1955. X    XDrawLine(dpy, fieldpm, gcfield, fieldpts[0][0][iz].x,
  1956. X          fieldpts[0][0][iz].y, fieldpts[fieldx-1][0][iz].x,
  1957. X          fieldpts[fieldx-1][0][iz].y);
  1958. X    XDrawLine(dpy, fieldpm, gcfield, fieldpts[0][0][iz].x,
  1959. X          fieldpts[0][0][iz].y, fieldpts[0][fieldx-1][iz].x,
  1960. X          fieldpts[0][fieldx-1][iz].y);
  1961. X    XDrawLine(dpy, fieldpm, gcfield, fieldpts[fieldx-1][0][iz].x,
  1962. X          fieldpts[fieldx-1][0][iz].y, fieldpts[0][fieldx-1][iz].x,
  1963. X          fieldpts[0][fieldx-1][iz].y);
  1964. X    };
  1965. X
  1966. X    /* draw perpendiculars to screen */
  1967. X    for (ix=0; ix<fieldx; ix++) {
  1968. X    XDrawLine(dpy, fieldpm, gcfield, fieldpts[ix][0][0].x,
  1969. X          fieldpts[ix][0][0].y, fieldpts[ix][0][fieldz-1].x,
  1970. X          fieldpts[ix][0][fieldz-1].y);
  1971. X    XDrawLine(dpy, fieldpm, gcfield, fieldpts[0][ix][0].x,
  1972. X          fieldpts[0][ix][0].y, fieldpts[0][ix][fieldz-1].x,
  1973. X          fieldpts[0][ix][fieldz-1].y);
  1974. X    XDrawLine(dpy, fieldpm, gcfield, fieldpts[ix][fieldx-1-ix][0].x,
  1975. X          fieldpts[ix][fieldx-1-ix][0].y,
  1976. X          fieldpts[ix][fieldx-1-ix][fieldz-1].x,
  1977. X          fieldpts[ix][fieldx-1-ix][fieldz-1].y);
  1978. X    }
  1979. X
  1980. X    for (ix=0; ix<fieldx-1; ix++) {
  1981. X    XDrawLine(dpy, fieldpm, gcfield, fieldpts[ix+1][0][0].x,
  1982. X          fieldpts[ix+1][0][0].y, fieldpts[0][ix+1][0].x,
  1983. X          fieldpts[0][ix+1][0].y);
  1984. X    XDrawLine(dpy, fieldpm, gcfield, fieldpts[ix][0][0].x,
  1985. X          fieldpts[ix][0][0].y, fieldpts[ix][fieldx-ix-1][0].x,
  1986. X          fieldpts[ix][fieldx-ix-1][0].y);
  1987. X    XDrawLine(dpy, fieldpm, gcfield, fieldpts[0][ix][0].x,
  1988. X          fieldpts[0][ix][0].y, fieldpts[fieldx-ix-1][ix][0].x,
  1989. X          fieldpts[fieldx-ix-1][ix][0].y);
  1990. X    }
  1991. X
  1992. X    bbackx1 = dispx-1;
  1993. X    bbackx2 = 0;
  1994. X
  1995. X    ddispx1 = 0;
  1996. X    ddispx2 = dispx-1;
  1997. X    ddispy1 = 0;
  1998. X    ddispy2 = dispy-1;
  1999. X    /*meteroldlev = 0;*/
  2000. X}
  2001. X
  2002. Xvoid setup_backpm()
  2003. X/* put stuff on the backpm, so that bback is the smallest
  2004. X area different from fieldpm (but larger than ddisp), and
  2005. X those together are an accurate picture of the board */
  2006. X{
  2007. X    piecesum psum;
  2008. X    register int ix;
  2009. X    int rad;
  2010. X
  2011. X    /* measure piece, store max{sshap, ddisp} in bback limits */
  2012. X    measure_curpiece(&psum);
  2013. X    sshapx1 = dispx;
  2014. X    sshapx2 = 0;
  2015. X    sshapy1 = dispy;
  2016. X    sshapy2 = 0;
  2017. X    for (ix=0; ix<psum.numballs; ix++) {
  2018. X    rad = psum.rad[ix];
  2019. X    if (psum.p[ix].x-rad < sshapx1) sshapx1 = psum.p[ix].x-rad;
  2020. X    if (psum.p[ix].x+rad > sshapx2) sshapx2 = psum.p[ix].x+rad;
  2021. X    if (psum.p[ix].y-rad < sshapy1) sshapy1 = psum.p[ix].y-rad;
  2022. X    if (psum.p[ix].y+rad > sshapy2) sshapy2 = psum.p[ix].y+rad;
  2023. X    }
  2024. X    sshapx1 -= 2;
  2025. X    sshapy1 -= 2;
  2026. X    sshapx2 += 2;
  2027. X    sshapy2 += 2;
  2028. X
  2029. X    bbackx1 = (sshapx1 < ddispx1) ? sshapx1 : ddispx1;
  2030. X    bbacky1 = (sshapy1 < ddispy1) ? sshapy1 : ddispy1;
  2031. X    bbackx2 = (sshapx2 > ddispx2) ? sshapx2 : ddispx2;
  2032. X    bbacky2 = (sshapy2 > ddispy2) ? sshapy2 : ddispy2;
  2033. X
  2034. X    if (monomode) {
  2035. X    /* clear backpm, using bback limits */
  2036. X    XFillRectangle(dpy, backpm, gcblack, bbackx1, bbacky1,
  2037. X        bbackx2-bbackx1+1, bbacky2-bbacky1+1);
  2038. X    /* draw piece on backpm */
  2039. X    draw_curpiece(backpm, &psum, gcwhite, gcblack);
  2040. X
  2041. X    /* overlay fieldpm on backpm, using bback limits */
  2042. X    XCopyArea(dpy, fieldpm, backpm, gcadd, bbackx1, bbacky1,
  2043. X        bbackx2-bbackx1+1, bbacky2-bbacky1+1, bbackx1, bbacky1);
  2044. X    }
  2045. X    else {
  2046. X    /* clear piecepm, using bback limits */
  2047. X    XFillRectangle(dpy, piecepm, gcpiece0, bbackx1, bbacky1,
  2048. X        bbackx2-bbackx1+1, bbacky2-bbacky1+1);
  2049. X    /* draw piece on piecepm */
  2050. X    draw_curpiece(piecepm, &psum, gcpiece1, gcpiece0);
  2051. X
  2052. X    /* copy fieldpm to backpm, using bback limits */
  2053. X    XCopyArea(dpy, fieldpm, backpm, gccopy, bbackx1, bbacky1,
  2054. X        bbackx2-bbackx1+1, bbacky2-bbacky1+1, bbackx1, bbacky1);
  2055. X    XCopyPlane(dpy, piecepm, backpm, gcpieceadd, bbackx1, bbacky1,
  2056. X        bbackx2-bbackx1+1, bbacky2-bbacky1+1,
  2057. X        bbackx1, bbacky1, 1);
  2058. X    }
  2059. X}
  2060. X
  2061. Xvoid back_to_disp(all)
  2062. Xint all; 
  2063. X{
  2064. X    if (all || (bbackx2==0)) {
  2065. X    /* copy fieldpm to display, then backpm
  2066. X     to display (using sshap), then set ddisp to sshap */
  2067. X    XCopyArea(dpy, fieldpm, win, gccopy, 0, 0, dispx, dispy, 0, 0);
  2068. X    XCopyArea(dpy, backpm, win, gccopy, sshapx1, sshapy1,
  2069. X          sshapx2-sshapx1+1, sshapy2-sshapy1+1, sshapx1, sshapy1);
  2070. X    ddispx1 = sshapx1;
  2071. X    ddispy1 = sshapy1;
  2072. X    ddispx2 = sshapx2;
  2073. X    ddispy2 = sshapy2;
  2074. X    }
  2075. X    else {
  2076. X    /* copy from backpm to display (using bback) */
  2077. X    XCopyArea(dpy, backpm, win, gccopy, bbackx1, bbacky1,
  2078. X          bbackx2-bbackx1+1, bbacky2-bbacky1+1, bbackx1, bbacky1);
  2079. X
  2080. X    /* set ddisp limits to ddisp limits; */
  2081. X    ddispx1 = sshapx1;
  2082. X    ddispy1 = sshapy1;
  2083. X    ddispx2 = sshapx2;
  2084. X    ddispy2 = sshapy2;
  2085. X
  2086. X    /*if (meter_b_d) {
  2087. X        XCopyArea(dpy, backpm, win, gccopy, meterx, metery,
  2088. X              metersize*fieldz+1, 21, meterx, metery);
  2089. X        if (stereo) {
  2090. X        XCopyArea(dpy, backpm, win, gccopy, meterx2, metery,
  2091. X              metersize*fieldz+1, 21, meterx2, metery);
  2092. X        }
  2093. X        meter_b_d = 0;
  2094. X    }*/
  2095. X
  2096. X    }
  2097. X}
  2098. X
  2099. Xvoid draw_curpiece(drw, psum, gcon, gcoff) /* just that */
  2100. XDrawable drw;
  2101. Xpiecesum *psum;
  2102. XGC gcon, gcoff;
  2103. X{
  2104. X    register int ix;
  2105. X    int rad, radx, rady, lradx, lrady;
  2106. X
  2107. X    for (ix=0; ix<psum->numballs; ix++) {
  2108. X    rad = psum->rad[ix];
  2109. X    radx = (int)(rad*psum->scalex);
  2110. X    if (radx < 3) radx=3;
  2111. X    rady = (int)(rad*psum->scaley);
  2112. X    if (rady < 3) rady=3;
  2113. X
  2114. X    XFillArc(dpy, drw, gcon, psum->p[ix].x-radx,
  2115. X         psum->p[ix].y-rady, radx*2, rady*2, 0, 23040); 
  2116. X    XFillArc(dpy, drw, gcoff, psum->p[ix].x-radx+2,
  2117. X         psum->p[ix].y-rady+2, radx*2-4, rady*2-4, 0, 23040); 
  2118. X
  2119. X    /*XFillArc(dpy, drw, gcoff, psum->p[ix].x-rad,
  2120. X     psum->p[ix].y-rad, rad*2, rad*2, 0, 23040); 
  2121. X     XDrawArc(dpy, drw, gcon, psum->p[ix].x-rad,
  2122. X     psum->p[ix].y-rad, rad*2, rad*2, 0, 23040); */
  2123. X
  2124. X    /*XDrawArc(dpy, drw, gcon, psum->p[ix].x-rad/2,
  2125. X     psum->p[ix].y-rad, rad, rad*2, 0, 23040); 
  2126. X     XDrawArc(dpy, drw, gcon, psum->p[ix].x-rad,
  2127. X     psum->p[ix].y-rad/2, rad*2, rad, 0, 23040); */
  2128. X
  2129. X    lradx = radx/16;
  2130. X    if (lradx < 2) lradx = 2;
  2131. X    lrady = rady/16;
  2132. X    if (lrady < 2) lrady = 2;
  2133. X    XFillArc(dpy, drw, gcon, psum->p[ix].x-lradx,
  2134. X         psum->p[ix].y-lrady, 2*lradx, 2*lrady, 0, 23040); 
  2135. X    }
  2136. X}
  2137. X
  2138. Xvoid draw_score(drw)
  2139. XDrawable drw;
  2140. X{
  2141. X    static char buf[32];
  2142. X    register int ix;
  2143. X    long sc;
  2144. X
  2145. X    if (score==0) {
  2146. X    XDrawImageString(dpy, drw, gcwhite, 76, 20,
  2147. X             "0         ", 10);
  2148. X    }
  2149. X    else {
  2150. X    sc = score;
  2151. X    ix = 32;
  2152. X    buf[--ix] = '\0';
  2153. X    while (sc) {
  2154. X        buf[--ix] = (sc%10) + '0';
  2155. X        sc /= 10;
  2156. X    };
  2157. X    XDrawImageString(dpy, drw, gcwhite, 76, 20,
  2158. X             buf+ix, 31-ix);
  2159. X    }
  2160. X}
  2161. X
  2162. Xvoid loadpieces(flname)
  2163. Xchar *flname;
  2164. X{
  2165. X    register int jx, ix;
  2166. X    FILE *fl;
  2167. X    int res;
  2168. X
  2169. X    fl = fopen(flname, "r");
  2170. X    if (fl==NULL) {
  2171. X    fprintf(stderr, "spheral: could not open shape file.\n");
  2172. X    exit(-1);
  2173. X    };
  2174. X
  2175. X    res=fscanf(fl, "%hd\n", &numpieces);
  2176. X    if (res!=1) {
  2177. X    fprintf(stderr, "spheral: error 0 in shape file.\n");
  2178. X    exit(-1);
  2179. X    };
  2180. X
  2181. X    for (ix=0; ix<numpieces; ix++) {
  2182. X    int in1, in2, in3;
  2183. X    res=fscanf(fl, "%d\n", &in1);
  2184. X    if (res!=1) {
  2185. X        fprintf(stderr, "spheral: error 1 in shape file.\n");
  2186. X        exit(-1);
  2187. X    };
  2188. X    pieces[ix].numballs=in1;
  2189. X    if (pieces[ix].numballs>MAXBALLS) {
  2190. X        fprintf(stderr, "spheral: shape %d is too complex.\n", ix);
  2191. X        exit(-1);
  2192. X    };
  2193. X    for (jx=0; jx<pieces[ix].numballs; jx++) {
  2194. X        point *p = &(pieces[ix].points[jx]);
  2195. X        res=fscanf(fl, "%lf, %lf, %lf\n", &(p->x),
  2196. X               &(p->y), &(p->z));
  2197. X        if (res!=3) {
  2198. X        fprintf(stderr, "spheral: error 2 in shape file.\n");
  2199. X        exit(-1);
  2200. X        };
  2201. X        p->w = 1.0;
  2202. X    };
  2203. X    }
  2204. X}
  2205. X
  2206. END_OF_FILE
  2207. if test 11465 -ne `wc -c <'spheral/disp.c'`; then
  2208.     echo shar: \"'spheral/disp.c'\" unpacked with wrong size!
  2209. fi
  2210. # end of 'spheral/disp.c'
  2211. fi
  2212. if test -f 'spheral/game.c' -a "${1}" != "-c" ; then 
  2213.   echo shar: Will not clobber existing file \"'spheral/game.c'\"
  2214. else
  2215. echo shar: Extracting \"'spheral/game.c'\" \(10019 characters\)
  2216. sed "s/^X//" >'spheral/game.c' <<'END_OF_FILE'
  2217. X/* (C) Copyright 1991 Andrew Plotkin. Permission is
  2218. X given to copy and use, as long as this copyright
  2219. X notice is retained. */
  2220. X
  2221. X#include <stdio.h>
  2222. X#include <math.h>
  2223. X#include <sys/time.h>
  2224. X#include <X11/Xlib.h>
  2225. X#include <X11/keysym.h>
  2226. X#include "spheral.h"
  2227. X
  2228. X#define TICKLENGTH (25000)
  2229. X#define GLIDELENGTH (8)
  2230. X#define TURNLENGTH (8)
  2231. X#define PLUMLENGTH (3)
  2232. X#define FALLLENGTH (8)
  2233. X#define MIRRORLENGTH (12)
  2234. X
  2235. X/* int meterx, meterx2, metery, metersize, meterlev,
  2236. X meteroldlev, meter_f_b, meter_b_d;
  2237. X oldlev is level on fieldpm */
  2238. X
  2239. Xunsigned char field[MAXFIELDX][MAXFIELDX][MAXFIELDZ];
  2240. Xshort fieldx, fieldz;
  2241. Xdouble fieldoffx, fieldoffy, fieldoffz;
  2242. Xextern double offx, offy, offz;
  2243. Xlong score=(-1), dropticks;
  2244. X
  2245. Xextern int aspectflag;
  2246. Xextern double aspect;
  2247. X
  2248. Xextern point plist[], traplist[], templist[];
  2249. X
  2250. Xextern void setup_backpm(), setup_fieldpm(), setup_fieldpts(),
  2251. Xplop_piece(), add_balls(), round_piece(), draw_score();
  2252. Xextern void rotate_piece(), reverse_piece(), pauseloop();
  2253. X
  2254. Xvoid clearfield()
  2255. X{
  2256. X    int ix, iy, iz;
  2257. X    for (ix=0; ix<fieldx; ix++)
  2258. X    for (iy=0; iy<fieldx; iy++)
  2259. X        for (iz=0; iz<fieldz; iz++) 
  2260. X        field[ix][iy][iz] = 0;
  2261. X}
  2262. X
  2263. Xvoid initgame()
  2264. X{
  2265. X    curpiece = -1;
  2266. X    score = 0;
  2267. X    dropticks = 800;
  2268. X    /*meterlev = 0;*/
  2269. X    clearfield();
  2270. X    setup_fieldpts();
  2271. X    setup_fieldpm();
  2272. X}
  2273. X
  2274. Xvoid redo_board_globals()  /* using dispx, dispy */
  2275. X{
  2276. X    if (dispy*ROOTHALF < dispx/2) 
  2277. X    boardscale = 2.5 * (double)(dispy*ROOTHALF);
  2278. X    else
  2279. X    boardscale = 2.5 * (double)(dispx/2);
  2280. X    halfboardx = dispx/2;
  2281. X    halfboardy = dispy/2;
  2282. X/*
  2283. X    if (dispy-(int)boardscale > 60) {
  2284. X    meterx = 32;
  2285. X    metery = boardscale+30;
  2286. X    }
  2287. X    else {
  2288. X    meterx = 176;
  2289. X    metery = boardscale+10;
  2290. X    }
  2291. X    metersize = (((int)boardscale) - meterx) / fieldz;
  2292. X    if (metersize<1) metersize = 1;*/
  2293. X}
  2294. X
  2295. Xvoid gameloop()
  2296. X{
  2297. X#define ST_STILL (0)
  2298. X#define ST_FALL (1)
  2299. X#define ST_TURN (2)
  2300. X#define ST_GLIDE (3)
  2301. X#define ST_PLUMMET (4)
  2302. X#define ST_SPACEHIT (5)
  2303. X#define ST_PAUSE (6)
  2304. X#define ST_MIRROR (7)
  2305. X
  2306. X    short status, res;
  2307. X    short droptimer=0, stattick;
  2308. X    Bool eventp;
  2309. X    XEvent event, nextevent;
  2310. X    long evmasks;
  2311. X    char key;
  2312. X    KeySym ksym;
  2313. X    long lasttime;
  2314. X    double toffx, toffy, toffz;
  2315. X    int taxis; /* 1=x, 2=y, 3=z */
  2316. X    int tdir;
  2317. X    struct timeval tv;
  2318. X    fd_set readbits;
  2319. X    int gotit;
  2320. X
  2321. X    status = ST_PAUSE;
  2322. X    /*lasttime = current_usec();*/
  2323. X
  2324. X    while (1) {
  2325. X    if (curpiece==(-1)) {
  2326. X        startpiece();
  2327. X        if (curpiece==(-2)) break; /* game over, man */
  2328. X        setup_backpm();
  2329. X        back_to_disp(0);
  2330. X        draw_score(win);
  2331. X        droptimer = 0;
  2332. X
  2333. X        do {
  2334. X        eventp = XCheckWindowEvent(dpy, win,
  2335. X        KeyPressMask, &event);
  2336. X        }
  2337. X        while (eventp);
  2338. X    };
  2339. X
  2340. X    XFlush(dpy);
  2341. X
  2342. X    tv.tv_sec = 0;
  2343. X    tv.tv_usec = TICKLENGTH;
  2344. X    FD_ZERO(&readbits);
  2345. X    FD_SET(ConnectionNumber(dpy), &readbits);
  2346. X    (void)select(1+ConnectionNumber(dpy), &readbits, 0, 0, &tv);
  2347. X
  2348. X    if (status == ST_STILL)
  2349. X        evmasks = (KeyPressMask | ExposureMask
  2350. X               | StructureNotifyMask);
  2351. X    else
  2352. X        evmasks = (ExposureMask | StructureNotifyMask);
  2353. X    eventp = XCheckWindowEvent(dpy, win, evmasks, &event);
  2354. X    if (eventp) switch (event.type) {
  2355. X        case Expose:
  2356. X        do {
  2357. X            gotit = XCheckWindowEvent(dpy, win,
  2358. X            ExposureMask, &nextevent);
  2359. X        } while (gotit);
  2360. X        back_to_disp(1);
  2361. X        break;
  2362. X        case KeyPress:
  2363. X        XLookupString(&event, &key, 1, &ksym, NULL);
  2364. X        /*printf("got '%s'\n", XKeysymToString(ksym));*/
  2365. X        switch (ksym) {
  2366. X            case XK_Q:
  2367. X            return;
  2368. X            break;
  2369. X/*            case XK_equal:
  2370. X            curpiece = (-1);
  2371. X            break;*/
  2372. X            case XK_Escape:
  2373. X            pauseloop();
  2374. X            setup_fieldpm();
  2375. X            add_balls(0);   
  2376. X            setup_backpm();
  2377. X            back_to_disp(1);            
  2378. X            draw_score(win);
  2379. X            break;
  2380. X            case XK_s:
  2381. X            case XK_g:
  2382. X            case XK_e:
  2383. X            case XK_f:
  2384. X            case XK_r:
  2385. X            case XK_d:
  2386. X            if (status != ST_STILL) break;
  2387. X            if (ksym==XK_s || ksym==XK_g) taxis=1;
  2388. X            if (ksym==XK_e || ksym==XK_f) taxis=2;
  2389. X            if (ksym==XK_r || ksym==XK_d) taxis=3;
  2390. X            if (ksym==XK_s || ksym==XK_f || ksym==XK_r)
  2391. X                tdir=1;
  2392. X            else tdir=(-1);
  2393. X            toffx = 0.0;
  2394. X            toffy = 0.0;
  2395. X            toffz = 0.0;
  2396. X            updatetemp_tra(toffx, toffy, toffz, taxis, tdir);
  2397. X            res = collision(1);
  2398. X            while (res!=OUT_NOT && res!=OUT_COLLIDE
  2399. X                   && res!=OUT_DOWN) {
  2400. X                switch (res) { /* as collision, ignore 2 */
  2401. X                case OUT_UP:
  2402. X                    toffz = toffz - 1.0 ;
  2403. X                    break;
  2404. X                case OUT_NORTHEAST:
  2405. X                    toffx = toffx - 0.5;
  2406. X                    toffy = toffy - ROOTHALF;
  2407. X                    toffz = toffz + 0.5;
  2408. X                    break;
  2409. X                case OUT_SOUTH:
  2410. X                    toffx = toffx - 0.5;
  2411. X                    toffy = toffy + ROOTHALF;
  2412. X                    toffz = toffz - 0.5;
  2413. X                    break;
  2414. X                case OUT_NORTHWEST:
  2415. X                    toffx = toffx + 1.0;
  2416. X                    break;
  2417. X                }
  2418. X                updatetemp_tra(toffx, toffy, toffz,
  2419. X                       taxis, tdir);
  2420. X                res = collision(1);
  2421. X            };
  2422. X            if (res==OUT_NOT) {
  2423. X                status = ST_TURN;
  2424. X                stattick = 0;
  2425. X            };
  2426. X            break;
  2427. X            case XK_v:
  2428. X            if (status != ST_STILL) break;
  2429. X            toffx = 0.0;
  2430. X            toffy = 0.0;
  2431. X            toffz = 0.0;
  2432. X            updatetemp_tra(toffx, toffy, toffz, -1, 0);
  2433. X            res = collision(1);
  2434. X            while (res!=OUT_NOT && res!=OUT_COLLIDE && res!=OUT_DOWN) {
  2435. X                switch (res) { /* as collision, ignore 2 */
  2436. X                case OUT_UP:
  2437. X                    toffz = toffz - 1.0 ;
  2438. X                    break;
  2439. X                case OUT_NORTHEAST:
  2440. X                    toffx = toffx - 0.5;
  2441. X                    toffy = toffy - ROOTHALF;
  2442. X                    toffz = toffz + 0.5;
  2443. X                    break;
  2444. X                case OUT_SOUTH:
  2445. X                    toffx = toffx - 0.5;
  2446. X                    toffy = toffy + ROOTHALF;
  2447. X                    toffz = toffz - 0.5;
  2448. X                    break;
  2449. X                case OUT_NORTHWEST:
  2450. X                    toffx = toffx + 1.0;
  2451. X                    break;
  2452. X                }
  2453. X                updatetemp_tra(toffx, toffy, toffz, -1, 0);
  2454. X                res = collision(1);
  2455. X            };
  2456. X            if (res==OUT_NOT) {
  2457. X                status = ST_MIRROR;
  2458. X                aspectflag = 1;
  2459. X                aspect = 1.0;
  2460. X                stattick = 0;
  2461. X            };
  2462. X            break;
  2463. X            case XK_p:
  2464. X            if (status != ST_STILL) break;
  2465. X            droptimer = dropticks+100;
  2466. X            break;
  2467. X            case XK_space:
  2468. X            if (status != ST_STILL) break;
  2469. X            status = ST_SPACEHIT;
  2470. X            break;
  2471. X            case XK_KP_1:
  2472. X            case XK_KP_3:
  2473. X            case XK_KP_4:
  2474. X            case XK_KP_6:
  2475. X            case XK_KP_7:
  2476. X            case XK_KP_9:
  2477. X            case XK_u:
  2478. X            case XK_o:
  2479. X            case XK_l:
  2480. X            case XK_period:
  2481. X            case XK_m:
  2482. X            case XK_j:
  2483. X            if (status != ST_STILL) break;
  2484. X            toffx = 0.0;
  2485. X            toffy = 0.0;
  2486. X            toffz = 0.0;
  2487. X            if (ksym==XK_KP_4 || ksym==XK_j) toffx = -1.0;
  2488. X            if (ksym==XK_KP_6 || ksym==XK_l) toffx = 1.0;
  2489. X            if (ksym==XK_KP_9 || ksym==XK_o) {
  2490. X                toffx = 0.5;
  2491. X                toffy = ROOTHALF;
  2492. X                toffz = -0.5;
  2493. X            }
  2494. X            if (ksym==XK_KP_1 || ksym==XK_m) {
  2495. X                toffx = -0.5;
  2496. X                toffy = -ROOTHALF;
  2497. X                toffz = 0.5;
  2498. X            }
  2499. X            if (ksym==XK_KP_3 || ksym==XK_period) {
  2500. X                toffx = 0.5;
  2501. X                toffy = -ROOTHALF;
  2502. X                toffz = 0.5;
  2503. X            }
  2504. X            if (ksym==XK_KP_7 || ksym==XK_u) {
  2505. X                toffx = -0.5;
  2506. X                toffy = ROOTHALF;
  2507. X                toffz = -0.5;
  2508. X            }
  2509. X            updatetemp_tra(toffx, toffy, toffz, 0, 0);
  2510. X            if (collision(1)==OUT_NOT) {
  2511. X                status = ST_GLIDE;
  2512. X                stattick = 0;
  2513. X            };
  2514. X            break;
  2515. X        };
  2516. X        break;
  2517. X        case ConfigureNotify:
  2518. X        if (event.xconfigure.width != dispx ||
  2519. X            event.xconfigure.height != dispy) {
  2520. X            dispx = event.xconfigure.width;
  2521. X            dispy = event.xconfigure.height;
  2522. X            XFreePixmap(dpy, backpm);
  2523. X            XFreePixmap(dpy, fieldpm);
  2524. X            backpm = XCreatePixmap(dpy, win, dispx,
  2525. X            dispy, scndepth);   
  2526. X            fieldpm = XCreatePixmap(dpy, win, dispx,
  2527. X            dispy, scndepth);   
  2528. X            redo_board_globals();
  2529. X            setup_fieldpts();
  2530. X            setup_fieldpm();
  2531. X            add_balls(0);   
  2532. X            setup_backpm();
  2533. X            back_to_disp(1);            
  2534. X            draw_score(win);
  2535. X        }
  2536. X        break;
  2537. X    } /* done event switch */
  2538. X
  2539. X    if (status==ST_PAUSE) status=ST_STILL;
  2540. X    switch (status) {
  2541. X        case ST_STILL:
  2542. X        droptimer++;
  2543. X        if (droptimer>dropticks) {
  2544. X            droptimer=0;
  2545. X            updatetemp_tra(0.0, 0.0, -1.0, 0, 0);
  2546. X            if (collision(1)==OUT_NOT) {   
  2547. X            stattick=0;
  2548. X            status = ST_FALL;
  2549. X            }
  2550. X            else {
  2551. X            plop_piece();
  2552. X            curpiece = -1;
  2553. X            }
  2554. X        }
  2555. X        break;
  2556. X        case ST_SPACEHIT:
  2557. X        updatetemp_tra(0.0, 0.0, -1.0, 0, 0);
  2558. X        if (collision(1)==OUT_NOT) {  
  2559. X            score++;
  2560. X            stattick=1;
  2561. X            status = ST_PLUMMET;
  2562. X            offz -= 1.0/PLUMLENGTH;
  2563. X            updatepiece();
  2564. X            setup_backpm();
  2565. X            back_to_disp(0);
  2566. X        }
  2567. X        else {
  2568. X            plop_piece();
  2569. X            curpiece = -1;
  2570. X            status = ST_PAUSE;
  2571. X        }
  2572. X        break;
  2573. X        case ST_GLIDE:
  2574. X        stattick++;
  2575. X        offx += (double)toffx/GLIDELENGTH;
  2576. X        offy += (double)toffy/GLIDELENGTH;
  2577. X        offz += (double)toffz/GLIDELENGTH;
  2578. X        if (stattick==GLIDELENGTH) {
  2579. X            round_piece(); 
  2580. X        };
  2581. X        updatepiece();
  2582. X        setup_backpm();
  2583. X        back_to_disp(0);
  2584. X        if (stattick==GLIDELENGTH) {
  2585. X            status = ST_PAUSE;
  2586. X        };
  2587. X        break;
  2588. X        case ST_FALL:
  2589. X        stattick++;
  2590. X        offz -= 1.0/FALLLENGTH;
  2591. X        if (stattick==FALLLENGTH) {
  2592. X            round_piece(); 
  2593. X        };
  2594. X        updatepiece();
  2595. X        setup_backpm();
  2596. X        back_to_disp(0);
  2597. X        if (stattick==FALLLENGTH) {
  2598. X            status = ST_PAUSE;
  2599. X        };
  2600. X        break;
  2601. X        case ST_PLUMMET:
  2602. X        stattick++;
  2603. X        offz -= 1.0/PLUMLENGTH;
  2604. X        if (stattick==PLUMLENGTH) {
  2605. X            round_piece(); 
  2606. X        };
  2607. X        updatepiece();
  2608. X        setup_backpm();
  2609. X        back_to_disp(0);
  2610. X        if (stattick==PLUMLENGTH) {
  2611. X            status = ST_SPACEHIT;
  2612. X        };
  2613. X        break;
  2614. X        case ST_TURN:
  2615. X        stattick++;
  2616. X        rotate_piece(plist, taxis, ((double)(tdir))*PI/2.0/TURNLENGTH);
  2617. X        offx += (double)toffx/TURNLENGTH;
  2618. X        offy += (double)toffy/TURNLENGTH;
  2619. X        offz += (double)toffz/TURNLENGTH;
  2620. X        if (stattick==TURNLENGTH) {
  2621. X            round_piece(); 
  2622. X        };
  2623. X        updatepiece();
  2624. X        setup_backpm();
  2625. X        back_to_disp(0);
  2626. X        if (stattick==TURNLENGTH) {
  2627. X            status = ST_PAUSE;
  2628. X        };
  2629. X        break;
  2630. X        case ST_MIRROR:
  2631. X        stattick++;
  2632. X        if (stattick == MIRRORLENGTH/2) {
  2633. X            reverse_piece(plist, -1);
  2634. X        };
  2635. X        if (stattick < MIRRORLENGTH/2) {
  2636. X            aspect = (double)(MIRRORLENGTH/2-stattick)
  2637. X              / (double)(MIRRORLENGTH/2);
  2638. X        }
  2639. X        else {
  2640. X            aspect = (double)(stattick-MIRRORLENGTH/2)
  2641. X              / (double)(MIRRORLENGTH/2);
  2642. X        };
  2643. X        offx += (double)toffx/MIRRORLENGTH;
  2644. X        offy += (double)toffy/MIRRORLENGTH;
  2645. X        offz += (double)toffz/MIRRORLENGTH;
  2646. X        if (stattick==MIRRORLENGTH) {
  2647. X            round_piece(); 
  2648. X            aspectflag = 0;
  2649. X        };
  2650. X        updatepiece();
  2651. X        setup_backpm();
  2652. X        back_to_disp(0);
  2653. X        if (stattick==MIRRORLENGTH) {
  2654. X            status = ST_PAUSE;
  2655. X        };
  2656. X        break;
  2657. X    } /* done switch status */
  2658. X    }
  2659. X}
  2660. X
  2661. END_OF_FILE
  2662. if test 10019 -ne `wc -c <'spheral/game.c'`; then
  2663.     echo shar: \"'spheral/game.c'\" unpacked with wrong size!
  2664. fi
  2665. # end of 'spheral/game.c'
  2666. fi
  2667. if test -f 'spheral/patchlevel.h' -a "${1}" != "-c" ; then 
  2668.   echo shar: Will not clobber existing file \"'spheral/patchlevel.h'\"
  2669. else
  2670. echo shar: Extracting \"'spheral/patchlevel.h'\" \(58 characters\)
  2671. sed "s/^X//" >'spheral/patchlevel.h' <<'END_OF_FILE'
  2672. Xstatic char *patchlevel = "Spheral version 1.0, patch 1";
  2673. END_OF_FILE
  2674. if test 58 -ne `wc -c <'spheral/patchlevel.h'`; then
  2675.     echo shar: \"'spheral/patchlevel.h'\" unpacked with wrong size!
  2676. fi
  2677. # end of 'spheral/patchlevel.h'
  2678. fi
  2679. if test -f 'spheral/score.c' -a "${1}" != "-c" ; then 
  2680.   echo shar: Will not clobber existing file \"'spheral/score.c'\"
  2681. else
  2682. echo shar: Extracting \"'spheral/score.c'\" \(3980 characters\)
  2683. sed "s/^X//" >'spheral/score.c' <<'END_OF_FILE'
  2684. X/* (C) Copyright 1991 Andrew Plotkin. Permission is
  2685. X given to copy and use, as long as this copyright
  2686. X notice is retained. */
  2687. X
  2688. X#include <stdio.h>
  2689. X#include <errno.h>
  2690. X#include <ctype.h> 
  2691. X#include <pwd.h>
  2692. X#ifdef USELOCKF 
  2693. X#include <unistd.h> /* this is for SOLARIS;
  2694. X other systems may need a different include
  2695. X file to get lockf() to work right */
  2696. X#endif
  2697. X#include <sys/file.h>
  2698. X#include <X11/Xlib.h>
  2699. X#include "spheral.h"
  2700. X
  2701. Xextern char *getenv();
  2702. Xchar ProgramName[] = "spheral";
  2703. X
  2704. Xgamer hscores[NUMGAMERS];
  2705. Xchar hscorefl[512];
  2706. Xchar userid[16], gamename[16];
  2707. X
  2708. Xextern int errno;
  2709. X
  2710. Xvoid load_hscores(save)
  2711. Xint save;
  2712. X{
  2713. X    FILE *fl;
  2714. X    register int ix, jx;
  2715. X    int fd, res;
  2716. X    char buf[255];
  2717. X
  2718. X    fl = fopen(hscorefl, "r+");
  2719. X    if (!fl) {
  2720. X    fprintf(stderr,
  2721. X        "spheral: unable to open high score file\n");
  2722. X    fprintf(stderr,
  2723. X        "spheral: generating empty score file\n");
  2724. X
  2725. X    fl = fopen(hscorefl, "w");
  2726. X    if (!fl) {
  2727. X        fprintf(stderr,
  2728. X            "spheral: unable to create high score file\n");
  2729. X        exit(-1);
  2730. X    }
  2731. X
  2732. X    for (ix=0; ix<NUMGAMERS; ix++) {
  2733. X        fprintf(fl, "----\nSpheral\n0\n");
  2734. X    }
  2735. X    fclose(fl);
  2736. X    fl = fopen(hscorefl, "r+");
  2737. X    if (!fl) {
  2738. X        fprintf(stderr,
  2739. X            "spheral: unable to reopen high score file\n");
  2740. X        exit(-1);
  2741. X    }
  2742. X    }
  2743. X
  2744. X    fd = fileno(fl);
  2745. X#ifdef USELOCKF
  2746. X    res = lockf(fd, F_LOCK, 0);
  2747. X#else
  2748. X    res = flock(fd, LOCK_NB | LOCK_EX);
  2749. X#endif
  2750. X    while (res) {
  2751. X    if (errno != EWOULDBLOCK) {
  2752. X        fprintf(stderr,
  2753. X            "spheral: unable to lock high score file\n");
  2754. X        exit(-1);
  2755. X    };
  2756. X    sleep(1);
  2757. X#ifdef USELOCKF
  2758. X    res = lockf(fd, F_LOCK, 0);
  2759. X#else
  2760. X    res = flock(fd, LOCK_NB | LOCK_EX);
  2761. X#endif
  2762. X    };
  2763. X
  2764. X    for (ix=0; ix<NUMGAMERS; ix++) {
  2765. X    long val;
  2766. X
  2767. X    fgets(buf, 255, fl);
  2768. X    for (jx=0; jx<15 && buf[jx]!='\n'; jx++) 
  2769. X        hscores[ix].userid[jx] = buf[jx];
  2770. X    hscores[ix].userid[jx] = '\0';
  2771. X    
  2772. X    fgets(buf, 255, fl);
  2773. X    for (jx=0; jx<15 && buf[jx]!='\n'; jx++) 
  2774. X        hscores[ix].name[jx] = buf[jx];
  2775. X    hscores[ix].name[jx] = '\0';
  2776. X    
  2777. X    fgets(buf, 255, fl);
  2778. X    val=0;
  2779. X    for (jx=0; buf[jx]!='\n'; jx++) 
  2780. X        val = val*10 + buf[jx] - '0';
  2781. X    hscores[ix].score = val;
  2782. X    sprintf(hscores[ix].scoret, "%d", val);
  2783. X    };
  2784. X
  2785. X    if (save) {
  2786. X    if (checkmod_scores()) {
  2787. X        rewind(fl);
  2788. X        for (ix=0; ix<NUMGAMERS; ix++) {
  2789. X        fprintf(fl, "%s\n%s\n%d\n", hscores[ix].userid,
  2790. X            hscores[ix].name, hscores[ix].score);
  2791. X        }
  2792. X    }
  2793. X    }
  2794. X
  2795. X#ifdef USELOCKF
  2796. X    lockf(fd, F_ULOCK, 0);
  2797. X#else
  2798. X    flock(fd, LOCK_UN);
  2799. X#endif
  2800. X
  2801. X    fclose(fl);
  2802. X}
  2803. X
  2804. Xint checkmod_scores()
  2805. X{
  2806. X    register int ix;
  2807. X    int new, bottom;
  2808. X    
  2809. X    if (score <= hscores[NUMGAMERS-1].score) return 0;
  2810. X    
  2811. X    for (ix=0; strcmp(hscores[ix].userid, userid)
  2812. X      && ix<NUMGAMERS; ix++);
  2813. X    
  2814. X    if (ix<NUMGAMERS) { /* was in list */
  2815. X    if (score <= hscores[ix].score) return 0;
  2816. X    bottom = ix;
  2817. X    }
  2818. X    else { /* wasn't in list */
  2819. X    bottom = NUMGAMERS-1;
  2820. X    };
  2821. X
  2822. X    for (new=0; score<=hscores[new].score; new++);
  2823. X    for (ix=bottom; ix>new; ix--) {
  2824. X    strcpy(hscores[ix].name, hscores[ix-1].name);
  2825. X    strcpy(hscores[ix].userid, hscores[ix-1].userid);
  2826. X    strcpy(hscores[ix].scoret, hscores[ix-1].scoret);
  2827. X    hscores[ix].score = hscores[ix-1].score;
  2828. X    };
  2829. X    strcpy(hscores[new].name, gamename);
  2830. X    strcpy(hscores[new].userid, userid);
  2831. X    hscores[new].score = score;
  2832. X    sprintf(hscores[new].scoret, "%d", score);
  2833. X
  2834. X    return 1;
  2835. X}
  2836. X
  2837. Xvoid get_names()
  2838. X{
  2839. X    register int ix;
  2840. X    struct passwd *tp;
  2841. X    char *tcp;
  2842. X
  2843. X    strcpy(hscorefl, SCOREFILENAME);
  2844. X
  2845. X    tp = getpwuid(getuid());
  2846. X    if (!tp) {
  2847. X    printf("unable to get userid!\n");
  2848. X    strcpy(userid, "????");
  2849. X    }
  2850. X    else {
  2851. X    strncpy(userid, tp->pw_name, 16);
  2852. X    userid[15] = '\0';
  2853. X    }
  2854. X
  2855. X    tcp = getenv("NAME");
  2856. X    if (tcp) {
  2857. X    strncpy(gamename, tcp, 16);
  2858. X    gamename[15] = '\0';
  2859. X    }
  2860. X    else if (tcp=XGetDefault(dpy, "spheral", "name")) {
  2861. X    strncpy(gamename, tcp, 16);
  2862. X    gamename[15] = '\0';
  2863. X    }
  2864. X    else if (tcp=XGetDefault(dpy, "spatial", "name")) {
  2865. X    strncpy(gamename, tcp, 16);
  2866. X    gamename[15] = '\0';
  2867. X    }
  2868. X    else {
  2869. X    strcpy(gamename, userid);
  2870. X    };
  2871. X
  2872. X    printf("Welcome, %s (%s)\n", gamename, userid);
  2873. X}
  2874. END_OF_FILE
  2875. if test 3980 -ne `wc -c <'spheral/score.c'`; then
  2876.     echo shar: \"'spheral/score.c'\" unpacked with wrong size!
  2877. fi
  2878. # end of 'spheral/score.c'
  2879. fi
  2880. if test -f 'spheral/spheral.6' -a "${1}" != "-c" ; then 
  2881.   echo shar: Will not clobber existing file \"'spheral/spheral.6'\"
  2882. else
  2883. echo shar: Extracting \"'spheral/spheral.6'\" \(2537 characters\)
  2884. sed "s/^X//" >'spheral/spheral.6' <<'END_OF_FILE'
  2885. X.PU
  2886. X.TH SPHERAL 6 contributed
  2887. X.SH NAME
  2888. Xspheral  \-  three-dimensional Tetris on a close-packed
  2889. Xlattice of spheres
  2890. X.SH SYNOPSIS
  2891. X.B spheral
  2892. X[ 
  2893. X.I -m
  2894. X]
  2895. X.PP
  2896. X.B -m
  2897. X: Force monochrome mode, even on color displays.
  2898. X.SH DESCRIPTION
  2899. XIf you don't know the rules of Tetris by now, you're beyond hope.
  2900. X.PP
  2901. XYou are looking down; pieces appear directly in front of you
  2902. Xand fall away from you. The current piece is transparent;
  2903. Xwhen it lands, it becomes opaque. You must complete an entire
  2904. Xlayer (a triangle of 21 balls) to make it disappear.
  2905. X.PP
  2906. XThe bottom of the board (and therefore, the layers that you
  2907. Xare trying to complete) are
  2908. X.I not
  2909. Xparallel to the screen. They lean backwards (away from you) 
  2910. Xon the top (north) edge. When a piece lands on the bottom
  2911. Xof the board, the balls fall on the intersections of the grey
  2912. Xlines, not in the triangles between the lines.
  2913. X.PP
  2914. XThe top corner of the game display shows your score.
  2915. X.PP
  2916. XYou can resize the window, and the board will be scaled
  2917. Xappropriately. (The high-score list doesn't behave so
  2918. Xcleverly.)
  2919. X.PP
  2920. XBy hitting
  2921. X.B c
  2922. Xat the title screen, you can change the display of the balls
  2923. Xfrom solid grey disks to nifty shaded balls. However, in
  2924. Xthis mode, the game will have to generate the shaded
  2925. Ximages the first time you start a game, and again each time
  2926. Xyou resize the window. Generating the images takes about
  2927. X15 seconds, more or less, depending on how much
  2928. Xtestosterone your computer has to crunch numbers with.
  2929. X.SH CONTROLS
  2930. X.B s, g, r, d, e, f
  2931. X: rotate the current piece. The control of rotation around three
  2932. Xspatial axes is nigh impossible to describe, especially since
  2933. Xtwo of the axes are slantwise to the screen. See the title
  2934. Xscreen for a picture that may help.
  2935. X.br
  2936. X.B 4, 6, 7, 3, 1, 9
  2937. X.I or
  2938. X.br
  2939. X.B j, l, u, ., m, o
  2940. X: slide the current piece horizontally. (Again, this motion
  2941. Xis parallel with the bottom of the board, not with your
  2942. Xscreen.)
  2943. X.br
  2944. X.B p
  2945. X: drop the current piece one space down.
  2946. X.br
  2947. X.B v
  2948. X: mirror-image the current piece, left-to-right.
  2949. X.br
  2950. X.I SPACE
  2951. X: drop the current piece all the way to the bottom of the
  2952. Xboard.
  2953. X.br
  2954. X.I ESCAPE
  2955. X: pause the game, and draw pretty random cubes until
  2956. Xyou hit
  2957. X.I ESCAPE
  2958. Xagain.
  2959. X.br
  2960. X.B Q
  2961. X: quit the current game with your current score. Hitting
  2962. X.B Q
  2963. Xagain, from the title screen, will exit the program. Note
  2964. Xthat this is a capital letter (shift-Q).
  2965. X.SH AUTHOR
  2966. XAndrew Plotkin <ap1i+@andrew.cmu.edu>
  2967. X.br
  2968. XThis program is (C) Copyright 1991-3 Andrew Plotkin.
  2969. X.br
  2970. XPermission is given to copy and distribute freely, as long
  2971. Xas this copyright notice is retained.
  2972. END_OF_FILE
  2973. if test 2537 -ne `wc -c <'spheral/spheral.6'`; then
  2974.     echo shar: \"'spheral/spheral.6'\" unpacked with wrong size!
  2975. fi
  2976. # end of 'spheral/spheral.6'
  2977. fi
  2978. echo shar: End of archive 2 \(of 4\).
  2979. cp /dev/null ark2isdone
  2980. MISSING=""
  2981. for I in 1 2 3 4 ; do
  2982.     if test ! -f ark${I}isdone ; then
  2983.     MISSING="${MISSING} ${I}"
  2984.     fi
  2985. done
  2986. if test "${MISSING}" = "" ; then
  2987.     echo You have unpacked all 4 archives.
  2988.     rm -f ark[1-9]isdone
  2989. else
  2990.     echo You still need to unpack the following archives:
  2991.     echo "        " ${MISSING}
  2992. fi
  2993. ##  End of shell archive.
  2994. exit 0
  2995.