src/supertux/tile.hpp

Go to the documentation of this file.
00001 //  SuperTux
00002 //  Copyright (C) 2004 Tobias Glaesser <tobi.web@gmx.de>
00003 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
00004 //  Copyright (C) 2010 Florian Forster <supertux at octo.it>
00005 //
00006 //  This program is free software: you can redistribute it and/or modify
00007 //  it under the terms of the GNU General Public License as published by
00008 //  the Free Software Foundation, either version 3 of the License, or
00009 //  (at your option) any later version.
00010 //
00011 //  This program is distributed in the hope that it will be useful,
00012 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //  GNU General Public License for more details.
00015 //
00016 //  You should have received a copy of the GNU General Public License
00017 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00018 
00019 #ifndef HEADER_SUPERTUX_SUPERTUX_TILE_HPP
00020 #define HEADER_SUPERTUX_SUPERTUX_TILE_HPP
00021 
00022 #include <vector>
00023 #include <stdint.h>
00024 
00025 #include "math/rectf.hpp"
00026 #include "video/surface.hpp"
00027 #include "util/reader_fwd.hpp"
00028 
00029 class DrawingContext;
00030 
00031 class Tile
00032 {
00033 public:
00034   static bool draw_editor_images;
00036   enum {
00038     SOLID     = 0x0001,
00040     UNISOLID  = 0x0002,
00042     BRICK     = 0x0004,
00047     GOAL      = 0x0008,
00049     SLOPE     = 0x0010,
00051     FULLBOX   = 0x0020,
00053     COIN      = 0x0040,
00054 
00055     /* interesting flags (the following are passed to gameobjects) */
00056     FIRST_INTERESTING_FLAG = 0x0100,
00057 
00059     ICE       = 0x0100,
00061     WATER     = 0x0200,
00063     HURTS     = 0x0400,
00065     FIRE      = 0x0800
00066   };
00067 
00069   enum {
00070     WORLDMAP_NORTH = 0x0001,
00071     WORLDMAP_SOUTH = 0x0002,
00072     WORLDMAP_EAST  = 0x0004,
00073     WORLDMAP_WEST  = 0x0008,
00074     WORLDMAP_DIR_MASK = 0x000f,
00075 
00076     WORLDMAP_STOP  = 0x0010,
00077 
00078     // convenience values ("C" stands for crossroads)
00079     WORLDMAP_CNSE  = WORLDMAP_NORTH | WORLDMAP_SOUTH | WORLDMAP_EAST,
00080     WORLDMAP_CNSW  = WORLDMAP_NORTH | WORLDMAP_SOUTH | WORLDMAP_WEST,
00081     WORLDMAP_CNEW  = WORLDMAP_NORTH | WORLDMAP_EAST  | WORLDMAP_WEST,
00082     WORLDMAP_CSEW  = WORLDMAP_SOUTH | WORLDMAP_EAST  | WORLDMAP_WEST,
00083     WORLDMAP_CNSEW = WORLDMAP_NORTH | WORLDMAP_SOUTH | WORLDMAP_EAST | WORLDMAP_WEST
00084   };
00085 
00086   struct ImageSpec {
00087     ImageSpec(const std::string& newfile, const Rectf& newrect)
00088       : file(newfile), rect(newrect)
00089     { }
00090 
00091     std::string file;
00092     Rectf rect;
00093   };
00094 
00095   enum
00096   {
00097     UNI_DIR_NORTH = 0,
00098     UNI_DIR_SOUTH = 1,
00099     UNI_DIR_WEST  = 2,
00100     UNI_DIR_EAST  = 3,
00101     UNI_DIR_MASK  = 3
00102   };
00103 
00104 private:
00105   std::vector<ImageSpec> imagespecs;
00106   std::vector<SurfacePtr>  images;
00107   std::vector<ImageSpec> editor_imagespecs;
00108   std::vector<SurfacePtr>  editor_images;
00109 
00111   uint32_t attributes;
00112 
00114   int data;
00115 
00116   float fps;
00117 
00118 public:
00119   Tile();
00120   Tile(const std::vector<ImageSpec>& images, const std::vector<ImageSpec>& editor_images,
00121        uint32_t attributes, uint32_t data, float fps);
00122   ~Tile();
00123 
00125   void load_images();
00126 
00128   void draw(DrawingContext& context, const Vector& pos, int z_pos) const;
00129 
00130   uint32_t getAttributes() const
00131   { return attributes; }
00132 
00133   int getData() const
00134   { return data; }
00135 
00137   bool is_slope() const
00138   {
00139     return attributes & SLOPE;
00140   }
00141 
00147   bool is_solid (const Rectf& tile_bbox, const Rectf& position, const Vector& movement) const;
00148 
00153   bool is_solid() const
00154   {
00155     return attributes & SOLID;
00156   }
00157 
00159   bool is_unisolid() const
00160   {
00161     return attributes & UNISOLID;
00162   }
00163 
00164   void print_debug(int id) const;
00165 
00166 private:
00167   //Correct small oddities in attributes that naive people
00168   //might miss (and rebuke them for it)
00169   void correct_attributes();
00170 
00173   bool check_movement_unisolid (const Vector movement) const;
00174 
00177   bool check_position_unisolid (const Rectf& obj_bbox,
00178                                 const Rectf& tile_bbox) const;
00179 
00180 private:
00181   Tile(const Tile&);
00182   Tile& operator=(const Tile&);
00183 };
00184 
00185 #endif
00186 
00187 /* EOF */

Generated on Mon Jun 9 03:38:23 2014 for SuperTux by  doxygen 1.5.1