96fcb1f0a7e0d0d018c42790e15b473fbe47a5ac
[supertux.git] / src / level.h
1 //
2 // C Interface: level
3 //
4 // Description:
5 //
6 //
7 // Author: Tobias Glaesser <tobi.web@gmx.de>, (C) 2003
8 //
9 // Copyright: See COPYING file that comes with this distribution
10 //
11 //
12
13 #ifndef SUPERTUX_LEVEL_H
14 #define SUPERTUX_LEVEL_H
15
16 #include <string>
17 #include "texture.h"
18 #include "badguy.h"
19 #include "lispreader.h"
20
21 class Tile;
22
23 /** This type holds meta-information about a level-subset. 
24     It could be extended to handle manipulation of subsets. */
25 class st_subset
26   {
27   public:
28     st_subset();
29     static void create(const std::string& subset_name);
30     void load(char *subset);
31     void save();
32     void free();
33
34     std::string name;
35     std::string title;
36     std::string description;
37     texture_type image;
38     int levels;
39  
40   private:
41     void parse(lisp_object_t* cursor);
42   };
43
44 #define LEVEL_NAME_MAX 20
45
46
47 enum TileMapType {
48  TM_BG,
49  TM_IA,
50  TM_FG
51  };
52
53 class Level 
54 {
55  public:
56   texture_type img_bkgd;
57
58   std::string name;
59   std::string theme;
60   std::string song_title;
61   std::string bkgd_image;
62   std::string particle_system;
63   unsigned int* bg_tiles[15]; /* Tiles in the background */
64   unsigned int* ia_tiles[15]; /* Tiles which can interact in the game (solids for example)*/
65   unsigned int* fg_tiles[15]; /* Tiles in the foreground */
66   int time_left;
67   int bkgd_red;
68   int bkgd_green;
69   int bkgd_blue;
70   int width;
71   int  endpos;
72   float gravity;
73
74   std::vector<BadGuyData> badguy_data;
75  public:
76   /** Will the Level structure with default values */
77   void init_defaults();
78   
79   /** Cleanup the level struct from allocated tile data and such */
80   void cleanup();
81
82   /** Load data for this level: 
83       Returns -1, if the loading of the level failed. */
84   int  load(const std::string& subset, int level);
85
86   /** Load data for this level: 
87       Returns -1, if the loading of the level failed. */
88   int  load(const std::string& filename);
89
90   void load_gfx();
91   
92   void load_song();
93   void free_song();
94
95   void save(const char* subset, int level);
96
97   /** Edit a piece of the map! */
98   void change(float x, float y, int tm, unsigned int c);
99
100   /** Resize the level to a new width */
101   void change_size (int new_width);
102
103   /** Return the id of the tile at position x/y */
104   unsigned int gettileid(float x, float y);
105
106   void free_gfx();
107
108   void load_image(texture_type* ptexture, std::string theme, const char * file, int use_alpha);
109 };
110
111 #endif /*SUPERTUX_LEVEL_H*/