home *** CD-ROM | disk | FTP | other *** search
/ PC-Online 1996 May / PCOnline_05_1996.bin / linux / source / xap / xgames / xtetris-.6 / xtetris- / xtetris-2.6 / shape.c < prev    next >
C/C++ Source or Header  |  1995-02-10  |  9KB  |  238 lines

  1. #include "defs.h"
  2. #ifdef SVR4
  3. # define random rand
  4. #endif
  5.  
  6. shape_type shape[] = {
  7.  
  8. /*      bitmap    score X Y wid ht */
  9.   { /* Shape 0 */
  10.     { { 0x00000f00, 5,  { {0,1,4,1}, {0,0,0,0} }, {{0,0,0,0},{0,0,0,0}}, 1,  0,4,  {0,0,0,0}, {0,0,0,0}, {0,0,0,0} },   /*      */
  11.       { 0x00004444, 8,  { {1,0,1,4}, {0,0,0,0} }, {{0,0,0,0},{0,0,0,0}}, 1,  1,1,  {0,0,0,0}, {0,0,0,0}, {0,0,0,0} },   /* #### */
  12.       { 0x00000f00, 5,  { {0,1,4,1}, {0,0,0,0} }, {{0,0,0,0},{0,0,0,0}}, 1,  0,4,  {0,0,0,0}, {0,0,0,0}, {0,0,0,0} },   /*      */
  13.       { 0x00004444, 8,  { {1,0,1,4}, {0,0,0,0} }, {{0,0,0,0},{0,0,0,0}}, 1,  1,1,  {0,0,0,0}, {0,0,0,0}, {0,0,0,0} } }, /*      */
  14.   },
  15.  
  16.   { /* Shape 1 */
  17.     { { 0x0000cc00, 6,  { {0,0,2,2}, {0,0,0,0} }, {{0,0,0,0},{0,0,0,0}}, 1,  0,2,  {0,0,0,0}, {0,0,0,0}, {0,0,0,0} },   /* ##   */
  18.       { 0x0000cc00, 6,  { {0,0,2,2}, {0,0,0,0} }, {{0,0,0,0},{0,0,0,0}}, 1,  0,2,  {0,0,0,0}, {0,0,0,0}, {0,0,0,0} },   /* ##   */
  19.       { 0x0000cc00, 6,  { {0,0,2,2}, {0,0,0,0} }, {{0,0,0,0},{0,0,0,0}}, 1,  0,2,  {0,0,0,0}, {0,0,0,0}, {0,0,0,0} },   /*      */
  20.       { 0x0000cc00, 6,  { {0,0,2,2}, {0,0,0,0} }, {{0,0,0,0},{0,0,0,0}}, 1,  0,2,  {0,0,0,0}, {0,0,0,0}, {0,0,0,0} } }, /*      */
  21.   },
  22.  
  23.   { /* Shape 2 */
  24.     { { 0x00004e00, 5,  { {0,1,3,1}, {1,0,1,1} }, {{0,0,0,0},{0,0,0,0}}, 2,  0,3,  {0,0,0,0}, {0,0,0,0}, {0,0,0,0} },   /*  #   */
  25.       { 0x00004640, 5,  { {1,0,1,3}, {2,1,1,1} }, {{0,0,0,0},{0,0,0,0}}, 2,  1,2,  {0,0,0,0}, {0,0,0,0}, {0,0,0,0} },   /* ###  */
  26.       { 0x00000e40, 6,  { {0,1,3,1}, {1,2,1,1} }, {{0,0,0,0},{0,0,0,0}}, 2,  0,3,  {0,0,0,0}, {0,0,0,0}, {0,0,0,0} },   /*      */
  27.       { 0x00004c40, 5,  { {1,0,1,3}, {0,1,1,1} }, {{0,0,0,0},{0,0,0,0}}, 2,  0,2,  {0,0,0,0}, {0,0,0,0}, {0,0,0,0} } }, /*      */
  28.   },
  29.  
  30.   { /* Shape 3 */
  31.     { { 0x0000c600, 6,  { {0,0,2,1}, {1,1,2,1} }, {{0,0,0,0},{0,0,0,0}}, 2,  0,3,  {0,0,0,0}, {0,0,0,0}, {0,0,0,0} },   /* ##   */
  32.       { 0x00004c80, 7,  { {1,0,1,2}, {0,1,1,2} }, {{0,0,0,0},{0,0,0,0}}, 2,  0,2,  {0,0,0,0}, {0,0,0,0}, {0,0,0,0} },   /*  ##  */
  33.       { 0x0000c600, 6,  { {0,0,2,1}, {1,1,2,1} }, {{0,0,0,0},{0,0,0,0}}, 2,  0,3,  {0,0,0,0}, {0,0,0,0}, {0,0,0,0} },   /*      */
  34.       { 0x00004c80, 7,  { {1,0,1,2}, {0,1,1,2} }, {{0,0,0,0},{0,0,0,0}}, 2,  0,2,  {0,0,0,0}, {0,0,0,0}, {0,0,0,0} } }, /*      */
  35.   },
  36.  
  37.   { /* Shape 4 */
  38.     { { 0x00006c00, 6,  { {1,0,2,1}, {0,1,2,1} }, {{0,0,0,0},{0,0,0,0}}, 2,  0,3,  {0,0,0,0}, {0,0,0,0}, {0,0,0,0} },   /*  ##  */
  39.       { 0x00008c40, 7,  { {0,0,1,2}, {1,1,1,2} }, {{0,0,0,0},{0,0,0,0}}, 2,  0,2,  {0,0,0,0}, {0,0,0,0}, {0,0,0,0} },   /* ##   */
  40.       { 0x00006c00, 6,  { {1,0,2,1}, {0,1,2,1} }, {{0,0,0,0},{0,0,0,0}}, 2,  0,3,  {0,0,0,0}, {0,0,0,0}, {0,0,0,0} },   /*      */
  41.       { 0x00008c40, 7,  { {0,0,1,2}, {1,1,1,2} }, {{0,0,0,0},{0,0,0,0}}, 2,  0,2,  {0,0,0,0}, {0,0,0,0}, {0,0,0,0} } }, /*      */
  42.   },
  43.  
  44.   { /* Shape 5 */
  45.     { { 0x00002e00, 6,  { {2,0,1,1}, {0,1,3,1} }, {{0,0,0,0},{0,0,0,0}}, 2,  0,3,  {0,0,0,0}, {0,0,0,0}, {0,0,0,0} },   /*   #  */
  46.       { 0x000088c0, 7,  { {0,0,1,3}, {1,2,1,1} }, {{0,0,0,0},{0,0,0,0}}, 2,  0,2,  {0,0,0,0}, {0,0,0,0}, {0,0,0,0} },   /* ###  */
  47.       { 0x0000e800, 6,  { {0,0,3,1}, {0,1,1,1} }, {{0,0,0,0},{0,0,0,0}}, 2,  0,3,  {0,0,0,0}, {0,0,0,0}, {0,0,0,0} },   /*      */
  48.       { 0x0000c440, 7,  { {1,0,1,3}, {0,0,1,1} }, {{0,0,0,0},{0,0,0,0}}, 2,  0,2,  {0,0,0,0}, {0,0,0,0}, {0,0,0,0} } }, /*      */
  49.   },
  50.  
  51.   { /* Shape 6 */
  52.     { { 0x0000e200, 6,  { {0,0,3,1}, {2,1,1,1} }, {{0,0,0,0},{0,0,0,0}}, 2,  0,3,  {0,0,0,0}, {0,0,0,0}, {0,0,0,0} },   /* ###  */
  53.       { 0x000044c0, 7,  { {1,0,1,3}, {0,2,1,1} }, {{0,0,0,0},{0,0,0,0}}, 2,  0,2,  {0,0,0,0}, {0,0,0,0}, {0,0,0,0} },   /*   #  */
  54.       { 0x00008e00, 6,  { {0,1,3,1}, {0,0,1,1} }, {{0,0,0,0},{0,0,0,0}}, 2,  0,3,  {0,0,0,0}, {0,0,0,0}, {0,0,0,0} },   /*      */
  55.       { 0x0000c880, 7,  { {0,0,1,3}, {1,0,1,1} }, {{0,0,0,0},{0,0,0,0}}, 2,  0,2,  {0,0,0,0}, {0,0,0,0}, {0,0,0,0} } }, /*      */
  56.   },
  57.  
  58.   { /* Quayle */
  59.     { { 0x00000400,  21, { {1,1,1,1}, {0,0,0,0} }, {{0,0,0,0},{0,0,0,0}}, 1,  1,1, {0,0,0,0}, {0,0,0,0}, {0,0,0,0} },   /*      */
  60.       { 0x00000400, 272, { {1,1,1,1}, {0,0,0,0} }, {{0,0,0,0},{0,0,0,0}}, 1,  1,1, {0,0,0,0}, {0,0,0,0}, {0,0,0,0} },   /*  #   */
  61.       { 0x00000400, 119, { {1,1,1,1}, {0,0,0,0} }, {{0,0,0,0},{0,0,0,0}}, 1,  1,1, {0,0,0,0}, {0,0,0,0}, {0,0,0,0} },   /*      */
  62.       { 0x00000400, 645, { {1,1,1,1}, {0,0,0,0} }, {{0,0,0,0},{0,0,0,0}}, 1,  1,1, {0,0,0,0}, {0,0,0,0}, {0,0,0,0} } }, /*      */
  63.   }
  64. };
  65.  
  66. void define_shapes()
  67. {
  68.   Pixmap boxstipple;
  69.   int s, r, x, y;
  70.   
  71.   /* First create the stipple for the boxes, depending on the box size. */
  72.   {
  73.     XGCValues gcv;
  74.     GC cleargc, setgc, checkgc;
  75.     Pixmap graytile;
  76.     static XPoint points[] = 
  77.     { 
  78.       { 0,1 }, 
  79.       { 1,0 }, 
  80.     };
  81.  
  82.     /* This long, complicated thing is intended to reduce traffic to the server: 
  83.        create a gray stipple first, then spray it over the box to make the final
  84.        stipple. */
  85.  
  86.     graytile = XCreatePixmap( XtDisplay(canvas), XtWindow(canvas), 2, 2, 1 );
  87.     gcv.foreground = gcv.background = 0;
  88.     cleargc = XCreateGC( XtDisplay(canvas), graytile, (unsigned long) GCForeground|GCBackground, &gcv );
  89.     gcv.foreground = 1; 
  90.     setgc = XCreateGC( XtDisplay(canvas), graytile, (unsigned long) GCForeground|GCBackground, &gcv );
  91.     XFillRectangle( XtDisplay(canvas), graytile, cleargc, 0, 0, 2, 2 );
  92.     XDrawPoints( XtDisplay(canvas), graytile, setgc, points, 2, CoordModeOrigin );
  93.  
  94.     /* Now create the box. */
  95.  
  96.     boxstipple = XCreatePixmap( XtDisplay(canvas), XtWindow(canvas), 
  97.                    resources.boxsize, resources.boxsize, 1 );
  98.     gcv.tile = graytile;
  99.     gcv.fill_style = FillTiled;
  100.     checkgc = XCreateGC( XtDisplay(canvas), boxstipple, 
  101.             (unsigned long) GCForeground|GCBackground|GCTile|GCFillStyle, &gcv );
  102.     XFillRectangle( XtDisplay(canvas), boxstipple, checkgc, 0, 0, 
  103.            resources.boxsize-1, resources.boxsize-1 );
  104.     XDrawLine( XtDisplay(canvas), boxstipple, setgc, 0, 0, resources.boxsize-2, 0 );
  105.     XDrawLine( XtDisplay(canvas), boxstipple, setgc, 0, 1, 0, resources.boxsize-2 );
  106.     XDrawLine( XtDisplay(canvas), boxstipple, cleargc, resources.boxsize-1, 0, 
  107.           resources.boxsize-1, resources.boxsize-1 );
  108.     XDrawLine( XtDisplay(canvas), boxstipple, cleargc, 0, resources.boxsize-1,
  109.           resources.boxsize-2, resources.boxsize-1 );
  110.     
  111.     /* Now free up all this garbage. */
  112.  
  113.     XFreeGC( XtDisplay(canvas), setgc );
  114.     XFreeGC( XtDisplay(canvas), cleargc );
  115.     XFreeGC( XtDisplay(canvas), checkgc );
  116.     XFreePixmap( XtDisplay(canvas), graytile );
  117.   }
  118.  
  119.   /* First set the highesty values (could have specified these statically, but the
  120.      human cost is too high.  This is one-shot anyway). */
  121.  
  122.   for (s = 0; s < XtNumber(shape); s++)
  123.     {
  124.       shape_ptr sh = &shape[s];
  125.       XGCValues gcv;
  126.  
  127.       for (r = 0; r < 4; r++)
  128.     {
  129.       /* working on shape s */
  130.  
  131.       rotshape_ptr rot = &sh->forms[r];
  132.       unsigned long unitson;
  133.       int i;
  134.  
  135.  
  136.       /* Scale the x,y,width,length */
  137.  
  138.       for (i = 0; i < rot->nrect; i++)
  139.         {
  140.           XRectangle *rec = &rot->rect[i];
  141.  
  142.           *rec = rot->urect[i];
  143.  
  144.           rec->x *= resources.boxsize;
  145.           rec->y *= resources.boxsize;
  146.           rec->width *= resources.boxsize;
  147.           rec->height *= resources.boxsize;
  148.         }
  149.  
  150.       rot->shadowx *= resources.boxsize;
  151.       rot->shadowwidth *= resources.boxsize;
  152.  
  153.       /* set the highesty values. */
  154.  
  155.       unitson = rot->unitson;
  156.       for (x = 0; x < 4; x++)
  157.         {
  158.           rot->highesty[x] = rot->highestx[x] = 0;
  159.           rot->lowestx[x] = -2;
  160.  
  161.         }
  162.  
  163.       for (y = 3; y >= 0; y -- )
  164.         for (x = 3; x >= 0; x--)
  165.           {
  166.         if (unitson & 1)
  167.           {
  168.             if (rot->highesty[x] == 0)
  169.               rot->highesty[x] = y+1;
  170.             if (rot->highestx[y] == 0)
  171.               rot->highestx[y] = x+1;
  172.             rot->lowestx[y] = x-1;
  173.           }
  174.         unitson >>= 1;
  175.           }
  176.     }
  177.  
  178.       /* Now allocate the graphics context, and set it properly. */
  179.  
  180.       gcv.foreground = sh->foreground;
  181.       gcv.background = sh->background;
  182.       gcv.stipple = boxstipple;
  183.       gcv.fill_style = FillOpaqueStippled;
  184.  
  185.       sh->gc = XCreateGC( XtDisplay(canvas), XtWindow(canvas),
  186.              (unsigned long) GCForeground|GCBackground|GCStipple|GCFillStyle,
  187.              &gcv );
  188.     }
  189. }
  190.  
  191.  
  192. void store_shape(shape_no, xpos, ypos, rot)
  193.   int     shape_no, xpos, ypos, rot;
  194. {
  195.   register unsigned long unitson = shape[shape_no].forms[rot].unitson;
  196.  
  197.   int y, x;
  198.  
  199.   for (y = ypos+3; y >= ypos; y--)
  200.     for (x = xpos+3; x >= xpos; x--)
  201.       {
  202.  
  203.     if ((x >= 0) && (y >= 0))
  204.       if (unitson & 0x00000001)
  205.         grid[x][y] = &shape[shape_no];
  206.     unitson >>= 1;
  207.       }
  208. }
  209.  
  210. extern long random();
  211.  
  212. void create_shape()
  213. {
  214.   shape_no = next_no;
  215.   rot = next_rot;
  216.   if (resources.quayle)
  217.     next_no = 7;
  218.   else
  219.     next_no = random() % 7;
  220.   next_rot = random() % 4;
  221.   xpos = (UWIDTH / 2) - 1;
  222.   ypos = -4;
  223. }
  224. /*
  225. emacs mode: indented-text
  226.  
  227. emacs Local Variables: 
  228. emacs mode: c 
  229. emacs c-indent-level: 2
  230. emacs c-continued-statement-offset: 2
  231. emacs c-continued-brace-offset: -2
  232. emacs c-tab-always-indent: nil
  233. emacs c-brace-offset: 0 
  234. emacs tab-width: 8
  235. emacs tab-stop-list: (2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84)
  236. emacs End:
  237. */
  238.