home *** CD-ROM | disk | FTP | other *** search
/ Game.EXE 2001 January / execd1200.iso / Shareware / Blocks 3 / setup.exe / Source / LASER.C < prev    next >
Encoding:
C/C++ Source or Header  |  2000-10-03  |  3.0 KB  |  146 lines

  1. #include <allegro.h>
  2. #include <jgmod.h>
  3. #include <blocks3.h>
  4.  
  5. int x, y, z, dx, dy;
  6.  
  7. void Laser(void)
  8. {
  9.  int i, j, k;
  10.  int map_laser_back[20][15][2];
  11.  
  12.  for (i = 0; i < 20; i++)
  13.  for (j = 0; j < 15; j++)
  14.  {
  15.   map_laser_back[i][j][0] = map_laser[i][j][0];
  16.   map_laser_back[i][j][1] = map_laser[i][j][1];
  17.  
  18.   map_laser[i][j][0] = 0;
  19.   map_laser[i][j][1] = 0;
  20.  }
  21.  
  22.  for (i = 0; i < box_count; i++)
  23.  {
  24.   if (box[i].type & LASER)
  25.   {
  26.    if (box[i].type == LASER_4WAY)
  27.    {
  28.     Start_XYZ(box[i].x, box[i].y, box[i].z, box[i].dx, box[i].dy, 1);
  29.     Track_Laser();
  30.     Start_XYZ(box[i].x, box[i].y, box[i].z, box[i].dx, box[i].dy, 2);
  31.     Track_Laser();
  32.     Start_XYZ(box[i].x, box[i].y, box[i].z, box[i].dx, box[i].dy, 4);
  33.     Track_Laser();
  34.     Start_XYZ(box[i].x, box[i].y, box[i].z, box[i].dx, box[i].dy, 8);
  35.     Track_Laser();
  36.    }
  37.    else
  38.    {
  39.     Start_XYZ(box[i].x, box[i].y, box[i].z, box[i].dx, box[i].dy, box[i].dir);
  40.     Track_Laser();
  41.    }
  42.   }
  43.  }
  44.  
  45.  
  46.  for (i = 0; i < 20; i++)
  47.  for (j = 0; j < 15; j++)
  48.  for (k = 0; k < 2; k++)
  49.  if (map_laser[i][j][k] != map_laser_back[i][j][k]) DirtyList(i*32, j*32, k*8, 32, 40, blank);
  50.  
  51. }
  52.  
  53. void Start_XYZ(int b_x, int b_y, int b_z, int b_dx, int b_dy, int b_dir)
  54. {
  55.  dx = 0;
  56.  dy = 0;
  57.  
  58.  if (b_dir == 1) dy = -1;
  59.  if (b_dir == 2) dx = 1;
  60.  if (b_dir == 4) dy = 1;
  61.  if (b_dir == 8) dx = -1;
  62.  
  63.  if ((!b_dx) && (!b_dy))
  64.  {
  65.   x = (b_x)/32 + dx;
  66.   y = (b_y)/32 + dy;
  67.  }
  68.  
  69.  if ((b_dx) && (dy))
  70.  {
  71.   x = (b_x + 16)/32;
  72.   y = b_y/32 + dy;
  73.  }
  74.  
  75.  if ((b_dy) && (dx))
  76.  {
  77.   x = b_x/32 + dx;
  78.   y = (b_y + 16)/32;
  79.  }
  80.  
  81.  if ((b_dx) && (dx))
  82.  {
  83.   x = (b_x)/32 + dx;
  84.   y = b_y/32;
  85.  }
  86.  
  87.  if ((b_dy) && (dy))
  88.  {
  89.   x = b_x/32;
  90.   y = (b_y)/32 + dy;
  91.  }
  92.  
  93.  
  94.  if ((b_dx ==  1) && (dx)) x++;
  95.  if ((b_dy ==  1) && (dy)) y++;
  96.  
  97.  z = b_z/8;
  98. }
  99.  
  100. void Track_Laser(void)
  101. {
  102.  int j;
  103.  
  104.    while ((x > 0) && (x < 20) && (y > 0) && (y < 15) &&
  105.          ((map[x][y][z] == 0) || (map[x][y][z] & MIRROR)
  106.            || (map[x][y][z] & BOMB) || (map[x][y][z] & PICKUP)
  107.            || (map[x][y][z] & RESERVE0)
  108.            || (map[x][y][z] == FALL)
  109.            || (map[x][y][z] & SWITCH)))
  110.    {
  111.     if ((map[x][y][z] == 0)
  112.     || (map[x][y][z] & BOMB)
  113.     || (map[x][y][z] & PICKUP)
  114.     || (map[x][y][z] & RESERVE0)
  115.     || (map[x][y][z] & SWITCH)
  116.     || (map[x][y][z] == FALL))
  117.     {
  118.      if (dx) map_laser[x][y][z] = map_laser[x][y][z] | 2;
  119.      else map_laser[x][y][z] = map_laser[x][y][z] | 1;
  120.     }
  121.  
  122.     if ((map[x][y][z] & MIRROR_PLUS) == MIRROR_PLUS)
  123.     {
  124.      if ((dx == 1) || (dy == 1)) map_laser[x][y][z] = map_laser[x][y][z] | 32;
  125.      else map_laser[x][y][z] = map_laser[x][y][z] | 8;
  126.  
  127.      j = dx;
  128.      dx = -dy;
  129.      dy = -j;
  130.     }
  131.  
  132.     if ((map[x][y][z] & MIRROR_MINUS) == MIRROR_MINUS)
  133.     {
  134.      if ((dx == 1) || (dy == -1)) map_laser[x][y][z] = map_laser[x][y][z] | 16;
  135.      else map_laser[x][y][z] = map_laser[x][y][z] | 4;
  136.  
  137.      j = dx;
  138.      dx = dy;
  139.      dy = j;
  140.     }
  141.  
  142.     x += dx;
  143.     y += dy;
  144.    }
  145. }
  146.