- added read_string and read_int_vector to LispReader
[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 Tile
46 {
47   texture_type sprite;
48
49   // Directions in which Tux is allowed to walk from this tile
50   bool north;
51   bool east;
52   bool south;
53   bool west;
54
55   /** Stop on this tile or walk over it? */
56   bool stop;
57 };
58
59 class TileManager
60 {
61 private:
62   typedef std::vector<Tile*> Tiles;
63   Tiles tiles;
64   static TileManager* instance_ ;
65
66  TileManager();
67 public:
68   static TileManager* instance() { return instance_ ? instance_ : instance_ = new TileManager(); }
69
70   void load();
71   Tile* get(int i);
72 };
73
74 /** */
75 class WorldMap
76 {
77 private:
78   texture_type tux_sprite;
79   bool quit;
80   std::vector<int> tilemap;
81   int width;
82   int height;
83
84   enum Direction { NONE, WEST, EAST, NORTH, SOUTH };
85   Direction tux_direction;
86   Point tux_tile_pos;
87   /** Length by which tux is away from its current tile, length is in
88       input_direction direction */
89   float tux_offset;
90   bool tux_moving;
91
92   Direction input_direction;
93   bool enter_level;
94
95   Tile* at(Point pos);
96 public:
97   WorldMap();
98   ~WorldMap();
99
100   /** Busy loop */
101   void display();
102   
103   void get_input();
104
105   /** Update Tux position */
106   void update();
107
108   /** Draw one frame */
109   void draw();
110 };
111
112 } // namespace WorldMapNS
113
114 void worldmap_run();
115
116 #endif
117
118 /* Local Variables: */
119 /* mode:c++ */
120 /* End */