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