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.
19 #ifndef SUPERTUX_SECTOR_H
20 #define SUPERTUX_SECTOR_H
26 #include "direction.hpp"
27 #include "math/vector.hpp"
28 #include "video/drawing_context.hpp"
43 class ScriptInterpreter;
53 /** This class holds a sector (a part of a level) and all the game objects
54 * (badguys, player, background, tilemap, ...)
62 /// read sector from lisp file
63 void parse(const lisp::Lisp& lisp);
64 void parse_old_format(const lisp::Lisp& lisp);
65 /// write sector to lisp file
66 void write(lisp::Writer& writer);
68 /// activates this sector (change music, intialize player class, ...)
69 void activate(const std::string& spawnpoint);
70 void activate(const Vector& player_pos);
73 void update(float elapsed_time);
74 void update_game_objects();
76 void draw(DrawingContext& context);
79 * runs a script in the context of the sector (sector_table will be the
80 * roottable of this squirrel VM)
82 HSQUIRRELVM run_script(std::istream& in, const std::string& sourcename);
85 void add_object(GameObject* object);
87 void set_name(const std::string& name)
88 { this->name = name; }
89 const std::string& get_name() const
92 /// tests if a given rectangle is inside the sector
93 bool inside(const Rect& rectangle) const;
95 void play_music(MusicType musictype);
96 MusicType get_music_type();
98 bool add_bullet(const Vector& pos, float xm, Direction dir);
99 bool add_smoke_cloud(const Vector& pos);
100 void add_floating_text(const Vector& pos, const std::string& text);
102 /** get currently activated sector. */
103 static Sector* current()
106 /** Get total number of badguys */
107 int get_total_badguys();
109 void collision_tilemap(const Rect& dest, const Vector& movement, CollisionHit& hit) const;
111 /** Checks if at the specified rectangle are gameobjects with STATIC flag set
112 * (or solid tiles from the tilemap)
114 bool is_free_space(const Rect& rect) const;
117 * returns a list of players currently in the sector
119 std::vector<Player*> get_players() {
120 return std::vector<Player*>(1, this->player);
123 Rect get_active_region();
126 uint32_t collision_tile_attributes(const Rect& dest) const;
128 void before_object_remove(GameObject* object);
129 bool before_object_add(GameObject* object);
131 void try_expose(GameObject* object);
132 void try_unexpose(GameObject* object);
134 bool collision_static(MovingObject* object, const Vector& movement);
136 /** Checks for all possible collisions. And calls the
137 collision_handlers, which the collision_objects provide for this
139 void handle_collisions();
141 void collision_object(MovingObject* object1, MovingObject* object2) const;
142 GameObject* parse_object(const std::string& name, const lisp::Lisp& lisp);
144 void fix_old_tiles();
146 typedef std::vector<GameObject*> GameObjects;
147 typedef std::vector<MovingObject*> MovingObjects;
148 typedef std::vector<SpawnPoint*> SpawnPoints;
150 static Sector* _current;
154 std::vector<Bullet*> bullets;
156 std::string init_script;
158 /// container for newly created objects, they'll be added in Sector::update
159 GameObjects gameobjects_new;
161 MusicType currentmusic;
165 HSQOBJECT sector_table;
167 public: // TODO make this private again
168 GameObjects gameobjects;
169 MovingObjects moving_objects;
170 SpawnPoints spawnpoints;
175 // some special objects, where we need direct access
176 // (try to avoid accessing them directly)