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
96 /// tests if a given rectangle is inside the sector
97 bool inside(const Rect& rectangle) const;
99 void play_music(MusicType musictype);
100 MusicType get_music_type();
102 bool add_bullet(const Vector& pos, float xm, Direction dir);
103 bool add_smoke_cloud(const Vector& pos);
104 void add_floating_text(const Vector& pos, const std::string& text);
106 /** get currently activated sector. */
107 static Sector* current()
110 /** Get total number of badguys */
111 int get_total_badguys();
113 void collision_tilemap(const Rect& dest, const Vector& movement, CollisionHit& hit) const;
115 /** Checks if at the specified rectangle are gameobjects with STATIC flag set
116 * (or solid tiles from the tilemap)
118 bool is_free_space(const Rect& rect) const;
121 * returns a list of players currently in the sector
123 std::vector<Player*> get_players() {
124 return std::vector<Player*>(1, this->player);
127 Rect get_active_region();
129 typedef std::vector<GameObject*> GameObjects;
130 typedef std::vector<MovingObject*> MovingObjects;
131 typedef std::vector<SpawnPoint*> SpawnPoints;
134 uint32_t collision_tile_attributes(const Rect& dest) const;
136 void before_object_remove(GameObject* object);
137 bool before_object_add(GameObject* object);
139 void try_expose(GameObject* object);
140 void try_unexpose(GameObject* object);
142 bool collision_static(MovingObject* object, const Vector& movement);
144 /** Checks for all possible collisions. And calls the
145 collision_handlers, which the collision_objects provide for this
147 void handle_collisions();
149 void collision_object(MovingObject* object1, MovingObject* object2) const;
150 GameObject* parse_object(const std::string& name, const lisp::Lisp& lisp);
152 void fix_old_tiles();
154 static Sector* _current;
158 std::vector<Bullet*> bullets;
160 std::string init_script;
162 /// container for newly created objects, they'll be added in Sector::update
163 GameObjects gameobjects_new;
165 MusicType currentmusic;
167 std::auto_ptr<CollisionGrid> grid;
169 HSQOBJECT sector_table;
171 std::auto_ptr<ScriptManager> script_manager;
173 public: // TODO make this private again
174 /// show collision rectangles of moving objects (for debugging)
175 static bool show_collrects;
176 static bool draw_solids_only;
178 GameObjects gameobjects;
179 MovingObjects moving_objects;
180 SpawnPoints spawnpoints;
185 // some special objects, where we need direct access
186 // (try to avoid accessing them directly)