fixed butt jump to work even when up-key is not pressed, added a little jump after...
[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
33 /** This type holds meta-information about a level-subset. 
34     It could be extended to handle manipulation of subsets. */
35 class LevelSubset
36   {
37   public:
38     LevelSubset();
39     ~LevelSubset();
40
41     static void create(const std::string& subset_name);
42     void load(char *subset);
43     void save();
44
45     std::string name;
46     std::string title;
47     std::string description;
48     Surface* image;
49     int levels;
50  
51   private:
52     void parse(lisp_object_t* cursor);
53   };
54
55 #define LEVEL_NAME_MAX 20
56
57
58 enum TileMapType {
59  TM_BG,
60  TM_IA,
61  TM_FG
62  };
63
64 struct ResetPoint
65 {
66   int x;
67   int y;
68 };
69
70 class Level 
71 {
72  public:
73   Surface* img_bkgd;
74   MusicRef level_song;
75   MusicRef level_song_fast;
76
77   std::string name;
78   std::string author;
79   std::string song_title;
80   std::string bkgd_image;
81   std::string particle_system;
82   std::vector<std::vector<unsigned int> > bg_tiles; /* Tiles in the background */
83   std::vector<std::vector<unsigned int> > ia_tiles; /* Tiles which can interact in the game (solids for example)*/
84   std::vector<std::vector<unsigned int> > fg_tiles; /* Tiles in the foreground */
85 //  std::vector<unsigned int> bg_tiles[15]; /* Tiles in the background */
86 //  std::vector<unsigned int> ia_tiles[15]; /* Tiles which can interact in the game (solids for example)*/
87 //  std::vector<unsigned int> fg_tiles[15]; /* Tiles in the foreground */
88   int time_left;
89   Color bkgd_top;
90   Color bkgd_bottom;
91   int width;
92   int height;
93   int bkgd_speed;
94   int start_pos_x;
95   int start_pos_y;
96   float gravity;
97   bool back_scrolling;
98   float hor_autoscroll_speed;
99
100   std::vector<BadGuyData> badguy_data;
101   std::vector< ObjectData<TrampolineData> > trampoline_data;
102
103   /** A collection of points to which Tux can be reset after a lost live */
104   std::vector<ResetPoint> reset_points;
105  public:
106   Level();
107   Level(const std::string& subset, int level);
108   Level(const std::string& filename);
109   ~Level();
110
111   /** Will the Level structure with default values */
112   void init_defaults();
113   
114   /** Cleanup the level struct from allocated tile data and such */
115   void cleanup();
116
117   /** Load data for this level: 
118       Returns -1, if the loading of the level failed. */
119   int  load(const std::string& subset, int level);
120
121   /** Load data for this level: 
122       Returns -1, if the loading of the level failed. */
123   int  load(const std::string& filename);
124
125   void load_gfx();
126   
127   void load_song();
128   void free_song();
129   MusicRef get_level_music();
130   MusicRef get_level_music_fast();
131
132   void save(const std::string& subset, int level);
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 change_width (int new_width);
139   void change_height (int new_height);
140
141   /* Draw background */
142   void draw_bg();
143
144   /** Return the id of the tile at position x/y */
145   unsigned int gettileid(float x, float y) const;
146   /** returns the id of the tile at position x,y
147    * (these are logical and not pixel coordinates)
148    */
149   unsigned int get_tile_at(int x, int y) const;
150
151   void load_image(Surface** ptexture, std::string theme, const char * file, int use_alpha);
152 };
153
154 #endif /*SUPERTUX_LEVEL_H*/