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