1f2fe9486c5efc35f1d50f7a593adff71470f7e5
[supertux.git] / src / level.h
1 //  $Id$
2 // 
3 //  SuperTux
4 //  Copyright (C) 2004 SuperTux Development Team, see AUTHORS for details
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
19 //  02111-1307, USA.
20
21 #ifndef SUPERTUX_LEVEL_H
22 #define SUPERTUX_LEVEL_H
23
24 #include <string>
25 #include "texture.h"
26 #include "badguy.h"
27 #include "lispreader.h"
28 #include "musicref.h"
29 #include "gameobjs.h"
30
31 class Tile;
32 class World;
33
34 /** This type holds meta-information about a level-subset. 
35     It could be extended to handle manipulation of subsets. */
36 class LevelSubset
37   {
38   public:
39     LevelSubset();
40     ~LevelSubset();
41
42     static void create(const std::string& subset_name);
43     void load(char *subset);
44     void save();
45
46     std::string name;
47     std::string title;
48     std::string description;
49     Surface* image;
50     int levels;
51  
52   private:
53     void parse(lisp_object_t* cursor);
54   };
55
56 #define LEVEL_NAME_MAX 20
57
58
59 enum TileMapType {
60  TM_BG,
61  TM_IA,
62  TM_FG
63  };
64
65 struct ResetPoint
66 {
67   int x;
68   int y;
69 };
70
71 class Level 
72 {
73  public:
74   Surface* img_bkgd;
75   MusicRef level_song;
76   MusicRef level_song_fast;
77
78   std::string name;
79   std::string author;
80   std::string song_title;
81   std::string bkgd_image;
82   std::string particle_system;
83   std::vector<unsigned int> bg_tiles; /* Tiles in the background */
84   std::vector<unsigned int> ia_tiles; /* Tiles which can interact in the game (solids for example)*/
85   std::vector<unsigned int> fg_tiles; /* Tiles in the foreground */
86 //  std::vector<unsigned int> bg_tiles[15]; /* Tiles in the background */
87 //  std::vector<unsigned int> ia_tiles[15]; /* Tiles which can interact in the game (solids for example)*/
88 //  std::vector<unsigned int> fg_tiles[15]; /* Tiles in the foreground */
89   int time_left;
90   Color bkgd_top;
91   Color bkgd_bottom;
92   int width;
93   int height;
94   int bkgd_speed;
95   Vector start_pos;
96   float gravity;
97
98   /** A collection of points to which Tux can be reset after a lost live */
99   std::vector<ResetPoint> reset_points;
100  public:
101   Level();
102   Level(const std::string& subset, int level, World* world);
103   Level(const std::string& filename, World* world);
104   ~Level();
105
106   /** Will the Level structure with default values */
107   void init_defaults();
108   
109   /** Cleanup the level struct from allocated tile data and such */
110   void cleanup();
111
112   /** Load data for this level: 
113       Returns -1, if the loading of the level failed. 
114       XXX the world parameter is a temporary hack   
115   */
116   int  load(const std::string& subset, int level, World* world);
117
118   /** Load data for this level: 
119       Returns -1, if the loading of the level failed. 
120       XXX the world parameter is a temporary hack
121    */
122   int  load(const std::string& filename, World* world);
123
124   void load_gfx();
125   
126   void load_song();
127   void free_song();
128   MusicRef get_level_music();
129   MusicRef get_level_music_fast();
130
131   // XXX the world parameter is a temporary hack
132   void save(const std::string& subset, int level, World* world);
133
134   /** Edit a piece of the map! */
135   void change(float x, float y, int tm, unsigned int c);
136
137   /** Resize the level to a new width/height */
138   void resize(int new_width, int new_height);
139
140   /** Return the id of the tile at position x/y */
141   unsigned int gettileid(float x, float y) const;
142   /** returns the id of the tile at position x,y
143    * (these are logical and not pixel coordinates)
144    */
145   unsigned int get_tile_at(int x, int y) const;
146
147   void load_image(Surface** ptexture, std::string theme, const char * file, int use_alpha);
148 };
149
150 #endif /*SUPERTUX_LEVEL_H*/