- did some C++ifying. let's try to follow suit :)
[supertux.git] / src / tilemap.h
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
20 #ifndef SUPERTUX_TILEMAP_H
21 #define SUPERTUX_TILEMAP_H
22
23 #include <vector>
24
25 #include "game_object.h"
26 #include "serializable.h"
27 #include "vector.h"
28
29 class Level;
30 class TileManager;
31 class LispReader;
32 class Tile;
33
34 /**
35  * This class is reponsible for drawing the level tiles
36  */
37 class TileMap : public GameObject, public Serializable
38 {
39 public:
40   TileMap();
41   TileMap(LispReader& reader);
42   virtual ~TileMap();
43
44   virtual void write(LispWriter& writer);
45
46   virtual void action(float elapsed_time);
47   virtual void draw(DrawingContext& context);
48
49   void set(int width, int height, const std::vector<unsigned int>& vec,
50       int layer, bool solid);
51
52   /** resizes the tilemap to a new width and height (tries to not destroy the
53    * existing map)
54    */
55   void resize(int newwidth, int newheight);
56
57   size_t get_width() const
58   { return width; }
59
60   size_t get_height() const
61   { return height; }
62   
63   bool is_solid() const
64   { return solid; }
65
66   unsigned int get_tile_id_at(const Vector& pos) const;
67
68   /// returns tile in row y and column y (of the tilemap)
69   Tile* get_tile(int x, int y) const;
70   /// returns tile at position pos (in world coordinates)
71   Tile* get_tile_at(const Vector& pos) const;
72
73   void change(int x, int y, unsigned int newtile);
74
75   void change_at(const Vector& pos, unsigned int newtile);
76
77 public:
78   std::vector<unsigned int> tiles;
79   
80 private:
81   TileManager* tilemanager;
82   bool solid;
83   float speed;
84   int width, height;
85   int layer;
86 };
87
88 #endif /*SUPERTUX_TILEMAP_H*/
89