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