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 / support.c < prev    next >
C/C++ Source or Header  |  1991-08-30  |  3KB  |  134 lines

  1. #include "defs.h"
  2.  
  3. block_can_drop(shape_no, xpos, ypos, rot)
  4.         int     shape_no, xpos, ypos, rot;
  5. {
  6.   rotshape_ptr r = &shape[shape_no].forms[rot];
  7.   int     x, y, c;
  8.  
  9.   /* Find highest non-zero ycoordinate for each x */
  10.  
  11.   for (x = 0; x < 4; x++)
  12.     {
  13.       y = ypos + (c = r->highesty[x]);
  14.       if ((c != 0) && (y >= 0))
  15.     if ((y >= UHEIGHT) || (grid[xpos+x][y] != NULL))
  16.       return (FALSE);
  17.     }
  18.   return TRUE;
  19. }
  20.  
  21. block_can_left(shape_no, xpos, ypos, rot)
  22.   int     shape_no, xpos, ypos, rot;
  23. {
  24.   int x, y, yg, c;
  25.   rotshape_ptr r = &shape[shape_no].forms[rot];
  26.   
  27.   /* get the lowest x value for y, in (3-c) */
  28.   
  29.  
  30.   for (y = 0, yg = ypos; y < 4; y++, yg++) 
  31.     {
  32.       x = xpos + (c = r->lowestx[y]);
  33.       if (c != -2)
  34.     if ((x < 0) || ((y >= 0) && (grid[x][yg] != NULL)))
  35.       return (FALSE);
  36.     }
  37.   return TRUE;
  38. }
  39.  
  40. block_can_right(shape_no, xpos, ypos, rot)
  41.   int     shape_no, xpos, ypos, rot;
  42. {
  43.   int     x, y, yg, c;
  44.   rotshape_ptr r = &shape[shape_no].forms[rot];
  45.  
  46.   for (y = 0, yg = ypos; y < 4; y++, yg++)
  47.     {
  48.       x = xpos + (c = r->highestx[y]);
  49.       if ((c != 0) && (x >= 0))
  50.     if ((x == UWIDTH) || ((y >= 0) && (grid[x][yg] != NULL)))
  51.       return (FALSE);
  52.     }
  53.   return TRUE;
  54. }
  55.  
  56. remove_full_lines(starty)
  57.   int     starty;
  58. {
  59.   int     y, y2, ymax, x;
  60.   unsigned char linefull[UHEIGHT], foundfull;
  61.  
  62.   ymax = starty + 4;
  63.   if (UHEIGHT < ymax) ymax = UHEIGHT;
  64.   
  65.   foundfull = FALSE;
  66.   for (y = starty; y < ymax; y++) {
  67.     linefull[y] = TRUE;
  68.     for (x = 0; x < UWIDTH; x++)
  69.       if (grid[x][y] == NULL) {
  70.     linefull[y] = False;
  71.     break;
  72.       }
  73.     foundfull |= linefull[y];
  74.     if (linefull[y]) 
  75.       XFillRectangle( XtDisplay(canvas), XtWindow(canvas), erasegc,
  76.          0, y*resources.boxsize, resources.boxsize*UWIDTH, resources.boxsize );
  77.   }
  78.   if (!foundfull) return;
  79.   
  80.   /* Wait a bit for the user to see it. */
  81.       
  82.   XFlush(XtDisplay(toplevel));
  83.   sleep(1);  /* cannot use usleep because incompatible
  84.         with hpux. */
  85.   
  86.   /* Now change the data. */
  87.  
  88.   for (y = starty; y < ymax; y++) 
  89.     if (linefull[y]) 
  90.       {
  91.     for (y2 = y; y2 > 0; y2--)
  92.       for (x = 0; x < UWIDTH; x++) 
  93.         grid[x][y2] = grid[x][y2 - 1];
  94.     for (x = 0; x < UWIDTH; x++)
  95.       grid[x][0] = NULL;
  96.       
  97.     XCopyArea(XtDisplay(toplevel),
  98.           XtWindow(canvas),XtWindow(canvas),gc,
  99.           0,0, resources.boxsize*UWIDTH, y*resources.boxsize,0, resources.boxsize);
  100.     XClearArea(XtDisplay(toplevel),XtWindow(canvas),
  101.            0, 0, resources.boxsize*UWIDTH, resources.boxsize, False );
  102.     rows++;
  103.       }
  104.  
  105.   XFlush(XtDisplay(toplevel));
  106. }
  107.  
  108. check_rot(shape_no, xpos, ypos, newrot)
  109.         int     shape_no, xpos, ypos, newrot;
  110. {
  111.   rotshape_ptr sh = &shape[shape_no].forms[newrot];
  112.   int x, y, i;
  113.  
  114.   for (i = 0; i < sh->nrect; i++)
  115.     {
  116.       XRectangle *r = &sh->urect[i];
  117.  
  118.       int ymax = ypos+r->y+r->height;
  119.       for (y = ypos+r->y; y < ymax; y++) 
  120.     if (y >= 0)
  121.       {
  122.         int xmax = xpos+r->x+r->width;
  123.         
  124.         if (y >= UHEIGHT) return FALSE;
  125.         for (x = xpos+r->x; x < xmax; x++)
  126.           {
  127.         if ((x < 0) || (x >= UWIDTH) || (grid[x][y] != NULL)) return FALSE;
  128.           }
  129.         
  130.       }
  131.     }
  132.   return TRUE;
  133. }
  134.