#include "scripting/ssector.hpp"
#include "supertux/direction.hpp"
+#include "supertux/game_object_ptr.hpp"
#include "util/reader_fwd.hpp"
#include "util/writer_fwd.hpp"
#include "util/currenton.hpp"
#include "video/color.hpp"
+#include "object/anchor_point.hpp"
namespace collision {
class Constraints;
}
class Vector;
-class Rect;
+class Rectf;
class Sprite;
class GameObject;
class Player;
+class PlayerStatus;
class Camera;
class TileMap;
class Bullet;
*
* Sectors contain GameObjects, e.g. Badguys and Players.
*/
-class Sector : public Scripting::SSector,
+class Sector : public scripting::SSector,
public Currenton<Sector>
{
public:
/// read sector from lisp file
void parse(const Reader& lisp);
void parse_old_format(const Reader& lisp);
-
+
/// activates this sector (change music, initialize player class, ...)
void activate(const std::string& spawnpoint);
void activate(const Vector& player_pos);
HSQUIRRELVM run_script(std::istream& in, const std::string& sourcename);
/// adds a gameobject
- void add_object(GameObject* object);
+ void add_object(GameObjectPtr object);
- void set_name(const std::string& name)
- { this->name = name; }
+ void set_name(const std::string& name_)
+ { this->name = name_; }
const std::string& get_name() const
{ return name; }
* tests if a given rectangle is inside the sector
* (a rectangle that is on top of the sector is considered inside)
*/
- bool inside(const Rect& rectangle) const;
+ bool inside(const Rectf& rectangle) const;
void play_music(MusicType musictype);
+ void resume_music();
MusicType get_music_type();
- bool add_bullet(const Vector& pos, float xm, Direction dir);
+ int get_active_bullets()
+ { return (int)bullets.size(); }
bool add_smoke_cloud(const Vector& pos);
/** get currently activated sector. */
{
int total = 0;
for(GameObjects::iterator i = gameobjects.begin(); i != gameobjects.end(); ++i) {
- if (dynamic_cast<T*>(*i)) total++;
+ if (dynamic_cast<T*>(i->get())) total++;
}
return total;
}
void collision_tilemap(collision::Constraints* constraints,
- const Vector& movement, const Rect& dest) const;
+ const Vector& movement, const Rectf& dest,
+ MovingObject &object) const;
/**
* Checks if the specified rectangle is free of (solid) tiles.
* Note that this does not include static objects, e.g. bonus blocks.
*/
- bool is_free_of_tiles(const Rect& rect, const bool ignoreUnisolid = false) const;
+ bool is_free_of_tiles(const Rectf& rect, const bool ignoreUnisolid = false) const;
/**
* Checks if the specified rectangle is free of both
* 1.) solid tiles and
* 2.) MovingObjects in COLGROUP_STATIC.
* Note that this does not include badguys or players.
*/
- bool is_free_of_statics(const Rect& rect, const MovingObject* ignore_object = 0, const bool ignoreUnisolid = false) const;
+ bool is_free_of_statics(const Rectf& rect, const MovingObject* ignore_object = 0, const bool ignoreUnisolid = false) const;
/**
* Checks if the specified rectangle is free of both
* 1.) solid tiles and
* 2.) MovingObjects in COLGROUP_STATIC, COLGROUP_MOVINGSTATIC or COLGROUP_MOVING.
* This includes badguys and players.
*/
- bool is_free_of_movingstatics(const Rect& rect, const MovingObject* ignore_object = 0) const;
+ bool is_free_of_movingstatics(const Rectf& rect, const MovingObject* ignore_object = 0) const;
/**
* returns a list of players currently in the sector
std::vector<Player*> get_players() {
return std::vector<Player*>(1, this->player);
}
+ Player *get_nearest_player (const Vector& pos);
+ Player *get_nearest_player (const Rectf& pos)
+ {
+ return (get_nearest_player (get_anchor_pos (pos, ANCHOR_MIDDLE)));
+ }
+
+ std::vector<MovingObject*> get_nearby_objects (const Vector& center, float max_distance);
- Rect get_active_region();
+ Rectf get_active_region();
+
+ int get_foremost_layer();
/**
* returns the width (in px) of a sector)
*/
void change_solid_tiles(uint32_t old_tile_id, uint32_t new_tile_id);
- typedef std::vector<GameObject*> GameObjects;
+ typedef std::vector<GameObjectPtr> GameObjects;
typedef std::vector<MovingObject*> MovingObjects;
- typedef std::vector<SpawnPoint*> SpawnPoints;
+ typedef std::vector<std::shared_ptr<SpawnPoint> > SpawnPoints;
typedef std::vector<Portable*> Portables;
- // --- Scripting ---
+ // --- scripting ---
/**
* get/set color of ambient light
*/
float get_gravity() const;
private:
- uint32_t collision_tile_attributes(const Rect& dest) const;
+ uint32_t collision_tile_attributes(const Rectf& dest) const;
- void before_object_remove(GameObject* object);
- bool before_object_add(GameObject* object);
+ void before_object_remove(GameObjectPtr object);
+ bool before_object_add(GameObjectPtr object);
- void try_expose(GameObject* object);
- void try_unexpose(GameObject* object);
+ void try_expose(GameObjectPtr object);
+ void try_unexpose(GameObjectPtr object);
void try_expose_me();
void try_unexpose_me();
* (because of ABORT_MOVE in the collision response or no collisions)
*/
void collision_static(collision::Constraints* constraints,
- const Vector& movement, const Rect& dest, GameObject& object);
+ const Vector& movement, const Rectf& dest, MovingObject& object);
void collision_static_constrains(MovingObject& object);
- GameObject* parse_object(const std::string& name, const Reader& lisp);
+ GameObjectPtr parse_object(const std::string& name, const Reader& lisp);
void fix_old_tiles();
+ int calculate_foremost_layer();
+
private:
static Sector* _current;
Color ambient_light;
+ int foremost_layer;
+
public: // TODO make this private again
/// show collision rectangles of moving objects (for debugging)
static bool show_collrects;