home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / X11 / spatial / intro.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  4.8 KB  |  179 lines

  1. /* (C) Copyright 1991 Andrew Plotkin. Permission is
  2.  given to copy and use, as long as this copyright
  3.  notice is retained. */
  4.  
  5. #include <stdio.h>
  6. #include <sys/time.h>
  7. #include <X11/Xlib.h>
  8. #include <X11/keysym.h>
  9. #include "spatial.h"
  10.  
  11. #define TICKLENGTH (50000)
  12. #define xputs(x, y, str)  \
  13. XDrawImageString(dpy, win, gcwhite, x, y, str, strlen(str))
  14.  
  15. #define xline(x1, y1, x2, y2)  \
  16. XDrawLine(dpy, win, gcwhite, x1, y1, x2, y2) 
  17.  
  18. extern GC gcblack, gcwhite, gcinv, gccopy, gcline,
  19. gcfield, gccubes[];
  20.  
  21. extern void intro_redraw(), redo_board_globals();
  22.  
  23. void initintro()
  24. {
  25.     intro_redraw();
  26. }
  27.  
  28. void introloop()
  29. {
  30.     short status, res;
  31.     Bool eventp;
  32.     XEvent event, nextevent;
  33.     long evmasks;
  34.     char key;
  35.     KeySym ksym;
  36.     long lasttime;
  37.     struct timeval tv;
  38.     fd_set readbits;
  39.  
  40.     while (1) {
  41.     tv.tv_sec = 0;
  42.     tv.tv_usec = TICKLENGTH;
  43.     FD_ZERO(&readbits);
  44.     FD_SET(ConnectionNumber(dpy), &readbits);
  45.     (void)select(1+ConnectionNumber(dpy), &readbits, 0, 0, &tv);
  46.  
  47.     evmasks = (KeyPressMask | ExposureMask | StructureNotifyMask);
  48.     eventp = XCheckWindowEvent(dpy, win, evmasks, &event);
  49.     if (eventp) switch (event.type) {
  50.         case Expose:
  51.         eventp = XCheckWindowEvent(dpy, win, evmasks,
  52.             &nextevent);
  53.         while (eventp && nextevent.type == Expose) {
  54.             eventp = XCheckWindowEvent(dpy, win, evmasks,
  55.             &nextevent);
  56.         };
  57.         if (eventp) {
  58.             XPutBackEvent(dpy, &nextevent);
  59.         };
  60.         intro_redraw();
  61.         break;
  62.         case KeyPress:
  63.         XLookupString(&event, &key, 1, &ksym, NULL);
  64.         /*printf("got '%s'\n", XKeysymToString(ksym));*/
  65.         switch (ksym) {
  66.             case XK_q:
  67.             case XK_Q:
  68.             exit(0);
  69.             break;
  70.             case XK_c:
  71.             case XK_C:
  72.             if (!stereo) {
  73.                 stereo = 1;
  74.                 fieldoffx = -2.65;
  75.                 fieldoffx2 = -2.35;
  76.             }
  77.             else if (fieldoffx < -2.5) {
  78.                 fieldoffx = -2.35;
  79.                 fieldoffx2 = -2.65;
  80.             }
  81.             else {
  82.                 stereo = 0;
  83.                 fieldoffx = -2.5;
  84.             };
  85.             redo_board_globals();
  86.             intro_redraw();
  87.             break;
  88.             case XK_s:
  89.             case XK_S:
  90.             return;
  91.         };
  92.         break;
  93.         case ConfigureNotify:
  94.         if (event.xconfigure.width != dispx || event.xconfigure.height != dispy) {
  95.             dispx = event.xconfigure.width;
  96.             dispy = event.xconfigure.height;
  97.             redo_board_globals();
  98.             XFreePixmap(dpy, backpm);
  99.             XFreePixmap(dpy, fieldpm);
  100.             backpm = XCreatePixmap(dpy, win, dispx,
  101.                        dispy, scndepth);   
  102.             fieldpm = XCreatePixmap(dpy, win, dispx,
  103.                         dispy, scndepth);   
  104.         }
  105.         break;
  106.     }
  107.     }
  108. }
  109.  
  110. void intro_redraw()
  111. {
  112.     register int ix;
  113.     char buf[255];
  114.  
  115.     XFillRectangle(dpy, win, gcblack, 0, 0, dispx, dispy);
  116.     xputs(50, 180, "Spatial");
  117.     xputs(50, 200, "A Sadistic Software Production");
  118.     xputs(50, 220, "(C) Copyright 1991-3 Andrew Plotkin");
  119.     xputs(50, 240, " (ap1i@andrew.cmu.edu)");
  120.     if (score!=(-1)) {
  121.     sprintf(buf, "Your score: %d", score);
  122.     xputs(50, 260, buf);
  123.     }
  124.  
  125.     xputs(50, 280, "Commands:");
  126.     xputs(70, 300, "s: start game");
  127.     if (!stereo) xputs(70, 320, "c: change display (normal)");
  128.     else if (fieldoffx < -2.5)
  129.     xputs(70, 320, "c: change display (reversed stereoscopic)");
  130.     else
  131.     xputs(70, 320, "c: change display (normal stereoscopic)");
  132.     xputs(70, 340, "Escape: pause");
  133.     xputs(70, 360, "q: quit program");
  134.  
  135.     xputs(50, 400, "Game controls:");
  136.  
  137.     XDrawArc(dpy, win, gcfield, 50, 410, 140, 140, 0, 23040);
  138.     XDrawArc(dpy, win, gcfield, 100, 410, 40, 140, 0, 23040);
  139.     XDrawArc(dpy, win, gcfield, 50, 460, 140, 40, 0, 23040);
  140.     XDrawArc(dpy, win, gcfield, 102, 410, 40, 140, 5760, 11520);
  141.     XDrawArc(dpy, win, gcfield, 50, 462, 140, 40, 11520, 11520);
  142.     XDrawArc(dpy, win, gcwhite, 101, 410, 40, 140, 8000, 3000);
  143.     XDrawArc(dpy, win, gcwhite, 101, 410, 40, 140, 14000, 2000);
  144.     XDrawArc(dpy, win, gcwhite, 50, 461, 140, 40, 13000, 2000);
  145.     XDrawArc(dpy, win, gcwhite, 50, 461, 140, 40, 17800, 3000);
  146.     XDrawArc(dpy, win, gcwhite, 51, 411, 138, 138, 1920, 1920);
  147.     XDrawArc(dpy, win, gcwhite, 51, 411, 138, 138, 7680, 1920);
  148.     xline(110, 421, 114, 430);
  149.     xline(110, 421, 100, 427);
  150.     xline(179, 492, 170, 488);
  151.     xline(179, 492, 173, 502);
  152.     xline(57, 489, 60, 498);
  153.     xline(57, 489, 60, 484);
  154.     xline(114, 546, 105, 543);
  155.     xline(114, 546, 119, 543);
  156.     xline(182, 448, 172, 445);
  157.     xline(58, 448, 68, 445);
  158.  
  159.     xputs(83, 501, "h");
  160.     xputs(120, 503, "l");
  161.     xputs(99, 483, "i");
  162.     xputs(102, 518, "m");
  163.     xputs(91, 418, "k");
  164.     xputs(144, 416, "j");
  165.  
  166.     xputs(70, 570, "rotation keys as shown above");
  167.     xputs(70, 590, "arrow keys: move piece sideways");
  168.     xputs(70, 610, "p: drop piece by 1");
  169.     xputs(70, 630, "space: drop piece to bottom");
  170.     xputs(70, 650, "q: quit game and return to this menu");
  171.  
  172.     xputs(350, 250, "High Scores:");
  173.     for (ix=0; ix<NUMGAMERS; ix++) {
  174.     xputs(390, 270+20*ix, hscores[ix].name);
  175.     xputs(490, 270+20*ix, hscores[ix].userid);
  176.     xputs(590, 270+20*ix, hscores[ix].scoret);
  177.     }
  178. }
  179.