home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1993 #2 / Image.iso / graphics / acksrc.zip / ACKDOOR.C < prev    next >
Text File  |  1993-06-20  |  6KB  |  262 lines

  1. /*           ACK-3D ( Animation Construction Kit 3D )              */
  2. /* Door routines      */
  3. /* Author: Lary Myers */
  4.  
  5. #include <stdlib.h>
  6. #include <stdio.h>
  7. #include <dos.h>
  8. #include <mem.h>
  9. #include <alloc.h>
  10. #include <io.h>
  11. #include <fcntl.h>
  12. #include <time.h>
  13. #include <string.h>
  14. #include <sys\stat.h>
  15. #include "ack3d.h"
  16. #include "ackext.h"
  17.  
  18. /****************************************************************************
  19. ** Locate a door from its Map coordinate and return the index to the       **
  20. ** caller.                                   **
  21. **                                       **
  22. ****************************************************************************/
  23. int FindDoor(int MapPosn)
  24. {
  25.     int        index;
  26.  
  27. for (index = 0; index < MAX_DOORS; index++)
  28.     {
  29.     if (MapPosn == Door[index].mPos || MapPosn == Door[index].mPos1)
  30.     return(index);
  31.     }
  32.  
  33. return(-1);
  34. }
  35.  
  36. /****************************************************************************
  37. ** Find an empty slot for a door. If the door already occupies a slot and  **
  38. ** it is in a non-closed state then return error.               **
  39. **                                       **
  40. ****************************************************************************/
  41. int FindDoorSlot(int MapPosn)
  42. {
  43.     int        index;
  44.  
  45. index = FindDoor(MapPosn);
  46. if (index >= 0 && Door[index].ColOffset)
  47.     return(-1);
  48.  
  49. for (index = 0; index < MAX_DOORS; index++)
  50.     {
  51.     if (Door[index].mPos == -1)
  52.     return(index);
  53.  
  54.     }
  55.  
  56. return(-1);
  57. }
  58.  
  59. /****************************************************************************
  60. ** Check all the doors to see what state they are in. If a door's column   **
  61. ** offset is non-zero then it is either opening or closing, so add in the  **
  62. ** speed of the door and check for fully open and fully closed conditions. **
  63. **                                       **
  64. **                                       **
  65. ****************************************************************************/
  66. void CheckDoors(int xPlayer,int yPlayer)
  67. {
  68.      int    i,MapPosn,mPos,mPos1;
  69.      int    column,mx,my,DeltaGrid;
  70. unsigned char    mCode,mCode1;
  71.  
  72. for (i = 0; i < MAX_DOORS; i++)
  73.     {
  74.     if (Door[i].ColOffset)
  75.     {
  76.     Door[i].ColOffset += Door[i].Speed;
  77.     mPos = Door[i].mPos;
  78.     mPos1 = Door[i].mPos1;
  79.  
  80.    /* Door is closing and is visible. Put old codes back to make non-passable */
  81.     if (Door[i].Speed < 0 && Door[i].ColOffset < 65)
  82.         {
  83.         MapPosn = (yPlayer & 0xFFC0) + (xPlayer >> 6);
  84.         if (MapPosn == mPos ||
  85.         MapPosn == mPos1)
  86.         {
  87.         Door[i].ColOffset -= Door[i].Speed;
  88.         continue;
  89.         }
  90.  
  91.         if (Door[i].Type == DOOR_XCODE)
  92.         {
  93.         if (xObjGrid[mPos] || xObjGrid[mPos1])
  94.             {
  95.             Door[i].ColOffset -= Door[i].Speed;
  96.             continue;
  97.             }
  98.  
  99.         xGrid[mPos]  = Door[i].mCode;
  100.         xGrid[mPos1] = Door[i].mCode1;
  101.         }
  102.         else
  103.         {
  104.         if (yObjGrid[mPos] || yObjGrid[mPos1])
  105.             {
  106.             Door[i].ColOffset -= Door[i].Speed;
  107.             continue;
  108.             }
  109.         yGrid[mPos]  = Door[i].mCode;
  110.         yGrid[mPos1] = Door[i].mCode1;
  111.         }
  112.  
  113. /* Door is close enough to fully closed to get rid of the door from the array */
  114.         if (Door[i].ColOffset < 3)
  115.         {
  116.         Door[i].ColOffset = 0;
  117.         Door[i].mPos      = -1;
  118.         Door[i].mPos1      = -1;
  119.         }
  120.  
  121.         }
  122.  
  123.  
  124.     if (Door[i].ColOffset > 0xA0)
  125.         Door[i].Speed = -Door[i].Speed;
  126.     }
  127.     }
  128.  
  129.  
  130. /* Now check for any action occuring in a secret door. This is currently  */
  131. /* setup to handle only one door at a time in the X and Y directions, but */
  132. /* it should be fairly straightforward to use a list of doors, similiar      */
  133. /* to normal doors, to handle more than one.                  */
  134. if (xSecretColumn)
  135.     {
  136.     if (xSecretColumn > 0)        /* See if the door is to the right of us */
  137.     {
  138.     mPos = xSecretmPos1;
  139.     DeltaGrid = -1;
  140.     xSecretColumn += DoorSpeed;
  141.     }
  142.     else
  143.     {
  144.     mPos = xSecretmPos;
  145.     DeltaGrid = 0;
  146.     xSecretColumn -= DoorSpeed;
  147.     }
  148.  
  149.     my = mPos & 0xFFC0;
  150.     mx = (mPos - my) << 6;
  151.  
  152.     if (abs(xSecretColumn) > GRID_SIZE)        /* Beyond one grid square */
  153.     {
  154.     mx += xSecretColumn;
  155.     my = my + (mx >> 6);
  156.     if (xGrid[my])                /* No further, an obstruction */
  157.         {
  158.         xGrid[xSecretmPos] = 0;
  159.         xGrid[xSecretmPos1] = 0;
  160.         my += DeltaGrid;
  161.         xGrid[my] = NonSecretCode;
  162.         xGrid[my+1] = NonSecretCode;
  163.         yGrid[my] = NonSecretCode;
  164.         yGrid[my + GRID_WIDTH] = NonSecretCode;
  165.         xSecretColumn = 0;
  166.         }
  167.     else
  168.         {
  169.         if (my != mPos)
  170.         {
  171.         xGrid[xSecretmPos] = 0;
  172.         xGrid[xSecretmPos1] = 0;
  173.         if (xSecretColumn > 0)
  174.             {
  175.             xSecretColumn -= 63;
  176.             xGrid[my] = DOOR_SECRETCODE;
  177.             xSecretmPos1 = my;
  178.             my--;
  179.             xGrid[my] = DOOR_SECRETCODE;
  180.             xSecretmPos = my;
  181.             }
  182.         else
  183.             {
  184.             xSecretColumn += 63;
  185.             xGrid[my] = DOOR_SECRETCODE;
  186.             xGrid[my+1] = DOOR_SECRETCODE;
  187.             xSecretmPos = my;
  188.             xSecretmPos = my+1;
  189.             }
  190.         }
  191.         } /* End if (xGrid[my]) ... else ...     */
  192.     }     /* End if (abs(xSecretColumn) > GRID_SIZE) */
  193.     }          /* End if (xSecretColumn)             */
  194.  
  195. /* Perform same process on a secret door that may be moving in the Y */
  196. /* direction. The same door can move either way, depending on which  */
  197. /* angle the player struck it at.                     */
  198. if (ySecretColumn)
  199.     {
  200.     if (ySecretColumn > 0)
  201.     {
  202.     mPos = ySecretmPos1;
  203.     DeltaGrid = -GRID_WIDTH;
  204.     ySecretColumn += DoorSpeed;
  205.     }
  206.     else
  207.     {
  208.     mPos = ySecretmPos;
  209.     DeltaGrid = 0;
  210.     ySecretColumn -= DoorSpeed;
  211.     }
  212.  
  213.     my = mPos & 0xFFC0;
  214.     mx = (mPos - my) << 6;
  215.  
  216.     if (abs(ySecretColumn) > GRID_SIZE)
  217.     {
  218.     my += ySecretColumn;
  219.     my = (my & 0xFFC0) + (mx >> 6);
  220.     if (yGrid[my])
  221.         {
  222.         yGrid[ySecretmPos] = 0;
  223.         yGrid[ySecretmPos1] = 0;
  224.         my += DeltaGrid;
  225.         xGrid[my] = NonSecretCode;
  226.         xGrid[my+1] = NonSecretCode;
  227.         yGrid[my] = NonSecretCode;
  228.         yGrid[my + GRID_WIDTH] = NonSecretCode;
  229.         ySecretColumn = 0;
  230.         }
  231.     else
  232.         {
  233.         if (my != mPos)
  234.         {
  235.         yGrid[ySecretmPos] = 0;
  236.         yGrid[ySecretmPos1] = 0;
  237.         if (ySecretColumn > 0)
  238.             {
  239.             ySecretColumn -= 63;
  240.             yGrid[my] = DOOR_SECRETCODE;
  241.             ySecretmPos1 = my;
  242.             my -= GRID_WIDTH;
  243.             yGrid[my] = DOOR_SECRETCODE;
  244.             ySecretmPos = my;
  245.             }
  246.         else
  247.             {
  248.             ySecretColumn += 63;
  249.             yGrid[my] = DOOR_SECRETCODE;
  250.             yGrid[my+GRID_WIDTH] = DOOR_SECRETCODE;
  251.             ySecretmPos = my;
  252.             ySecretmPos = my+GRID_WIDTH;
  253.             }
  254.         }
  255.         }
  256.     }
  257.     }
  258.  
  259. }
  260.  
  261.  
  262.