home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / games / sot.zip / SOTS.C < prev    next >
Text File  |  1988-08-23  |  12KB  |  298 lines

  1. /********** The Son of Tetris Project ************/
  2.  
  3. /************ SHAPE DEFINITIONS ***********/
  4.  
  5. #include <alloc.h>
  6. #include <conio.h>
  7. #include <time.h>        /* Need these to get random number seed */
  8. #include <stdlib.h>
  9.  
  10. #include "sot.h"
  11.  
  12. #define  SHAPE !CLEAR
  13.  
  14. static void   rotate_shape(SHP_TYPE *cur_shape)
  15. {
  16.   int   i, j, wd, ht;
  17.   int  *ptr, *ptr1, *ptr2, *ptr3;
  18.  
  19.   ptr = cur_shape ->map[0];
  20.   ptr1 = cur_shape ->map[1];
  21.   ptr2 = cur_shape ->map[2];
  22.   ptr3 = cur_shape ->map[3];
  23.  
  24.   ht = cur_shape -> ht;
  25.   wd = cur_shape -> wd;
  26.  
  27.   for (j = 0; j < ht; j++)
  28.     for (i = 0; i < wd; i++)
  29.       ptr1[((wd - i - 1) * ht) + j]
  30.     = ptr2[(ht - j - 1) * wd + (wd - i - 1)]
  31.         = ptr3[(ht - j - 1) + i * ht]
  32.         = ptr[j * wd + i];
  33.  
  34. }  /* rotate_shape */
  35.  
  36.  
  37.  
  38. void  init_shapes(void)
  39. {
  40.   SHP_TYPE *cur_shape;
  41.   int       orient;
  42.   int      *ptr;
  43.   long     now;
  44.  
  45.   no_of_shapes = 0;
  46.   srand((unsigned)time(&now) % 37);    /* seed random number */
  47.  
  48. /* ************** Shape 1 ************** */  /* T shape */
  49.  
  50.   cur_shape = malloc(sizeof(SHP_TYPE));
  51.   shp_lst = cur_shape; /* First time only */
  52.   cur_shape -> ht = 3;                              /* Height */
  53.   cur_shape -> wd = 3;                              /* Width */
  54.   cur_shape -> col = BLUE;                          /* Colour */
  55.   for (orient = 0; orient < 4; orient++)            /* Reserve space for maps */
  56.     cur_shape -> map[orient] =
  57.       calloc(cur_shape -> ht * cur_shape -> wd,sizeof(int));
  58.  
  59.   ptr = cur_shape -> map[0];                        /* Define shape */
  60.   ptr[3] = ptr[4] = ptr[5] = ptr[7] = SHAPE;
  61.  
  62.   rotate_shape(cur_shape);                          /* Define other orientations */
  63.   no_of_shapes++;
  64.  
  65. /* ************** Shape 2 ************** */ /* Line */
  66.  
  67.   cur_shape -> next_shp = malloc(sizeof(SHP_TYPE));
  68.   cur_shape = cur_shape -> next_shp;                /* Link into list */
  69.   cur_shape -> ht = 3;                              /* Height */
  70.   cur_shape -> wd = 4;                              /* Width */
  71.   cur_shape -> col = GREEN;                         /* Colour */
  72.   for (orient = 0; orient < 4; orient++)            /* Reserve space for maps */
  73.     cur_shape -> map[orient] =
  74.       calloc(cur_shape -> ht * cur_shape -> wd,sizeof(int));
  75.  
  76.   ptr = cur_shape -> map[0];                        /* Define shape */
  77.   ptr[4] = ptr[5] = ptr[6] = ptr[7] = SHAPE;
  78.  
  79.   rotate_shape(cur_shape);                          /* Define other orientations */
  80.   no_of_shapes++;
  81.  
  82. /* ************** Shape 3************** */ /* Box */
  83.  
  84.   cur_shape -> next_shp = malloc(sizeof(SHP_TYPE));
  85.   cur_shape = cur_shape -> next_shp;                /* Link into list */
  86.   cur_shape -> ht = 2;                              /* Height */
  87.   cur_shape -> wd = 2;                              /* Width */
  88.   cur_shape -> col = CYAN;                          /* Colour */
  89.   for (orient = 0; orient < 4; orient++)            /* Reserve space for maps */
  90.     cur_shape -> map[orient] =
  91.       calloc(cur_shape -> ht * cur_shape -> wd,sizeof(int));
  92.  
  93.   ptr = cur_shape -> map[0];                        /* Define shape */
  94.   ptr[0] = ptr[1] = ptr[2] = ptr[3] = SHAPE;
  95.  
  96.   rotate_shape(cur_shape);                          /* Define other orientations */
  97.   no_of_shapes++;
  98.  
  99. /* ************** Shape 4************** */ /* 'L' */
  100.  
  101.   cur_shape -> next_shp = malloc(sizeof(SHP_TYPE));
  102.   cur_shape = cur_shape -> next_shp;                /* Link into list */
  103.   cur_shape -> ht = 2;                              /* Height */
  104.   cur_shape -> wd = 3;                              /* Width */
  105.   cur_shape -> col = RED;                           /* Colour */
  106.   for (orient = 0; orient < 4; orient++)            /* Reserve space for maps */
  107.     cur_shape -> map[orient] =
  108.       calloc(cur_shape -> ht * cur_shape -> wd,sizeof(int));
  109.  
  110.   ptr = cur_shape -> map[0];                        /* Define shape */
  111.   ptr[0] = ptr[1] = ptr[2] = ptr[5] = SHAPE;
  112.  
  113.   rotate_shape(cur_shape);                          /* Define other orientations */
  114.   no_of_shapes++;
  115.  
  116. /* ************** Shape 5************** */ /* Backwards 'L' */
  117.  
  118.   cur_shape -> next_shp = malloc(sizeof(SHP_TYPE));
  119.   cur_shape = cur_shape -> next_shp;                /* Link into list */
  120.   cur_shape -> ht = 2;                              /* Height */
  121.   cur_shape -> wd = 3;                              /* Width */
  122.   cur_shape -> col = MAGENTA;                       /* Colour */
  123.   for (orient = 0; orient < 4; orient++)            /* Reserve space for maps */
  124.     cur_shape -> map[orient] =
  125.       calloc(cur_shape -> ht * cur_shape -> wd,sizeof(int));
  126.  
  127.   ptr = cur_shape -> map[0];                        /* Define shape */
  128.   ptr[0] = ptr[1] = ptr[2] = ptr[3] = SHAPE;
  129.  
  130.   rotate_shape(cur_shape);                          /* Define other orientations */
  131.   no_of_shapes++;
  132.  
  133. /* ************** Shape 6************** */ /* 'N' thingy */
  134.  
  135.   cur_shape -> next_shp = malloc(sizeof(SHP_TYPE));
  136.   cur_shape = cur_shape -> next_shp;                /* Link into list */
  137.   cur_shape -> ht = 2;                              /* Height */
  138.   cur_shape -> wd = 3;                              /* Width */
  139.   cur_shape -> col = BROWN;                         /* Colour */
  140.   for (orient = 0; orient < 4; orient++)            /* Reserve space for maps */
  141.     cur_shape -> map[orient] =
  142.       calloc(cur_shape -> ht * cur_shape -> wd,sizeof(int));
  143.  
  144.   ptr = cur_shape -> map[0];                        /* Define shape */
  145.   ptr[0] = ptr[1] = ptr[4] = ptr[5] = SHAPE;
  146.  
  147.   rotate_shape(cur_shape);                          /* Define other orientations */
  148.   no_of_shapes++;
  149.  
  150. /* ************** Shape 7************* */ /* Backwards 'N' thingy */
  151.  
  152.   cur_shape -> next_shp = malloc(sizeof(SHP_TYPE));
  153.   cur_shape = cur_shape -> next_shp;                /* Link into list */
  154.   cur_shape -> ht = 2;                              /* Height */
  155.   cur_shape -> wd = 3;                              /* Width */
  156.   cur_shape -> col = LIGHTGRAY;                     /* Colour */
  157.   cur_shape -> next_shp = NULL;                     /* Seal off end of list */
  158.   for (orient = 0; orient < 4; orient++)            /* Reserve space for maps */
  159.     cur_shape -> map[orient] =
  160.       calloc(cur_shape -> ht * cur_shape -> wd,sizeof(int));
  161.  
  162.   ptr = cur_shape -> map[0];                        /* Define shape */
  163.   ptr[1] = ptr[2] = ptr[3] = ptr[4] = SHAPE;
  164.  
  165.   rotate_shape(cur_shape);                          /* Define other orientations */
  166.   no_of_shapes++;
  167.  
  168.   cur_shape -> next_shp = NULL;                     /* Seal off end of list */
  169.  
  170. /* ************** Shape 8************** */ /* The lone pixel */
  171.  
  172.   cur_shape -> next_shp = malloc(sizeof(SHP_TYPE));
  173.   cur_shape = cur_shape -> next_shp;                /* Link into list */
  174.   cur_shape -> ht = 1;                             /* Height */
  175.   cur_shape -> wd = 1;                              /* Width */
  176.   cur_shape -> col = LIGHTGRAY;                     /* Colour */
  177.   for (orient = 0; orient < 4; orient++)            /* Reserve space for maps */
  178.     cur_shape -> map[orient] =
  179.       calloc(cur_shape -> ht * cur_shape -> wd,sizeof(int));
  180.  
  181.   ptr = cur_shape -> map[0];                        /* Define shape */
  182.   ptr[0] = SHAPE;
  183.  
  184.   rotate_shape(cur_shape);                          /* Define other orientations */
  185.   no_of_shapes++;
  186.  
  187. /* ************** Shape 9 ************** */ /* Line with kink 1*/
  188.  
  189.   cur_shape -> next_shp = malloc(sizeof(SHP_TYPE));
  190.   cur_shape = cur_shape -> next_shp;                /* Link into list */
  191.   cur_shape -> ht = 3;                              /* Height */
  192.   cur_shape -> wd = 4;                              /* Width */
  193.   cur_shape -> col = GREEN;                         /* Colour */
  194.   for (orient = 0; orient < 4; orient++)            /* Reserve space for maps */
  195.     cur_shape -> map[orient] =
  196.       calloc(cur_shape -> ht * cur_shape -> wd,sizeof(int));
  197.  
  198.   ptr = cur_shape -> map[0];                        /* Define shape */
  199.   ptr[4] = ptr[5] = ptr[2] = ptr[7] = SHAPE;
  200.  
  201.   rotate_shape(cur_shape);                          /* Define other orientations */
  202.   no_of_shapes++;
  203.  
  204. /* ************** Shape 11 ************** */ /* Block with carbuncle */
  205.  
  206.   cur_shape -> next_shp = malloc(sizeof(SHP_TYPE));
  207.   cur_shape = cur_shape -> next_shp;                /* Link into list */
  208.   cur_shape -> ht = 3;                              /* Height */
  209.   cur_shape -> wd = 3;                              /* Width */
  210.   cur_shape -> col = RED;                           /* Colour */
  211.   for (orient = 0; orient < 4; orient++)            /* Reserve space for maps */
  212.     cur_shape -> map[orient] =
  213.       calloc(cur_shape -> ht * cur_shape -> wd,sizeof(int));
  214.  
  215.   ptr = cur_shape -> map[0];                        /* Define shape */
  216.   ptr[2] = ptr[4] = ptr[7] = ptr[8] = SHAPE;
  217.  
  218.   rotate_shape(cur_shape);                          /* Define other orientations */
  219.   no_of_shapes++;
  220.  
  221. /* ************** Shape 12 ************** */ /* Lambda */
  222.  
  223.   cur_shape -> next_shp = malloc(sizeof(SHP_TYPE));
  224.   cur_shape = cur_shape -> next_shp;                /* Link into list */
  225.   cur_shape -> ht = 3;                              /* Height */
  226.   cur_shape -> wd = 3;                              /* Width */
  227.   cur_shape -> col = MAGENTA;                       /* Colour */
  228.   for (orient = 0; orient < 4; orient++)            /* Reserve space for maps */
  229.     cur_shape -> map[orient] =
  230.       calloc(cur_shape -> ht * cur_shape -> wd,sizeof(int));
  231.  
  232.   ptr = cur_shape -> map[0];                        /* Define shape */
  233.   ptr[0] = ptr[4] = ptr[6] = ptr[8] = SHAPE;
  234.  
  235.   rotate_shape(cur_shape);                          /* Define other orientations */
  236.   no_of_shapes++;
  237.  
  238. /* ************** Shape 13************** */ /* The big Y */
  239.  
  240.   cur_shape -> next_shp = malloc(sizeof(SHP_TYPE));
  241.   cur_shape = cur_shape -> next_shp;                /* Link into list */
  242.   cur_shape -> ht = 3;                              /* Height */
  243.   cur_shape -> wd = 3;                              /* Width */
  244.   cur_shape -> col = BROWN;                         /* Colour */
  245.   for (orient = 0; orient < 4; orient++)            /* Reserve space for maps */
  246.     cur_shape -> map[orient] =
  247.       calloc(cur_shape -> ht * cur_shape -> wd,sizeof(int));
  248.  
  249.   ptr = cur_shape -> map[0];                        /* Define shape */
  250.   ptr[0] = ptr[2] = ptr[4] = ptr[7] = SHAPE;
  251.  
  252.   rotate_shape(cur_shape);                          /* Define other orientations */
  253.   no_of_shapes++;
  254.  
  255. /* ************** Shape 8************* */ /* Hollow sprite thingy */
  256.  
  257.   cur_shape -> next_shp = malloc(sizeof(SHP_TYPE));
  258.   cur_shape = cur_shape -> next_shp;                /* Link into list */
  259.   cur_shape -> ht = 3;                              /* Height */
  260.   cur_shape -> wd = 3;                              /* Width */
  261.   cur_shape -> col = BLUE;                          /* Colour */
  262.   cur_shape -> next_shp = NULL;                     /* Seal off end of list */
  263.   for (orient = 0; orient < 4; orient++)            /* Reserve space for maps */
  264.     cur_shape -> map[orient] =
  265.       calloc(cur_shape -> ht * cur_shape -> wd,sizeof(int));
  266.  
  267.   ptr = cur_shape -> map[0];                        /* Define shape */
  268.   ptr[1] = ptr[3] = ptr[5] = ptr[7] = SHAPE;
  269.  
  270.   rotate_shape(cur_shape);                          /* Define other orientations */
  271.   no_of_shapes++;
  272.  
  273. /* ************** Shape 10 ************** */ /* Line with kink 2*/
  274.  
  275.   cur_shape -> next_shp = malloc(sizeof(SHP_TYPE));
  276.   cur_shape = cur_shape -> next_shp;                /* Link into list */
  277.   cur_shape -> ht = 3;                              /* Height */
  278.   cur_shape -> wd = 4;                              /* Width */
  279.   cur_shape -> col = CYAN;                          /* Colour */
  280.   for (orient = 0; orient < 4; orient++)            /* Reserve space for maps */
  281.     cur_shape -> map[orient] =
  282.       calloc(cur_shape -> ht * cur_shape -> wd,sizeof(int));
  283.  
  284.   ptr = cur_shape -> map[0];                        /* Define shape */
  285.   ptr[4] = ptr[5] = ptr[6] = ptr[3] = SHAPE;
  286.  
  287.   rotate_shape(cur_shape);                          /* Define other orientations */
  288.   no_of_shapes++;
  289.  
  290.  
  291.   cur_shape -> next_shp = NULL;                     /* Seal off end of list */
  292. } /* init_shapes */
  293.  
  294.  
  295.  
  296.  
  297.  
  298.