'nother music patch by matzeb
[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
30 class Tile;
31
32 /** This type holds meta-information about a level-subset. 
33     It could be extended to handle manipulation of subsets. */
34 class st_subset
35   {
36   public:
37     st_subset();
38     static void create(const std::string& subset_name);
39     void load(char *subset);
40     void save();
41     void free();
42
43     std::string name;
44     std::string title;
45     std::string description;
46     Surface* image;
47     int levels;
48  
49   private:
50     void parse(lisp_object_t* cursor);
51   };
52
53 #define LEVEL_NAME_MAX 20
54
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 theme;
78   std::string song_title;
79   std::string bkgd_image;
80   std::string particle_system;
81   std::vector<unsigned int> bg_tiles[15]; /* Tiles in the background */
82   std::vector<unsigned int> ia_tiles[15]; /* Tiles which can interact in the game (solids for example)*/
83   std::vector<unsigned int> fg_tiles[15]; /* Tiles in the foreground */
84   int time_left;
85   Color bkgd_top;
86   Color bkgd_bottom;
87   int width;
88   int start_pos_x;
89   int start_pos_y;
90   int  endpos;
91   bool use_endsequence;
92   float gravity;
93
94   std::vector<BadGuyData> badguy_data;
95
96   /** A collection of points to which Tux can be reset after a lost live */
97   std::vector<ResetPoint> reset_points;
98  public:
99   Level();
100   Level(const std::string& subset, int level);
101   Level(const std::string& filename);
102   ~Level();
103
104   /** Will the Level structure with default values */
105   void init_defaults();
106   
107   /** Cleanup the level struct from allocated tile data and such */
108   void cleanup();
109
110   /** Load data for this level: 
111       Returns -1, if the loading of the level failed. */
112   int  load(const std::string& subset, int level);
113
114   /** Load data for this level: 
115       Returns -1, if the loading of the level failed. */
116   int  load(const std::string& filename);
117
118   void load_gfx();
119   void free_gfx();
120   
121   void load_song();
122   void free_song();
123   MusicRef get_level_music();
124   MusicRef get_level_music_fast();
125
126   void save(const char* subset, int level);
127
128   /** Edit a piece of the map! */
129   void change(float x, float y, int tm, unsigned int c);
130
131   /** Resize the level to a new width */
132   void change_size (int new_width);
133
134   /** Return the id of the tile at position x/y */
135   unsigned int gettileid(float x, float y);
136
137   void load_image(Surface** ptexture, std::string theme, const char * file, int use_alpha);
138 };
139
140 #endif /*SUPERTUX_LEVEL_H*/