3 // SuperTux - A Jump'n Run
4 // Copyright (C) 2004 Matthias Braun <matze@braunis.de
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.
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.
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.
20 #ifndef SUPERTUX_SECTOR_H
21 #define SUPERTUX_SECTOR_H
26 #include "direction.h"
27 #include "math/vector.h"
28 #include "audio/musicref.h"
29 #include "video/drawing_context.h"
31 using namespace SuperTux;
56 /** This class holds a sector (a part of a level) and all the game objects
57 * (badguys, player, background, tilemap, ...)
65 /// read sector from lisp file
66 void parse(const lisp::Lisp& lisp);
67 void parse_old_format(const lisp::Lisp& lisp);
68 /// write sector to lisp file
69 void write(lisp::Writer& writer);
71 /// activates this sector (change music, intialize player class, ...)
72 void activate(const std::string& spawnpoint = "main");
73 /// get best spawn point
74 Vector get_best_spawn_point(Vector pos);
76 void action(float elapsed_time);
77 void update_game_objects();
79 void draw(DrawingContext& context);
82 void add_object(GameObject* object);
84 void set_name(const std::string& name)
85 { this->name = name; }
86 const std::string& get_name() const
89 /// tests if a given rectangle is inside the sector
90 bool inside(const Rectangle& rectangle) const;
92 void play_music(int musictype);
95 /** Checks for all possible collisions. And calls the
96 collision_handlers, which the collision_objects provide for this
98 void collision_handler();
100 bool add_bullet(const Vector& pos, float xm, Direction dir);
101 bool add_smoke_cloud(const Vector& pos);
102 void add_floating_text(const Vector& pos, const std::string& text);
104 /** @evil@ but can't always be avoided in current design... */
105 static Sector* current()
108 /** Get total number of badguys */
109 int get_total_badguys();
111 // make this private again soon
112 void collision_tilemap(MovingObject* object, int depth);
115 void collision_object(MovingObject* object1, MovingObject* object2);
118 GameObject* parse_object(const std::string& name, const lisp::Lisp& lisp);
120 static Sector* _current;
125 MusicRef level_song_fast;
128 std::string song_title;
131 // some special objects, where we need direct access
137 std::vector<Bullet*> bullets;
139 public: // TODO make this private again
140 typedef std::vector<GameObject*> GameObjects;
141 GameObjects gameobjects;
142 typedef std::vector<SpawnPoint*> SpawnPoints;
143 SpawnPoints spawnpoints;
145 Rectangle get_active_region();
148 void fix_old_tiles();
150 /// container for newly created objects, they'll be added in Sector::action
151 GameObjects gameobjects_new;