home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 February / maximum-cd-2009-02.iso / DiscContents / SMC_1.6_win32.exe / src / overworld / world_layer.h < prev    next >
Encoding:
C/C++ Source or Header  |  2008-07-01  |  4.9 KB  |  184 lines

  1. /***************************************************************************
  2.  * layer.h  -  header for the corresponding cpp file
  3.  *
  4.  * Copyright (C) 2003 - 2008 Florian Richter
  5.  ***************************************************************************/
  6. /*
  7.    This program is free software; you can redistribute it and/or modify
  8.    it under the terms of the GNU General Public License as published by
  9.    the Free Software Foundation; either version 3 of the License, or
  10.    (at your option) any later version.
  11.    
  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  14. */
  15.  
  16. #ifndef SMC_WORLD_LAYER_H
  17. #define SMC_WORLD_LAYER_H
  18.  
  19. #include "../core/globals.h"
  20. #include "../objects/movingsprite.h"
  21. #include "../core/obj_manager.h"
  22. #include "../overworld/world_waypoint.h"
  23.  
  24.  
  25. /* *** *** *** *** *** *** Layer_Line *** *** *** *** *** *** *** *** *** *** *** */
  26.  
  27. // Layer Line Point class
  28. // TODO : create a real basic/virtual sprite ?
  29. class cLayer_Line_Point : public cSprite
  30. {
  31. public:
  32.     cLayer_Line_Point( SpriteType ntype );
  33.     virtual ~cLayer_Line_Point( void );
  34.  
  35.     // copy this sprite
  36.     virtual cLayer_Line_Point *Copy( void ) { return NULL; };
  37.  
  38.     // save to stream
  39.     virtual void Save_to_Stream( ofstream &file ) {};
  40.  
  41.     // draw
  42.     virtual void Draw( cSurfaceRequest *request = NULL );
  43.  
  44.     // editor activation
  45.     virtual void Editor_Activate( void );
  46.     // editor events
  47.     bool Editor_Origin_Key( const CEGUI::EventArgs &event ); // editor origin key up
  48.  
  49.     float Get_Line_Pos_X( void );
  50.     float Get_Line_Pos_Y( void );
  51.  
  52.     // line
  53.     void *line;
  54. };
  55.  
  56. // Overworld Layer Line class
  57. class cLayer_Line
  58. {
  59. public:
  60.     cLayer_Line( void );
  61.     virtual ~cLayer_Line( void );
  62.  
  63.     // Draw
  64.     void Draw( void );
  65.  
  66.     // return a normal line
  67.     GL_line Get_Line( void );
  68.  
  69.     /* Returns the Waypoint on the end of the line(s)
  70.      * if the line continues on another line it is followed to the end
  71.     */
  72.     cWaypoint *Get_End_Waypoint( void );
  73.     
  74.     // start point
  75.     cLayer_Line_Point *start;
  76.     // end point
  77.     cLayer_Line_Point *end;
  78.  
  79.     /* animation type 
  80.      * 0 = normal walking, 1 = swimming
  81.      */
  82.     unsigned int anim_type;
  83.     // waypoint origin identifier
  84.     unsigned int origin;
  85. };
  86.  
  87. /* *** *** *** *** *** *** *** Layer *** *** *** *** *** *** *** *** *** *** */
  88.  
  89. // Layer Line Collision data
  90. class cLine_collision
  91. {
  92. public:
  93.     cLine_collision( void );
  94.  
  95.     // nearest line pointer
  96.     cLayer_Line *line;
  97.     // nearest line number
  98.     int line_number;
  99.     // position difference
  100.     float difference;
  101. };
  102.  
  103. // Layer Nearest Line Collision data
  104. class cNearLine_collision
  105. {
  106. public:
  107.     cNearLine_collision( void );
  108.  
  109.     // nearest line number
  110.     int line_number;
  111.     // line start collision else end collision
  112.     bool start;
  113. };
  114.  
  115. // Layer Contact Collision data
  116. class cContact_collision
  117. {
  118. public:
  119.     // clear data
  120.     void clear( void );
  121.     // return the best fitting line for the given direction
  122.     int Get_Best_Line( ObjectDirection dir );
  123.  
  124.     // is there a contact
  125.     bool contact;
  126.     // horizontal line contact
  127.     cLine_collision line_hor;
  128.     // vertical line contact
  129.     cLine_collision line_ver;
  130. };
  131.  
  132. typedef vector<cLayer_Line *> LayerLineList;
  133.  
  134. // Layer class
  135. // handles the line collision detection
  136. class cLayer : public CEGUI::XMLHandler, public cObject_Manager<cLayer_Line>
  137. {
  138. public:
  139.     cLayer( void );
  140.     virtual ~cLayer( void );
  141.  
  142.     // Load from file
  143.     void Load( string filename );
  144.  
  145.     // Save
  146.     bool Save( string filename );
  147.  
  148.     // Draw the lines and waypoints
  149.     void Draw( void );
  150.  
  151.     /* Returns the colliding Line start point
  152.      * if not found returns NULL
  153.     */
  154.     cLayer_Line *Get_Line_Collision_Start( GL_rect *line_rect );
  155.     /* Returns the colliding Line from the given position and the added direction size
  156.      * if not found returns a NULL line in the class
  157.     */
  158.     cLine_collision Get_Line_Collision_Direction( float x, float y, ObjectDirection dir, float dir_size = 15, unsigned int check_size = 10 );
  159.  
  160.     /* Return the collision data between the nearest line and the given position
  161.      * check_size is maximum size for both direction checking lines
  162.      * if only_origin_id is set only checks lines with the given id
  163.     */
  164.     cLine_collision Get_Nearest( float x, float y, ObjectDirection dir = DIR_HORIZONTAL, unsigned int check_size = 15, int only_origin_id = -1 );
  165.     // Return the collision data between the given line and position
  166.     cLine_collision Get_Nearest_Line( cLayer_Line *map_layer_line, float x, float y, ObjectDirection dir = DIR_HORIZONTAL, unsigned int check_size = 15 );
  167.  
  168. private:
  169.     // XML element start
  170.     virtual void elementStart( const CEGUI::String &element, const CEGUI::XMLAttributes &attributes );
  171.     // XML element end
  172.     virtual void elementEnd( const CEGUI::String &element );
  173.  
  174.     // handles a line
  175.     void handle_line( const CEGUI::XMLAttributes &attributes );
  176.  
  177.     // XML element Property list
  178.     CEGUI::XMLAttributes xml_attributes;
  179. };
  180.  
  181. /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
  182.  
  183. #endif
  184.