d8317936c9a1c98e6b2c62f656d37d6d14e64d1b
[supertux.git] / src / worldmap.h
1 //  $Id$
2 // 
3 //  SuperTux
4 //  Copyright (C) 2004 Ingo Ruhnke <grumbel@gmx.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 HEADER_WORLDMAP_HXX
21 #define HEADER_WORLDMAP_HXX
22
23 #include <vector>
24 #include <string>
25
26 namespace WorldMapNS {
27
28 struct Point
29 {
30   Point() : x(0), y(0) {}
31
32   Point(int x_, int y_)
33     : x(x_), y(y_) {}
34
35   int x;
36   int y;
37 };
38
39 struct Pointf
40 {
41   float x;
42   float y;
43 };
44
45 struct Level
46 {
47   int x;
48   int y;
49   std::string name;
50 };
51
52 struct Tile
53 {
54   texture_type sprite;
55
56   // Directions in which Tux is allowed to walk from this tile
57   bool north;
58   bool east;
59   bool south;
60   bool west;
61
62   /** Stop on this tile or walk over it? */
63   bool stop;
64 };
65
66 class TileManager
67 {
68 private:
69   typedef std::vector<Tile*> Tiles;
70   Tiles tiles;
71   static TileManager* instance_ ;
72
73  TileManager();
74 public:
75   static TileManager* instance() { return instance_ ? instance_ : instance_ = new TileManager(); }
76
77   void load();
78   Tile* get(int i);
79 };
80
81 /** */
82 class WorldMap
83 {
84 private:
85   texture_type tux_sprite;
86   texture_type level_sprite;
87   bool quit;
88
89   std::string name;
90   std::string music;
91
92   std::vector<int> tilemap;
93   int width;
94   int height;
95
96   typedef std::vector<Level> Levels;
97   Levels levels;
98
99   Mix_Music* song;
100
101   enum Direction { NONE, WEST, EAST, NORTH, SOUTH };
102   Direction tux_direction;
103   Point tux_tile_pos;
104   /** Length by which tux is away from its current tile, length is in
105       input_direction direction */
106   float tux_offset;
107   bool tux_moving;
108
109   Direction input_direction;
110   bool enter_level;
111
112   Tile* at(Point pos);
113 public:
114   WorldMap();
115   ~WorldMap();
116
117   /** Busy loop */
118   void display();
119
120   void load_map();
121   
122   void get_input();
123
124   /** Update Tux position */
125   void update();
126
127   /** Draw one frame */
128   void draw();
129 };
130
131 } // namespace WorldMapNS
132
133 void worldmap_run();
134
135 #endif
136
137 /* Local Variables: */
138 /* mode:c++ */
139 /* End */