Massive copyright update. I'm sorry if I'm crediting Matze for something he didn...
[supertux.git] / src / object / tilemap.hpp
1 //  $Id$
2 //
3 //  SuperTux
4 //  Copyright (C) 2006 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
20 #ifndef SUPERTUX_TILEMAP_H
21 #define SUPERTUX_TILEMAP_H
22
23 #include <vector>
24 #include <stdint.h>
25
26 #include "game_object.hpp"
27 #include "serializable.hpp"
28 #include "math/vector.hpp"
29 #include "video/drawing_context.hpp"
30
31 namespace lisp {
32 class Lisp;
33 }
34
35 class Level;
36 class TileManager;
37 class Tile;
38
39 /**
40  * This class is reponsible for drawing the level tiles
41  */
42 class TileMap : public GameObject, public Serializable
43 {
44 public:
45   TileMap();
46   TileMap(const lisp::Lisp& reader, TileManager* tile_manager = 0);
47   TileMap(int layer_, bool solid_, size_t width_, size_t height_);
48   virtual ~TileMap();
49
50   virtual void write(lisp::Writer& writer);
51
52   virtual void update(float elapsed_time);
53   virtual void draw(DrawingContext& context);
54
55   void set(int width, int height, const std::vector<unsigned int>& vec,
56       int layer, bool solid);
57
58   /** resizes the tilemap to a new width and height (tries to not destroy the
59    * existing map)
60    */
61   void resize(int newwidth, int newheight);
62
63   size_t get_width() const
64   { return width; }
65
66   size_t get_height() const
67   { return height; }
68
69   int get_layer() const
70   { return layer; }
71   
72   bool is_solid() const
73   { return solid; }
74
75   /// returns tile in row y and column y (of the tilemap)
76   const Tile* get_tile(int x, int y) const;
77   /// returns tile at position pos (in world coordinates)
78   const Tile* get_tile_at(const Vector& pos) const;
79
80   void change(int x, int y, uint32_t newtile);
81
82   void change_at(const Vector& pos, uint32_t newtile);
83
84   /// changes all tiles with the given ID
85   void change_all(uint32_t oldtile, uint32_t newtile);
86
87   TileManager* get_tilemanager() const
88   {
89     return tilemanager;
90   }
91
92   void set_drawing_effect(DrawingEffect effect)
93   {
94     drawing_effect = effect;
95   }
96
97   DrawingEffect get_drawing_effect()
98   {
99     return drawing_effect;
100   }
101
102 private:
103   typedef std::vector<uint32_t> Tiles;
104   Tiles tiles;
105   
106 private:
107   TileManager* tilemanager;
108   bool solid;
109   float speed;
110   int width, height;
111   int layer;
112
113   DrawingEffect drawing_effect;
114 };
115
116 #endif /*SUPERTUX_TILEMAP_H*/
117