big refactoring of level and world class. A level is now basically a set of
[supertux.git] / src / sector.h
1 #ifndef __SECTOR_H__
2 #define __SECTOR_H__
3
4 #include <string>
5 #include <vector>
6 #include "vector.h"
7 #include "badguy.h"
8 #include "special.h"
9 #include "musicref.h"
10 #include "screen/drawing_context.h"
11
12 class GameObject;
13 class Background;
14 class Player;
15 class Camera;
16 class Trampoline;
17 class FlyingPlatform;
18 class TileMap;
19 class Upgrade;
20 class Bullet;
21 class BadGuy;
22 class Vector;
23 class LispReader;
24 class Tile;
25
26 struct SpawnPoint
27 {
28   std::string name;
29   Vector pos;
30 };
31
32 /** This class holds a sector (a part of a level) and all the game objects
33  * (badguys, player, background, tilemap, ...)
34  */
35 class Sector
36 {
37 public:
38   Sector();
39   ~Sector();
40
41   /// read sector from lisp file
42   void parse(LispReader& reader);
43   void parse_old_format(LispReader& reader);
44   /// write sector to lisp file
45   void write(LispWriter& writer);
46
47   /// activates this sector (change music, intialize player class, ...)
48   void activate(const std::string& spawnpoint = "main");
49
50   void action(float elapsed_time);
51   void draw(DrawingContext& context);
52
53   /// adds a gameobject
54   void add_object(GameObject* object);
55
56   const std::string& get_name() const
57   { return name; }
58
59   void play_music(int musictype);
60   int get_music_type();
61   
62   /** Checks for all possible collisions. And calls the
63       collision_handlers, which the collision_objects provide for this
64       case (or not). */
65   void collision_handler();
66                                                                                 
67   void add_score(const Vector& pos, int s);
68   void add_bouncy_distro(const Vector& pos);
69   void add_broken_brick(const Vector& pos, Tile* tile);
70   void add_broken_brick_piece(const Vector& pos,
71       const Vector& movement, Tile* tile);
72   void add_bouncy_brick(const Vector& pos);
73                                                                                 
74   BadGuy* add_bad_guy(float x, float y, BadGuyKind kind);
75                                                                                 
76   void add_upgrade(const Vector& pos, Direction dir, UpgradeKind kind);
77   bool add_bullet(const Vector& pos, float xm, Direction dir);
78                                                                                 
79   /** Try to grab the coin at the given coordinates */
80   void trygrabdistro(const Vector& pos, int bounciness);
81                                                                                 
82   /** Try to break the brick at the given coordinates */
83   bool trybreakbrick(const Vector& pos, bool small);
84                                                                                 
85   /** Try to get the content out of a bonus box, thus emptying it */
86   void tryemptybox(const Vector& pos, Direction col_side);
87                                                                                 
88   /** Try to bumb a badguy that might we walking above Tux, thus shaking
89       the tile which the badguy is walking on an killing him this way */
90   void trybumpbadguy(const Vector& pos);
91
92   /** @evil@ */
93   static Sector* current()
94   { return _current; }
95
96 private:
97   void load_music();
98   
99   static Sector* _current;
100   
101   std::string name;
102
103   std::string song_title;
104   MusicRef level_song;
105   MusicRef level_song_fast;
106
107 public:
108   float gravity;
109
110   // some special objects, where we need direct access
111   Player* player;
112   TileMap* solids;
113   Background* background;
114   Camera* camera;
115   
116 private:
117   typedef std::vector<BadGuy*> BadGuys;
118   BadGuys badguys;
119   typedef std::vector<Trampoline*> Trampolines;
120   Trampolines trampolines;
121   typedef std::vector<FlyingPlatform*> FlyingPlatforms;
122   FlyingPlatforms flying_platforms;
123
124   std::vector<Upgrade*> upgrades;
125   std::vector<Bullet*> bullets;
126
127 public: // ugly
128   typedef std::vector<GameObject*> GameObjects;
129   GameObjects gameobjects;
130
131 private:
132   typedef std::vector<SpawnPoint*> SpawnPoints;
133   SpawnPoints spawnpoints;
134
135   int distro_counter;
136   bool counting_distros;
137   int currentmusic;        
138 };
139
140 #endif
141