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