- Reworked Surface class and drawing stuff:
[supertux.git] / src / object / tilemap.hpp
1 //  $Id$
2 //
3 //  SuperTux -  A Jump'n Run
4 //  Copyright (C) 2004 Matthias Braun <matze@braunis.de
5 //
6 //  This program is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU General Public License
8 //  as published by the Free Software Foundation; either version 2
9 //  of the License, or (at your option) any later version.
10 //
11 //  This program is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //  GNU General Public License for more details.
15 //
16 //  You should have received a copy of the GNU General Public License
17 //  along with this program; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19 #ifndef SUPERTUX_TILEMAP_H
20 #define SUPERTUX_TILEMAP_H
21
22 #include <vector>
23 #include <stdint.h>
24
25 #include "game_object.hpp"
26 #include "serializable.hpp"
27 #include "math/vector.hpp"
28 #include "video/drawing_context.hpp"
29
30 namespace lisp {
31 class Lisp;
32 }
33
34 class Level;
35 class TileManager;
36 class Tile;
37
38 /**
39  * This class is reponsible for drawing the level tiles
40  */
41 class TileMap : public GameObject, public Serializable
42 {
43 public:
44   TileMap();
45   TileMap(const lisp::Lisp& reader, TileManager* tile_manager = 0);
46   TileMap(int layer_, bool solid_, size_t width_, size_t height_);
47   virtual ~TileMap();
48
49   virtual void write(lisp::Writer& writer);
50
51   virtual void update(float elapsed_time);
52   virtual void draw(DrawingContext& context);
53
54   void set(int width, int height, const std::vector<unsigned int>& vec,
55       int layer, bool solid);
56
57   /** resizes the tilemap to a new width and height (tries to not destroy the
58    * existing map)
59    */
60   void resize(int newwidth, int newheight);
61
62   size_t get_width() const
63   { return width; }
64
65   size_t get_height() const
66   { return height; }
67
68   int get_layer() const
69   { return layer; }
70   
71   bool is_solid() const
72   { return solid; }
73
74   /// returns tile in row y and column y (of the tilemap)
75   const Tile* get_tile(int x, int y) const;
76   /// returns tile at position pos (in world coordinates)
77   const Tile* get_tile_at(const Vector& pos) const;
78
79   void change(int x, int y, uint32_t newtile);
80
81   void change_at(const Vector& pos, uint32_t newtile);
82
83   /// changes all tiles with the given ID
84   void change_all(uint32_t oldtile, uint32_t newtile);
85
86   TileManager* get_tilemanager() const
87   {
88     return tilemanager;
89   }
90
91   void set_drawing_effect(DrawingEffect effect)
92   {
93     drawing_effect = effect;
94   }
95
96   DrawingEffect get_drawing_effect()
97   {
98     return drawing_effect;
99   }
100
101 private:
102   typedef std::vector<uint32_t> Tiles;
103   Tiles tiles;
104   
105 private:
106   TileManager* tilemanager;
107   bool solid;
108   float speed;
109   int width, height;
110   int layer;
111
112   DrawingEffect drawing_effect;
113 };
114
115 #endif /*SUPERTUX_TILEMAP_H*/
116