home *** CD-ROM | disk | FTP | other *** search
/ Game.EXE 2002 May / Game.EXE_05_2002.iso / Alawar / src / Position.h < prev    next >
Encoding:
C/C++ Source or Header  |  2002-04-02  |  1.3 KB  |  79 lines

  1. #ifndef POSITION_H
  2. #define POSITION_H
  3.  
  4. #include "Coord.h"
  5.  
  6. class Direction
  7. {
  8. public:
  9.     enum Dir { STAND, LEFT=1, UP=2, RIGHT=4, DOWN=8 };
  10.  
  11.     Direction()
  12.     : dir( STAND )
  13.     {}
  14.  
  15.     Direction( Dir dir )
  16.     : dir( dir )
  17.     {}
  18.  
  19.     bool operator== ( const Direction & d )const
  20.     {
  21.         return dir == d.dir;
  22.     }
  23.     bool operator!= ( const Direction & d )const
  24.     {
  25.         return !operator==( d );
  26.     }
  27.     bool is_opposed( const Direction & d )const
  28.     {
  29.         if( dir == LEFT && d.dir == RIGHT )
  30.             return true;
  31.         if( dir == RIGHT && d.dir == LEFT )
  32.             return true;
  33.         if( dir == UP && d.dir == DOWN )
  34.             return true;
  35.         if( dir == DOWN && d.dir == UP )
  36.             return true;
  37.         return false;
  38.     }
  39.     Dir get_dir()const
  40.     {
  41.         return dir;
  42.     }
  43. private:
  44.     Dir dir;
  45. };
  46.  
  47. class Position
  48. {
  49.     Coord src;
  50.     Coord dst;
  51.     float koef;
  52.     int cell_size;
  53. public:
  54.     friend class Level;
  55.     Position()
  56.     :    src( 0, 0 ),
  57.         dst( 0, 0 ),
  58.         koef( 0 ),
  59.         cell_size( 0 )
  60.     {}
  61.     Position( Coord src, Coord dst, int cell_size )
  62.     :    src( src ),
  63.         dst( dst ),
  64.         koef( 0 ),
  65.         cell_size ( cell_size )
  66.     {}
  67.     bool go_to(float length);
  68.     void swap_dst();
  69.     int get_x()const
  70.     {
  71.         return int( src.x * (1-koef) + dst.x * koef + cell_size/2);
  72.     }
  73.     int get_y()const
  74.     {
  75.         return int( src.y * (1-koef) + dst.y * koef  + cell_size/2);
  76.     }
  77. };
  78.  
  79. #endif //POSITION_H