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