8aa2b481a21f6a772d10d841ace1e101c680ac75
[supertux.git] / src / object / 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 #include <stdint.h>
25
26 #include "special/game_object.h"
27 #include "serializable.h"
28 #include "math/vector.h"
29
30 using namespace SuperTux;
31
32 namespace SuperTux {
33 class LispReader;
34 }
35
36 class Level;
37 class TileManager;
38 class Tile;
39
40 /**
41  * This class is reponsible for drawing the level tiles
42  */
43 class TileMap : public GameObject, public Serializable
44 {
45 public:
46   TileMap();
47   TileMap(LispReader& reader);
48   TileMap(int layer_, bool solid_, size_t width_, size_t height_);
49   virtual ~TileMap();
50
51   virtual void write(LispWriter& writer);
52
53   virtual void action(float elapsed_time);
54   virtual void draw(DrawingContext& context);
55
56   void set(int width, int height, const std::vector<unsigned int>& vec,
57       int layer, bool solid);
58
59   /** resizes the tilemap to a new width and height (tries to not destroy the
60    * existing map)
61    */
62   void resize(int newwidth, int newheight);
63
64   /** Flip the all tile map vertically. The purpose of this is to let
65       player to play the same level in a different way :) */
66   void do_vertical_flip();
67
68   size_t get_width() const
69   { return width; }
70
71   size_t get_height() const
72   { return height; }
73
74   int get_layer() const
75   { return layer; }
76   
77   bool is_solid() const
78   { return solid; }
79
80   /// returns tile in row y and column y (of the tilemap)
81   const Tile* get_tile(int x, int y) const;
82   /// returns tile at position pos (in world coordinates)
83   const Tile* get_tile_at(const Vector& pos) const;
84
85   void change(int x, int y, uint32_t newtile);
86
87   void change_at(const Vector& pos, uint32_t newtile);
88
89 private:
90   std::vector<uint32_t> tiles;
91   
92 private:
93   TileManager* tilemanager;
94   bool solid;
95   float speed;
96   int width, height;
97   int layer;
98
99   bool vertical_flip;
100 };
101
102 #endif /*SUPERTUX_TILEMAP_H*/
103