3 // SuperTux - A Jump'n Run
4 // Copyright (C) 2006 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.
19 #ifndef SUPERTUX_SECTOR_H
20 #define SUPERTUX_SECTOR_H
27 #include "direction.hpp"
28 #include "script_manager.hpp"
29 #include "math/vector.hpp"
30 #include "video/drawing_context.hpp"
45 class ScriptInterpreter;
57 * This class holds a sector (a part of a level) and all the game objects in
66 /// read sector from lisp file
67 void parse(const lisp::Lisp& lisp);
68 void parse_old_format(const lisp::Lisp& lisp);
69 /// write sector to lisp file
70 void write(lisp::Writer& writer);
72 /// activates this sector (change music, intialize player class, ...)
73 void activate(const std::string& spawnpoint);
74 void activate(const Vector& player_pos);
77 void update(float elapsed_time);
78 void update_game_objects();
80 void draw(DrawingContext& context);
83 * runs a script in the context of the sector (sector_table will be the
84 * roottable of this squirrel VM)
86 HSQUIRRELVM run_script(std::istream& in, const std::string& sourcename);
89 void add_object(GameObject* object);
91 void set_name(const std::string& name)
92 { this->name = name; }
93 const std::string& get_name() const
97 * tests if a given rectangle is inside the sector
98 * (a rectangle that is on top of the sector is considered inside)
100 bool inside(const Rect& rectangle) const;
102 void play_music(MusicType musictype);
103 MusicType get_music_type();
105 bool add_bullet(const Vector& pos, float xm, Direction dir);
106 bool add_smoke_cloud(const Vector& pos);
107 void add_floating_text(const Vector& pos, const std::string& text);
109 /** get currently activated sector. */
110 static Sector* current()
113 /** Get total number of badguys */
114 int get_total_badguys();
116 void collision_tilemap(const Rect& dest, const Vector& movement, CollisionHit& hit) const;
118 /** Checks if at the specified rectangle are gameobjects with STATIC flag set
119 * (or solid tiles from the tilemap)
121 bool is_free_space(const Rect& rect) const;
124 * returns a list of players currently in the sector
126 std::vector<Player*> get_players() {
127 return std::vector<Player*>(1, this->player);
130 Rect get_active_region();
132 typedef std::vector<GameObject*> GameObjects;
133 typedef std::vector<MovingObject*> MovingObjects;
134 typedef std::vector<SpawnPoint*> SpawnPoints;
137 uint32_t collision_tile_attributes(const Rect& dest) const;
139 void before_object_remove(GameObject* object);
140 bool before_object_add(GameObject* object);
142 void try_expose(GameObject* object);
143 void try_unexpose(GameObject* object);
145 bool collision_static(MovingObject* object, const Vector& movement);
147 /** Checks for all possible collisions. And calls the
148 collision_handlers, which the collision_objects provide for this
150 void handle_collisions();
152 void collision_object(MovingObject* object1, MovingObject* object2) const;
153 GameObject* parse_object(const std::string& name, const lisp::Lisp& lisp);
155 void fix_old_tiles();
157 static Sector* _current;
161 std::vector<Bullet*> bullets;
163 std::string init_script;
165 /// container for newly created objects, they'll be added in Sector::update
166 GameObjects gameobjects_new;
168 MusicType currentmusic;
170 std::auto_ptr<CollisionGrid> grid;
172 HSQOBJECT sector_table;
174 std::auto_ptr<ScriptManager> script_manager;
176 public: // TODO make this private again
177 /// show collision rectangles of moving objects (for debugging)
178 static bool show_collrects;
179 static bool draw_solids_only;
181 GameObjects gameobjects;
182 MovingObjects moving_objects;
183 SpawnPoints spawnpoints;
188 // some special objects, where we need direct access
189 // (try to avoid accessing them directly)