-converted remaining classes to GameObject
[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   int start_pos_x;
96   int start_pos_y;
97   float gravity;
98   bool back_scrolling;
99   float hor_autoscroll_speed;
100
101   /** A collection of points to which Tux can be reset after a lost live */
102   std::vector<ResetPoint> reset_points;
103  public:
104   Level();
105   Level(const std::string& subset, int level, World* world);
106   Level(const std::string& filename, World* world);
107   ~Level();
108
109   /** Will the Level structure with default values */
110   void init_defaults();
111   
112   /** Cleanup the level struct from allocated tile data and such */
113   void cleanup();
114
115   /** Load data for this level: 
116       Returns -1, if the loading of the level failed. 
117       XXX the world parameter is a temporary hack   
118   */
119   int  load(const std::string& subset, int level, World* world);
120
121   /** Load data for this level: 
122       Returns -1, if the loading of the level failed. 
123       XXX the world parameter is a temporary hack
124    */
125   int  load(const std::string& filename, World* world);
126
127   void load_gfx();
128   
129   void load_song();
130   void free_song();
131   MusicRef get_level_music();
132   MusicRef get_level_music_fast();
133
134   // XXX the world parameter is a temporary hack
135   void save(const std::string& subset, int level, World* world);
136
137   /** Edit a piece of the map! */
138   void change(float x, float y, int tm, unsigned int c);
139
140   /** Resize the level to a new width/height */
141   void resize(int new_width, int new_height);
142
143   /* Draw background */
144   void draw_bg();
145
146   /** Return the id of the tile at position x/y */
147   unsigned int gettileid(float x, float y) const;
148   /** returns the id of the tile at position x,y
149    * (these are logical and not pixel coordinates)
150    */
151   unsigned int get_tile_at(int x, int y) const;
152
153   void load_image(Surface** ptexture, std::string theme, const char * file, int use_alpha);
154 };
155
156 #endif /*SUPERTUX_LEVEL_H*/