mainly changed #includes to work with the new SuperTux library
[supertux.git] / src / sector.h
1 //  $Id$
2 //
3 //  SuperTux -  A Jump'n Run
4 //  Copyright (C) 2004 Matthias Braun <matze@braunis.de
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  02111-1307, USA.
19
20 #ifndef SUPERTUX_SECTOR_H
21 #define SUPERTUX_SECTOR_H
22
23 #include <string>
24 #include <vector>
25
26 #include "math/vector.h"
27 #include "badguy.h"
28 #include "special.h"
29 #include "audio/musicref.h"
30 #include "video/drawing_context.h"
31
32 class GameObject;
33 class InteractiveObject;
34 class Background;
35 class Player;
36 class Camera;
37 class Trampoline;
38 class FlyingPlatform;
39 class TileMap;
40 class Upgrade;
41 class Bullet;
42 class BadGuy;
43 class Vector;
44 class LispReader;
45 class Tile;
46
47 struct SpawnPoint
48 {
49   std::string name;
50   Vector pos;
51 };
52
53 /** This class holds a sector (a part of a level) and all the game objects
54  * (badguys, player, background, tilemap, ...)
55  */
56 class Sector
57 {
58 public:
59   Sector();
60   ~Sector();
61
62   /// read sector from lisp file
63   void parse(LispReader& reader);
64   void parse_old_format(LispReader& reader);
65   /// write sector to lisp file
66   void write(LispWriter& writer);
67
68   /// activates this sector (change music, intialize player class, ...)
69   void activate(const std::string& spawnpoint = "main");
70
71   void action(float elapsed_time);
72   void update_game_objects();
73
74   void draw(DrawingContext& context);
75
76   /// adds a gameobject
77   void add_object(GameObject* object);
78
79   const std::string& get_name() const
80   { return name; }
81
82   void play_music(int musictype);
83   int get_music_type();
84   
85   /** Checks for all possible collisions. And calls the
86       collision_handlers, which the collision_objects provide for this
87       case (or not). */
88   void collision_handler();
89                                                                                 
90   void add_score(const Vector& pos, int s);
91   void add_bouncy_distro(const Vector& pos);
92   void add_broken_brick(const Vector& pos, Tile* tile);
93   void add_broken_brick_piece(const Vector& pos,
94       const Vector& movement, Tile* tile);
95   void add_bouncy_brick(const Vector& pos);
96                                                                                 
97   BadGuy* add_bad_guy(float x, float y, BadGuyKind kind);
98                                                                                 
99   void add_upgrade(const Vector& pos, Direction dir, UpgradeKind kind);
100   bool add_bullet(const Vector& pos, float xm, Direction dir);
101                                                                                 
102   /** Try to grab the coin at the given coordinates */
103   void trygrabdistro(const Vector& pos, int bounciness);
104                                                                                 
105   /** Try to break the brick at the given coordinates */
106   bool trybreakbrick(const Vector& pos, bool small);
107                                                                                 
108   /** Try to get the content out of a bonus box, thus emptying it */
109   void tryemptybox(const Vector& pos, Direction col_side);
110                                                                                 
111   /** Try to bumb a badguy that might we walking above Tux, thus shaking
112       the tile which the badguy is walking on an killing him this way */
113   void trybumpbadguy(const Vector& pos);
114
115   /** Flip the all the sector vertically. The purpose of this is to let
116       player to play the same level in a different way :) */
117   void do_vertical_flip();
118
119   /** @evil@ */
120   static Sector* current()
121   { return _current; }
122
123 private:
124   void load_music();
125   
126   static Sector* _current;
127   
128   std::string name;
129
130   MusicRef level_song;
131   MusicRef level_song_fast;
132
133 public:
134   std::string song_title;
135   float gravity;
136
137   // some special objects, where we need direct access
138   Player* player;
139   TileMap* solids;
140   Background* background;
141   Camera* camera;
142   
143 private:
144   typedef std::vector<BadGuy*> BadGuys;
145   BadGuys badguys;
146   typedef std::vector<Trampoline*> Trampolines;
147   Trampolines trampolines;
148   typedef std::vector<FlyingPlatform*> FlyingPlatforms;
149   FlyingPlatforms flying_platforms;
150
151   std::vector<Upgrade*> upgrades;
152   std::vector<Bullet*> bullets;
153
154 public: // ugly
155   typedef std::vector<InteractiveObject*> InteractiveObjects;
156   InteractiveObjects interactive_objects;
157   typedef std::vector<GameObject*> GameObjects;
158   GameObjects gameobjects;
159   GameObjects gameobjects_new; // For newly created objects
160
161 private:
162   typedef std::vector<SpawnPoint*> SpawnPoints;
163   SpawnPoints spawnpoints;
164
165   int distro_counter;
166   bool counting_distros;
167   int currentmusic;        
168 };
169
170 #endif
171