home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / progmisc / acksrc.zip / ACKMAIN.C < prev    next >
Text File  |  1993-06-20  |  10KB  |  556 lines

  1. /*           ACK-3D ( Animation Construction Kit 3D )              */
  2. /* Main entry point   */
  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. **                                       **
  20. ****************************************************************************/
  21. void main(int argc,char *argv[])
  22. {
  23.         int        i,j,done,pos,dflag;
  24.         int        TablePosn;
  25.         int        xPlayer,yPlayer;
  26.         int        PlayerAngle;
  27.         int        x1,y1;
  28.         int        SkyCount;
  29.         int        SkyNumber;
  30.         int        DoFlash;
  31.         long    CosAngle,SinAngle;
  32.         int        Spin,SpinAngle;
  33.         int        DoorDelay;
  34. unsigned    char    sCode;
  35.         long    frames,tStart,tDraw,t1;
  36.  
  37.  
  38. #if DEBUG
  39. dfp = fopen("x.dst","wt");
  40. #else
  41. dfp = NULL;
  42. #endif
  43.  
  44. DoFlash = 1;
  45.  
  46. if (argc > 1)
  47.     {
  48.     for (i = 0; i < argc; i++)
  49.     {
  50.     if (!(stricmp(argv[i+1],"-F")))
  51.         DoFlash = 0;
  52.     }
  53.     }
  54.  
  55. randomize();
  56.  
  57. InitializeMouse();
  58.  
  59. strcpy(PalFile,"ack.pal");
  60. strcpy(GridFile,"ackmap.l01");
  61.  
  62. TopColor      = SkyColor = SKY_COLOR;
  63. BottomColor   = FloorColor = FLOOR_COLOR;
  64. FlashColor    = SKY_FLASH;
  65. SkyCount      = 0;
  66. Spin          = SpinAngle = 0;
  67. CenterRow     = 120;
  68. MaxObjects    = 0;
  69. DoorSpeed     = DEFAULT_DOOR_SPEED;
  70. StartX          = StartY = 96;
  71. StartAngle    = 0;
  72. CurrentLevel  = 1;
  73. NonSecretCode = 1;
  74.  
  75. if (BuildTables())
  76.     exit(1);
  77.  
  78. if (ReadMasterFile("ACK3D.L01"))
  79.     exit(1);
  80.  
  81. if (ReadMapFile())
  82.     exit(1);
  83.  
  84. BuildXYgrid();
  85.  
  86. TopColor    = SkyColor;
  87. BottomColor = FloorColor;
  88. xPlayer        = StartX;
  89. yPlayer        = StartY;
  90. PlayerAngle = StartAngle;
  91. CosAngle    = CosTable[PlayerAngle];
  92. SinAngle    = SinTable[PlayerAngle];
  93.  
  94. ObjList[0].Sides  = 0;
  95. ObjList[0].VidRow = CenterRow;
  96.  
  97.  
  98. keyBoardInit();
  99. oldvec=getvect(KEYBD);
  100. setvect(KEYBD,myInt);
  101.  
  102. graphinit();
  103.  
  104. PageNum = 1;
  105. usepage(PageNum);
  106.  
  107. LoadPalette(PalFile);
  108. NoWalls = 0;
  109. done    = 0;
  110.  
  111. DrawView(xPlayer,yPlayer,PlayerAngle);
  112. SkyNumber = random(1000);
  113.  
  114. txRay  = 0L;
  115. tyRay  = 0L;
  116. tDOW   = 0L;
  117. tFlip  = 0L;
  118. frames = 0L;
  119. tDraw  = 0L;
  120. tStart = CLOCK_PTR;
  121.  
  122. while (!done)
  123.     {
  124.     CheckDoors(xPlayer,yPlayer);
  125.     CheckObjectMovement();
  126.  
  127.     sCode = CheckSpecialCodes((yPlayer & 0xFFC0) + (xPlayer >> 6));
  128.  
  129.     if (sCode == MAP_DOWNCODE)
  130.     {
  131.     CurrentLevel++;
  132.     ReadNewLevel();
  133.     TopColor    = SkyColor;
  134.     BottomColor = FloorColor;
  135.     xPlayer        = StartX;
  136.     yPlayer        = StartY;
  137.     PlayerAngle = StartAngle;
  138.     CosAngle    = CosTable[PlayerAngle];
  139.     SinAngle    = SinTable[PlayerAngle];
  140.     }
  141.  
  142.     if (sCode == MAP_UPCODE)
  143.     {
  144.     if (CurrentLevel > 1)
  145.         {
  146.         CurrentLevel--;
  147.         ReadNewLevel();
  148.         TopColor    = SkyColor;
  149.         BottomColor = FloorColor;
  150.         xPlayer    = StartX;
  151.         yPlayer    = StartY;
  152.         PlayerAngle = StartAngle;
  153.         CosAngle    = CosTable[PlayerAngle];
  154.         SinAngle    = SinTable[PlayerAngle];
  155.         }
  156.     }
  157.  
  158.     if (sCode == MAP_GOALCODE)
  159.     {
  160.     DoGoalScreen();
  161.     done = 1;
  162.     break;
  163.     }
  164.  
  165.     if (Spin)
  166.     {
  167.     Spin >>= 1;
  168.     PlayerAngle += SpinAngle;
  169.     if (PlayerAngle >= INT_ANGLE_360)
  170.         PlayerAngle -= INT_ANGLE_360;
  171.     if (PlayerAngle < 0)
  172.         PlayerAngle += INT_ANGLE_360;
  173.     CosAngle = CosTable[PlayerAngle];
  174.     SinAngle = SinTable[PlayerAngle];
  175.     }
  176.  
  177.     if (SkyCount)
  178.     {
  179.     if (!(SkyCount & 1))
  180.         TopColor = FlashColor;
  181.     else
  182.         TopColor = SkyColor;
  183.  
  184.     SkyCount--;
  185.     }
  186.  
  187.     if (DoFlash)
  188.     {
  189.     if (!SkyCount && random(32768) == SkyNumber)
  190.         {
  191.         SkyCount = 5;
  192.         SkyNumber = random(31000) + 1000;
  193.         }
  194.     }
  195.  
  196.     if(keyBoard.escape)
  197.     break;
  198.  
  199.     CheckMouse(&mouse);
  200.  
  201.     if (mouse.mdx < 0)
  202.     {
  203.     Spin = -mouse.mdx;
  204.     Spin >>= 3;
  205.     SpinAngle = -INT_ANGLE_2 * Spin;
  206.     Spin = 1;
  207.     }
  208.  
  209.     if (mouse.mdx > 0)
  210.     {
  211.     Spin = mouse.mdx;
  212.     Spin >>= 3;
  213.     SpinAngle = INT_ANGLE_2 * Spin;
  214.     Spin = 1;
  215.     }
  216.  
  217.     if (mouse.mdy < 0)
  218.     {
  219.     i = -mouse.mdy;
  220.     i >>= 2;
  221.     i += 16;
  222.     x1 = xPlayer + (int)((CosAngle * i) >> FP_SHIFT);
  223.     y1 = yPlayer + (int)((SinAngle * i) >> FP_SHIFT);
  224.  
  225.     if ((i = CheckHit(xPlayer,yPlayer,PlayerAngle)) == 0)
  226.         {
  227.         xPlayer = x1;
  228.         yPlayer = y1;
  229.         }
  230.     else
  231.         {
  232.         if (i == 3)
  233.         continue;
  234.         if (i == 1)
  235.         {
  236.         x1 = xPlayer;
  237.         if (PlayerAngle < INT_ANGLE_180)
  238.             j = INT_ANGLE_90;
  239.         else
  240.             j = INT_ANGLE_270;
  241.  
  242.         }
  243.         else
  244.         {
  245.         y1 = yPlayer;
  246.         if (PlayerAngle > INT_ANGLE_270 || PlayerAngle < INT_ANGLE_90)
  247.             j = 0;
  248.         else
  249.             j = INT_ANGLE_180;
  250.         }
  251.  
  252.  
  253.         if (!CheckHit(xPlayer,yPlayer,j))
  254.         {
  255.         xPlayer = x1;
  256.         yPlayer = y1;
  257.         }
  258.         }
  259.  
  260.     }
  261.  
  262.     if (mouse.mdy > 0)
  263.     {
  264.     i = mouse.mdy;
  265.     i >>= 2;
  266.     i += 16;
  267.     x1 = xPlayer - (int)((CosAngle * i) >> FP_SHIFT);
  268.     y1 = yPlayer - (int)((SinAngle * i) >> FP_SHIFT);
  269.     j = PlayerAngle + INT_ANGLE_180;
  270.     if (j >= INT_ANGLE_360)
  271.         j -= INT_ANGLE_360;
  272.  
  273.     if ((i = CheckHit(xPlayer,yPlayer,j)) == 0)
  274.         {
  275.         xPlayer = x1;
  276.         yPlayer = y1;
  277.         }
  278.     else
  279.         {
  280.         if (i == 3)
  281.         continue;
  282.  
  283.         if (i == 1)
  284.         {
  285.         x1 = xPlayer;
  286.         if (j < INT_ANGLE_180)
  287.             j = INT_ANGLE_90;
  288.         else
  289.             j = INT_ANGLE_270;
  290.  
  291.         }
  292.         else
  293.         {
  294.         y1 = yPlayer;
  295.         if (j > INT_ANGLE_270 || j < INT_ANGLE_90)
  296.             j = 0;
  297.         else
  298.             j = INT_ANGLE_180;
  299.         }
  300.  
  301.  
  302.         if (!CheckHit(xPlayer,yPlayer,j))
  303.         {
  304.         xPlayer = x1;
  305.         yPlayer = y1;
  306.         }
  307.  
  308.         }
  309.  
  310.  
  311.     }
  312.  
  313.     if (mouse.mButtons & 2)
  314.     {
  315.     i = CheckHit(xPlayer,yPlayer,PlayerAngle);
  316.  
  317.     if (i == 1 && xGrid[xMapPosn] == DOOR_SECRETCODE)
  318.         {
  319.         if (xSecretColumn == 0)
  320.         {
  321.         xSecretmPos = xMapPosn;
  322.         if (iLastX > xPlayer)
  323.             {
  324.             xSecretmPos1 = xMapPosn + 1;
  325.             xSecretColumn = 1;
  326.             yGrid[xMapPosn] = yGrid[xMapPosn - GRID_WIDTH];
  327.             }
  328.         else
  329.             {
  330.             xSecretmPos1 = xMapPosn - 1;
  331.             xSecretColumn = -1;
  332.             yGrid[xSecretmPos1] = yGrid[xSecretmPos1 - GRID_WIDTH];
  333.             }
  334.         }
  335.         }
  336.  
  337.  
  338.     if (i == 2 && yGrid[yMapPosn] == DOOR_SECRETCODE)
  339.         {
  340.         if (ySecretColumn == 0)
  341.         {
  342.         ySecretmPos = yMapPosn;
  343.         if (iLastY > yPlayer)
  344.             {
  345.             ySecretmPos1 = yMapPosn + GRID_WIDTH;
  346.             xGrid[yMapPosn] = xGrid[yMapPosn-1];
  347.             ySecretColumn = 1;
  348.             }
  349.         else
  350.             {
  351.             ySecretmPos1 = yMapPosn - GRID_WIDTH;
  352.             xGrid[ySecretmPos1] = xGrid[ySecretmPos1 - 1];
  353.             ySecretColumn = -1;
  354.             }
  355.         }
  356.         }
  357.  
  358.     if (i == 1 && xGrid[xMapPosn] == DOOR_XCODE)
  359.         {
  360.         j = FindDoorSlot(xMapPosn);
  361.         if (j >= 0)
  362.         {
  363.         Door[j].mPos = xMapPosn;
  364.         if ((int)iLastX > xPlayer)
  365.             i = xMapPosn + 1;
  366.         else
  367.             i = xMapPosn - 1;
  368.  
  369.         Door[j].mCode = xGrid[xMapPosn];
  370.         Door[j].mCode1 = xGrid[i];
  371.         Door[j].mPos1 = i;
  372.         Door[j].ColOffset = 1;
  373.         Door[j].Speed = DoorSpeed;
  374.         Door[j].Type = DOOR_XCODE;
  375.         }
  376.         }
  377.  
  378.     if (i == 2 && yGrid[yMapPosn] == DOOR_YCODE)
  379.         {
  380.         j = FindDoorSlot(yMapPosn);
  381.         if (j >= 0)
  382.         {
  383.         Door[j].mPos = yMapPosn;
  384.         if ((int)iLastY > yPlayer)
  385.             i = yMapPosn + GRID_WIDTH;
  386.         else
  387.             i = yMapPosn - GRID_WIDTH;
  388.  
  389.         Door[j].mCode = yGrid[yMapPosn];
  390.         Door[j].mCode1 = yGrid[i];
  391.         Door[j].mPos1 = i;
  392.         Door[j].ColOffset = 1;
  393.         Door[j].Speed = DoorSpeed;
  394.         Door[j].Type = DOOR_YCODE;
  395.         }
  396.  
  397.         }
  398.  
  399.     }
  400.  
  401.  
  402.     if(keyBoard.rightArrow)
  403.     {
  404.     if (keyBoard.control)
  405.         PlayerAngle += INT_ANGLE_45;
  406.     else
  407.         PlayerAngle += INT_ANGLE_6;
  408.  
  409.     if (PlayerAngle >= INT_ANGLE_360)
  410.         PlayerAngle -= INT_ANGLE_360;
  411.  
  412.     CosAngle = CosTable[PlayerAngle];
  413.     SinAngle = SinTable[PlayerAngle];
  414.     }
  415.  
  416.     if(keyBoard.leftArrow)
  417.     {
  418.     if (keyBoard.control)
  419.         PlayerAngle -= INT_ANGLE_45;
  420.     else
  421.         PlayerAngle -= INT_ANGLE_6;
  422.  
  423.     if (PlayerAngle < 0)
  424.         PlayerAngle += INT_ANGLE_360;
  425.  
  426.  
  427.     CosAngle = CosTable[PlayerAngle];
  428.     SinAngle = SinTable[PlayerAngle];
  429.     }
  430.  
  431.     if(keyBoard.upArrow)
  432.     {
  433.     x1 = xPlayer + (int)(CosAngle >> (FP_SHIFT - 4));
  434.     y1 = yPlayer + (int)(SinAngle >> (FP_SHIFT - 4));
  435.     if ((i = CheckHit(xPlayer,yPlayer,PlayerAngle)) == 0)
  436.         {
  437.         xPlayer = x1;
  438.         yPlayer = y1;
  439.         }
  440.     else
  441.         {
  442.         if (i == 3)
  443.         continue;
  444.  
  445.         if (i == 1)
  446.         {
  447.         x1 = xPlayer;
  448.         if (PlayerAngle < INT_ANGLE_180)
  449.             j = INT_ANGLE_90;
  450.         else
  451.             j = INT_ANGLE_270;
  452.  
  453.         }
  454.         else
  455.         {
  456.         y1 = yPlayer;
  457.         if (PlayerAngle > INT_ANGLE_270 || PlayerAngle < INT_ANGLE_90)
  458.             j = 0;
  459.         else
  460.             j = INT_ANGLE_180;
  461.         }
  462.  
  463.  
  464.         if (!CheckHit(xPlayer,yPlayer,j))
  465.         {
  466.         xPlayer = x1;
  467.         yPlayer = y1;
  468.         }
  469.         }
  470.  
  471.  
  472.     }
  473.  
  474.     if(keyBoard.downArrow)
  475.     {
  476.     x1 = xPlayer - (int)(CosAngle >> (FP_SHIFT - 4));
  477.     y1 = yPlayer - (int)(SinAngle >> (FP_SHIFT - 4));
  478.  
  479.     j = PlayerAngle + INT_ANGLE_180;
  480.     if (j >= INT_ANGLE_360)
  481.         j -= INT_ANGLE_360;
  482.  
  483.     if ((i = CheckHit(xPlayer,yPlayer,j)) == 0)
  484.         {
  485.         xPlayer = x1;
  486.         yPlayer = y1;
  487.         }
  488.     else
  489.         {
  490.         if (i == 3)
  491.         continue;
  492.  
  493.         if (i == 1)
  494.         {
  495.         x1 = xPlayer;
  496.         if (j < INT_ANGLE_180)
  497.             j = INT_ANGLE_90;
  498.         else
  499.             j = INT_ANGLE_270;
  500.  
  501.         }
  502.         else
  503.         {
  504.         y1 = yPlayer;
  505.         if (j > INT_ANGLE_270 || j < INT_ANGLE_90)
  506.             j = 0;
  507.         else
  508.             j = INT_ANGLE_180;
  509.         }
  510.  
  511.  
  512.         if (!CheckHit(xPlayer,yPlayer,j))
  513.         {
  514.         xPlayer = x1;
  515.         yPlayer = y1;
  516.         }
  517.         }
  518.  
  519.     }
  520.  
  521.     if (keyBoard.letA)
  522.     {
  523.     if (CenterRow > 90)
  524.         {
  525.         CenterRow--;
  526.         }
  527.     }
  528.  
  529.     if (keyBoard.letS)
  530.     {
  531.     if (CenterRow < 150)
  532.         {
  533.         CenterRow++;
  534.         }
  535.     }
  536.  
  537.     t1 = CLOCK_PTR;
  538.     DrawView(xPlayer,yPlayer,PlayerAngle);
  539.     tDraw += CLOCK_PTR - t1;
  540.     frames++;
  541.     }
  542.  
  543. tStart = CLOCK_PTR - tStart;
  544.  
  545. WrapUp();
  546.  
  547.  
  548. printf("\nFrames  : %ld\n",frames);
  549. printf("tDrawRtn  : %ld\n",tDraw);
  550. printf("tTotal    : %ld\n",tStart);
  551. printf("txRay     : %ld\n",txRay);
  552. printf("tyRay     : %ld\n",tyRay);
  553. printf("tDrawWalls: %ld\n",tDOW);
  554. printf("tFlipPage : %ld\n",tFlip);
  555. }
  556.