game.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. #include "game.h"
  2. #include "JoyStick.h"
  3. #include "sort.h"
  4. #include "sine.h"
  5. /* -------------------------------------------------------------------- */
  6. extern byte walls[8][65][2];
  7. word INPUTMETHOD, FIN;
  8. struct BLOCKTYPE Level_One[ NbrBlocks+1 ] =
  9. {
  10. { 1,1,2,1, NORTH,NULL},
  11. { 0,0,3,1, NORTH,NULL},
  12. { 0,0,4,1, NORTH,NULL},
  13. { 1,1,5,2, WEST,NULL},
  14. { 0,0,5,3, WEST,NULL},
  15. { 0,0,4,4, WEST|SOUTH|NORTH,NULL},
  16. { 1,1,5,5, WEST,NULL},
  17. { 0,0,5,6, WEST,NULL},
  18. { 0,0,5,7, WEST,NULL},
  19. { 1,1,4,8, SOUTH,NULL},
  20. { 0,0,3,7, WEST|EAST|SOUTH,NULL},
  21. { 0,0,2,8, SOUTH,NULL},
  22. { 1,1,1,7, EAST,NULL},
  23. { 0,0,1,6, EAST,NULL},
  24. { 0,0,1,5, EAST,NULL},
  25. { 0,1,2,4, EAST|SOUTH|NORTH,NULL},
  26. { 0,0,1,3, EAST,NULL},
  27. { 0,0,1,2, EAST,NULL},
  28. { 1,1,3,4, DOOR|NORTH|SOUTH,NULL},
  29. };
  30. struct DOORTYPE myDoor;
  31. struct PLAYER player1 = { 0,0,0,0,0,0 };
  32. struct xBUFFTYPE xBUFFER[DISPLAY_WIDTH];
  33. word zBUFFER[NbrBlocks + NbrObjects][2];
  34. /* ------------------ I N T E R N A L R O U T I N E S ----------------- */
  35. void WOLF3D( void );
  36. /* ------------------------------------------------------------------------ */
  37. void WOLF3D(void)
  38. {
  39. register word index;
  40. word count;
  41. unsigned long frame = 0,start,seconds;
  42. unsigned int clock[2];
  43. /* ------------------------------------------------------------------ */
  44. /* PRE-GAME INITIALIZATION */
  45. /* ------------------------------------------------------------------ */
  46. COSINE = &SINE[90*2];
  47. INPUTMETHOD = JOYSTICK;
  48. FIN = 0;
  49. timer(clock);
  50. start = clock[0];
  51. /* Initialize level one's blocks to the proper coordinates (i*64) */
  52. for(index = 0; index < NbrBlocks; index++)
  53. {
  54. Level_One[index].x *= 64;
  55. Level_One[index].z *= 64;
  56. };
  57. /* ---------------------------------------- */
  58. /* Setup the playing display. Ie: its initial graphics */
  59. SetAPen(RASTPORT,13);
  60. RectFill(RASTPORT,0,0,DISPLAY_WIDTH-1,DISPLAY_HEIGHT-1);
  61. player1.X = (long)(128) << FFPBitSize; /* Set the player start coords at 2,2 */
  62. player1.Z = (long)(128) << FFPBitSize;
  63. player1.Xcopy = (word)(player1.X >> FFPBitSize);
  64. player1.Zcopy = (word)(player1.Z >> FFPBitSize);
  65. // CreateDoorList();
  66. // CreateNpcList();
  67. /*-------------------------
  68. Object[0].ShipDefn = &Cube;
  69. Object[0].center[0] = 192;
  70. Object[0].center[1] = 0;
  71. Object[0].center[2] = 64;
  72. Object[0].attitude = 0;
  73. -------------------------*/
  74. /* ---------------------------------------------------------------- */
  75. /* MAIN GAME LOOP */
  76. /* ---------------------------------------------------------------- */
  77. while(! FIN )
  78. {
  79. /* ------------------------------------------------------------ */
  80. /* TRANSFORM WORLD BLOCKS AND OBJECTS */
  81. /* ------------------------------------------------------------ */
  82. TransformBlocks( &player1 );
  83. // TransformObjects( &player1 );
  84. /* ------------------------------------------------------------ */
  85. /* CREATE AND SORT THE ZDEPTHBUFFER */
  86. /* ------------------------------------------------------------ */
  87. count = CreateZbuffer();
  88. SORTWORLD(zBUFFER, count);
  89. /* ------------------------------------------------------------ */
  90. /* CREATE THE XIMAGEBUFFER */
  91. /* ------------------------------------------------------------ */
  92. CreateXbuffer(count);
  93. /* ------------------------------------------------------------ */
  94. /* RENDER THE WORLD AND OBJECTS INTO THE FRAMEBUFFER */
  95. /* ------------------------------------------------------------ */
  96. AsmClearBackground((long *)fBUFFER,151587081L,134744072L);
  97. AsmRenderMaze((long *)&xBUFFER[VIEW_LEFT],(long *)fBUFFER);
  98. // AsmRenderObjects();
  99. /* ------------------------------------------------------------ */
  100. /* COPY THE FRAMEBUFFER TO VIDEO MEMORY */
  101. /* ------------------------------------------------------------ */
  102. if(DISPLAY_DEPTH == 4)
  103. {
  104. AsmChunky2Planar((long *)fBUFFER,(long *)RASTPORT->BitMap->Planes[0]);
  105. }
  106. else if(DISPLAY_DEPTH != 4)
  107. {
  108. chunky2planar((long *)fBUFFER,(long *)RASTPORT->BitMap->Planes[0]);
  109. };
  110. /* ------------------------------------------------------------ */
  111. /* FETCH AND EVALUATE PLAYER INPUT */
  112. /* ------------------------------------------------------------ */
  113. FetchEvaluateInput( &player1 );
  114. UpdatePlayerPosition( &player1 );
  115. // in updateposition also handle collision events
  116. // collision with: blocks & objects
  117. // UpdateDoorList();
  118. // UpdateNpcList(); /* NonPlayerCharacters - bad guys */
  119. frame++;
  120. // if(frame == 1000) FIN = 27;
  121. };
  122. timer(clock);
  123. seconds = clock[0] - start;
  124. if(! seconds) seconds = 1;
  125. // DestroyDoorList();
  126. // DestroyNpcList();
  127. printf("Frames: %d & Seconds: %d\n",frame,seconds);
  128. printf("Est Frames per second: %d\n",frame/seconds);
  129. }
  130. /* --------------------------------------------------------------------------
  131. if(code == ' ')
  132. {
  133. myDoor.status = 1;
  134. };
  135. myDoor.length = myDoor.length + myDoor.XDIR * myDoor.status;
  136. if( (myDoor.length == 64) && (myDoor.status != 0))
  137. {
  138. myDoor.status = 0;
  139. myDoor.XDIR *= -1;
  140. }
  141. else
  142. if( (myDoor.length == 0) && (myDoor.status != 0))
  143. {
  144. myDoor.status = 0;
  145. myDoor.XDIR *= -1;
  146. };
  147. Level_One[18].x = myDoor.oldX + myDoor.length;
  148. */
  149. /* HERE's the ORIGINAL RenderWorld routine I used - note this does not
  150. need a chunky to planar conversion routine
  151. */
  152. /* To get this work with wolf3d, insert this into functions.c and add:
  153. void RenderWorld( void );
  154. to the top of the file. Also add:
  155. extern void RenderWorld( void );
  156. to maze.h
  157. Place the call to this routine into game.c, in place of AsmRenderWorld()
  158. */
  159. /* notice that xBUFFER[x].column * BYTESPERROW implies that the images are stored
  160. sideways. This is for assembly since it is faster to traverse a single column
  161. if the bytes of that column are stored consecutively in memory */
  162. /* RenderWorld() - handles the task of drawing the visible wall columns as determined
  163. by the xBUFFER[];
  164. Each xBUFFER element represents a single column of the display.
  165. It contains information on the bitmap image we are fetching graphic data from,
  166. the height (in pixels) that this column will cover on the screen,
  167. and a column value, which is an offset into the bitmap image where
  168. this column's graphic data begins.
  169. Each wall column starts off as 64 pixels high. This is scaled
  170. up or down depending on the already calculated xBUFFER[x].height
  171. value. Since the wall is centered on the middle row of the
  172. display area, the xBUFFER[].height value is actually the height
  173. of the top of the wall as measured from the middle row.
  174. */
  175. /* Thanks to Simon Watfa for his two-dimensional scaling code */
  176. /*
  177. #define BYTESPERROW 64
  178. void RenderWorld( void )
  179. {
  180. register word x, height, destY, srcY, yinc, yrinc, errY;
  181. byte *bitmapPtr;
  182. for(x = ViewLeft; x <= ViewRight; x++) /* Draw each column of the screen */
  183. {
  184. height = xBUFFER[x].height; /* The height/2 of this wall column */
  185. if(height)
  186. {
  187. yinc = 32 / height; /* Calculate scaling factors for this column */
  188. yrinc = 32 % height;
  189. errY = srcY = 0;
  190. for(destY = (ViewCenterY-height+1); destY <=(height+ViewCenterY); destY++, srcY += yinc)
  191. {
  192. if( (destY >= ViewTop) && (destY <= ViewBottom) )
  193. {
  194. /* This pixel is within the drawing area so render it */
  195. bitmapPtr = (byte *)xBUFFER[x].bitmap;
  196. SetAPen(RASTPORT, *(bitmapPtr + (xBUFFER[x].column * BYTESPERROW) + srcY));
  197. WritePixel(RASTPORT,(word)x,(word)destY);
  198. };
  199. errY += yrinc;
  200. if(errY >= height)
  201. {
  202. srcY++;
  203. errY -= height;
  204. };
  205. };
  206. };
  207. };
  208. }
  209. */