home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / mnth0108.zip / Timur / mech.c < prev    next >
Text File  |  1993-03-14  |  2KB  |  82 lines

  1. /* MECH.C - routines to control all the BattleMechs
  2.  
  3. Copyright (c) 1993 Timur Tabi
  4. Copyright (c) 1993 Fasa Corporation
  5.  
  6. The following trademarks are the property of Fasa Corporation:
  7. BattleTech, CityTech, AeroTech, MechWarrior, BattleMech, and 'Mech.
  8. The use of these trademarks should not be construed as a challenge to these marks.
  9.  
  10. */
  11.  
  12. #define INCL_WINWINDOWMGR
  13. #define INCL_GPIBITMAPS
  14. #include <os2.h>
  15. #include <stdlib.h>
  16.  
  17. #define MECH_C
  18. #include "header.h"
  19. #include "resource.h"
  20. #include "hexes.h"
  21. #include "mech.h"
  22. #include "bitmap.h"
  23.  
  24. void MechInit(void) {
  25.   mech.hi.c=0;
  26.   mech.hi.r=0;
  27.   mech.iDirection=2;                         // Default is facing North
  28.   mech.hbm[0]=BitmapLoad(IDB_MECH_SE);
  29.   mech.hbm[1]=BitmapLoad(IDB_MECH_NE);
  30.   mech.hbm[2]=BitmapLoad(IDB_MECH_N);
  31.   mech.hbm[3]=BitmapLoad(IDB_MECH_NW);
  32.   mech.hbm[4]=BitmapLoad(IDB_MECH_SW);
  33.   mech.hbm[5]=BitmapLoad(IDB_MECH_S);
  34. }
  35.  
  36. void MechErase(void) {
  37. /* Erases the current 'Mech from the screen.
  38. */
  39.   HexFillDraw(mech.hi);
  40. }
  41.  
  42. void MechDraw(void) {
  43. /* Draws the current 'Mech.
  44. */
  45.   POINTL ptl;
  46.  
  47.   ptl=HexCoord(mech.hi);
  48.   ptl.x-=HEX_EXT;
  49.  
  50.   BitmapDraw(mech.hbm[mech.iDirection],hbmHexMask,ptl);
  51. }
  52.  
  53.  
  54. void MechMove(HEXINDEX hi) {
  55. /* This routine moves the 'Mech to position 'hi', if that position is adjacent
  56.    to the 'Mech's current position.
  57.    Future enhancement: allow the mech to change direction only by 60 degrees each turn.
  58. */
  59.   int dx=hi.c-mech.hi.c;
  60.   int dy=hi.r-mech.hi.r;
  61.   int iDir;                            // Direction from mech.hi to hi
  62.  
  63.   if (abs(dx) > 1) return;             // +/- one column?
  64.   if (abs(dy) > 2) return;             // +/- two rows?
  65.   if HI_EQUAL(hi,mech.hi) return;      // same row/column?
  66.  
  67. // Calculate direction based on dx and dy
  68.   switch (dy) {
  69.     case -2: iDir=5; break;
  70.     case -1: iDir= dx>0 ? 0 : 4; break;
  71.     case 1:  iDir= dx>0 ? 1 : 3; break;
  72.     case 2:  iDir=2; break;
  73.   }
  74.  
  75.   if (iDir==mech.iDirection) {         // Are we already facing the way we want to go?
  76.     MechErase();
  77.     mech.hi=hi;                        // Yes, we can move that way
  78.   } else
  79.     mech.iDirection=iDir;              // No, let's turn to that direction;
  80.   MechDraw();
  81. }
  82.