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
25 #include "direction.hpp"
26 #include "math/vector.hpp"
27 #include "video/drawing_context.hpp"
42 class ScriptInterpreter;
52 /** This class holds a sector (a part of a level) and all the game objects
53 * (badguys, player, background, tilemap, ...)
61 /// read sector from lisp file
62 void parse(const lisp::Lisp& lisp);
63 void parse_old_format(const lisp::Lisp& lisp);
64 /// write sector to lisp file
65 void write(lisp::Writer& writer);
67 /// activates this sector (change music, intialize player class, ...)
68 void activate(const std::string& spawnpoint);
69 void activate(const Vector& player_pos);
71 void update(float elapsed_time);
72 void update_game_objects();
74 void draw(DrawingContext& context);
77 void add_object(GameObject* object);
79 void set_name(const std::string& name)
80 { this->name = name; }
81 const std::string& get_name() const
84 /// tests if a given rectangle is inside the sector
85 bool inside(const Rect& rectangle) const;
87 void play_music(MusicType musictype);
88 MusicType get_music_type();
90 /** Checks for all possible collisions. And calls the
91 collision_handlers, which the collision_objects provide for this
93 void handle_collisions();
95 bool add_bullet(const Vector& pos, float xm, Direction dir);
96 bool add_smoke_cloud(const Vector& pos);
97 void add_floating_text(const Vector& pos, const std::string& text);
99 /** get currently activated sector. */
100 static Sector* current()
103 /** Get total number of badguys */
104 int get_total_badguys();
106 void collision_tilemap(MovingObject* object, CollisionHit& hit) const;
107 uint32_t collision_tile_attributes(MovingObject* object) const;
109 /** Checks if at the specified rectangle are gameobjects with STATIC flag set
110 * (or solid tiles from the tilemap)
112 bool is_free_space(const Rect& rect) const;
115 void collision_object(MovingObject* object1, MovingObject* object2) const;
116 GameObject* parse_object(const std::string& name, const lisp::Lisp& lisp);
118 static Sector* _current;
123 std::string song_title;
126 // some special objects, where we need direct access
132 std::vector<Bullet*> bullets;
134 std::string init_script;
136 public: // TODO make this private again
137 typedef std::vector<GameObject*> GameObjects;
138 GameObjects gameobjects;
139 typedef std::vector<MovingObject*> MovingObjects;
140 MovingObjects moving_objects;
141 typedef std::vector<SpawnPoint*> SpawnPoints;
142 SpawnPoints spawnpoints;
144 Rect get_active_region();
147 void fix_old_tiles();
149 /// container for newly created objects, they'll be added in Sector::update
150 GameObjects gameobjects_new;
152 MusicType currentmusic;