467fd1db7de0ab55971999244fc7d4e8db55ede4
[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 using namespace SuperTux;
33
34 namespace SuperTux {
35 class GameObject;
36 class LispReader;
37 }
38
39 class InteractiveObject;
40 class Background;
41 class Player;
42 class Camera;
43 class Trampoline;
44 class FlyingPlatform;
45 class TileMap;
46 class Upgrade;
47 class Bullet;
48 class SmokeCloud;
49 class Particles;
50 class BadGuy;
51 class Tile;
52
53 struct SpawnPoint
54 {
55   std::string name;
56   Vector pos;
57 };
58
59 enum {
60   NONE_ENDSEQ_ANIM,
61   FIREWORKS_ENDSEQ_ANIM
62   };
63
64 /** This class holds a sector (a part of a level) and all the game objects
65  * (badguys, player, background, tilemap, ...)
66  */
67 class Sector
68 {
69 public:
70   Sector();
71   ~Sector();
72
73   /// read sector from lisp file
74   void parse(LispReader& reader);
75   void parse_old_format(LispReader& reader);
76   /// write sector to lisp file
77   void write(LispWriter& writer);
78
79   /// activates this sector (change music, intialize player class, ...)
80   void activate(const std::string& spawnpoint = "main");
81   /// get best spawn point
82   Vector get_best_spawn_point(Vector pos);
83
84   void action(float elapsed_time);
85   void update_game_objects();
86
87   void draw(DrawingContext& context);
88
89   /// adds a gameobject
90   void add_object(GameObject* object);
91
92   const std::string& get_name() const
93   { return name; }
94
95   void play_music(int musictype);
96   int get_music_type();
97   
98   /** Checks for all possible collisions. And calls the
99       collision_handlers, which the collision_objects provide for this
100       case (or not). */
101   void collision_handler();
102                                                                                 
103   void add_score(const Vector& pos, int s);
104   void add_bouncy_distro(const Vector& pos);
105   void add_broken_brick(const Vector& pos, Tile* tile);
106   void add_broken_brick_piece(const Vector& pos,
107       const Vector& movement, Tile* tile);
108   void add_bouncy_brick(const Vector& pos);
109                                                                                 
110   BadGuy* add_bad_guy(float x, float y, BadGuyKind kind, bool activate);
111                                                                                 
112   void add_upgrade(const Vector& pos, Direction dir, UpgradeKind kind);
113   bool add_bullet(const Vector& pos, float xm, Direction dir);
114   bool add_smoke_cloud(const Vector& pos);
115   bool add_particles(const Vector& epicenter, const Vector& velocity, const Vector& acceleration, int number, Color color, int size, int life_time);
116   void add_floating_text(const Vector& pos, const std::string& text);
117                                                                                 
118   /** Try to grab the coin at the given coordinates */
119   void trygrabdistro(const Vector& pos, int bounciness);
120                                                                                 
121   /** Try to break the brick at the given coordinates */
122   bool trybreakbrick(const Vector& pos, bool small);
123                                                                                 
124   /** Try to get the content out of a bonus box, thus emptying it */
125   void tryemptybox(const Vector& pos, Direction col_side);
126                                                                                 
127   /** Try to bumb a badguy that might we walking above Tux, thus shaking
128       the tile which the badguy is walking on an killing him this way */
129   void trybumpbadguy(const Vector& pos);
130
131   /** Flip the all the sector vertically. The purpose of this is to let
132       player to play the same level in a different way :) */
133   void do_vertical_flip();
134
135   /** Get end sequence animation */
136   int end_sequence_animation()
137     { return end_sequence_animation_type; }
138
139   /** @evil@ */
140   static Sector* current()
141   { return _current; }
142
143   /** Get total number of some stuff */
144   int get_total_badguys();
145
146 private:
147   void load_music();
148   
149   static Sector* _current;
150   
151   std::string name;
152
153   MusicRef level_song;
154   MusicRef level_song_fast;
155
156   int end_sequence_animation_type;
157
158 public:
159   std::string song_title;
160   float gravity;
161
162   // some special objects, where we need direct access
163   Player* player;
164   TileMap* solids;
165   Background* background;
166   Camera* camera;
167   
168 private:
169   typedef std::vector<BadGuy*> BadGuys;
170   BadGuys badguys;
171   typedef std::vector<Trampoline*> Trampolines;
172   Trampolines trampolines;
173   typedef std::vector<FlyingPlatform*> FlyingPlatforms;
174   FlyingPlatforms flying_platforms;
175
176   std::vector<Upgrade*> upgrades;
177   std::vector<Bullet*> bullets;
178   std::vector<SmokeCloud*> smoke_clouds;
179   std::vector<Particles*> particles;
180
181 public: // ugly
182   typedef std::vector<InteractiveObject*> InteractiveObjects;
183   InteractiveObjects interactive_objects;
184   typedef std::vector<GameObject*> GameObjects;
185   GameObjects gameobjects;
186   GameObjects gameobjects_new; // For newly created objects
187
188 private:
189   typedef std::vector<SpawnPoint*> SpawnPoints;
190   SpawnPoints spawnpoints;
191
192   int distro_counter;
193   bool counting_distros;
194   int currentmusic;
195 };
196
197 #endif
198