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