supertux
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
TileMap Class Referencefinal

This class is responsible for managing an array of tiles. More...

#include <tilemap.hpp>

Inheritance diagram for TileMap:
Inheritance graph
[legend]
Collaboration diagram for TileMap:
Collaboration graph
[legend]

Public Types

enum  AutotileCornerOperation {
  ADD_TOP_LEFT, ADD_TOP_RIGHT, ADD_BOTTOM_LEFT, ADD_BOTTOM_RIGHT,
  REMOVE_TOP_LEFT, REMOVE_TOP_RIGHT, REMOVE_BOTTOM_LEFT, REMOVE_BOTTOM_RIGHT
}
 

Public Member Functions

 TileMap (const TileSet *tileset)
 
 TileMap (const TileSet *tileset, const ReaderMapping &reader)
 
virtual void finish_construction () override
 Called after all objects have been added to the Sector and the Sector is fully constructed. More...
 
virtual std::string get_class_name () const override
 
virtual std::string get_exposed_class_name () const override
 
virtual const std::string get_icon_path () const override
 
virtual std::string get_display_name () const override
 Returns the display name of the object, translated to the user's locale.
 
virtual GameObjectClasses get_class_types () const override
 List notable classes in inheritance hierarchy of class. More...
 
virtual ObjectSettings get_settings () override
 
virtual void after_editor_set () override
 
void save_state () override
 Save/check the current state of the object. More...
 
void check_state () override
 
virtual void update (float dt_sec) override
 This function is called once per frame and allows the object to update it's state. More...
 
virtual void draw (DrawingContext &context) override
 The GameObject should draw itself onto the provided DrawingContext if this function is called. More...
 
virtual void editor_update () override
 Called each frame in the editor, used to keep linked objects together (e.g. More...
 
virtual void on_flip (float height) override
 When level is flipped vertically.
 
void set (int width, int height, const std::vector< unsigned int > &vec, int z_pos, bool solid)
 
void resize (int newwidth, int newheight, int fill_id=0, int xoffset=0, int yoffset=0)
 resizes the tilemap to a new width and height (tries to not destroy the existing map)
 
void resize (const Size &newsize, const Size &resize_offset)
 
int get_width () const
 
int get_height () const
 
Size get_size () const
 
void set_offset (const Vector &offset_)
 
Vector get_offset () const
 
void set_ground_movement_manager (const std::shared_ptr< CollisionGroundMovementManager > &movement_manager)
 
void move_by (const Vector &pos)
 
Vector get_movement (bool actual) const
 Get the movement of this tilemap. More...
 
Vector get_tile_position (int x, int y) const
 Returns the position of the upper-left corner of tile (x, y) in the sector. More...
 
Rectf get_bbox () const
 
Rectf get_tile_bbox (int x, int y) const
 
Rect get_tiles_overlapping (const Rectf &rect) const
 Returns the half-open rectangle of (x, y) tile indices that overlap the given rectangle in the sector. More...
 
void hits_object_bottom (CollisionObject &object)
 Called by the collision mechanism to indicate that this tilemap has been hit on the top, i.e. More...
 
void notify_object_removal (CollisionObject *other)
 
int get_layer () const
 
void set_layer (int layer)
 
bool is_solid () const
 
void set_solid (bool solid=true)
 Switches the tilemap's real solidity to ""solid"". More...
 
bool is_outside_bounds (const Vector &pos) const
 
const Tileget_tile (int x, int y) const
 
const Tileget_tile_at (const Vector &pos) const
 
uint32_t get_tile_id (int x, int y) const
 Returns the ID of the tile at the given coordinates or 0 if out of bounds. More...
 
uint32_t get_tile_id_at (float x, float y) const
 Returns the ID of the tile at the given position (in world coordinates). More...
 
uint32_t get_tile_id_at (const Vector &pos) const
 
void change (int x, int y, uint32_t newtile)
 Changes the tile at the given coordinates to ""newtile"". More...
 
void change_at (float x, float y, uint32_t newtile)
 Changes the tile at the given position (in-world coordinates) to ""newtile"". More...
 
void change_at (const Vector &pos, uint32_t newtile)
 
void change_all (uint32_t oldtile, uint32_t newtile)
 Changes all tiles with the given ID. More...
 
void autotile (int x, int y, uint32_t tile)
 Puts the correct autotile block at the given position.
 
void autotile_corner (int x, int y, uint32_t tile, AutotileCornerOperation op)
 Puts the correct autotile blocks at the tiles around the given corner.
 
void autotile_erase (const Vector &pos, const Vector &corner_pos)
 Erases in autotile mode.
 
AutotileSetget_autotileset (uint32_t tile) const
 Returns the Autotileset associated with the given tile.
 
void set_flip (Flip flip)
 
Flip get_flip () const
 
void fade (float alpha, float time)
 Starts fading the tilemap to the opacity given by ""alpha"". More...
 
void tint_fade (const Color &new_tint, float time=0.f)
 Start fading the tilemap to tint given by RGBA. More...
 
void tint_fade (float time, float red, float green, float blue, float alpha)
 Starts fading the tilemap to tint given by RGBA. More...
 
Color get_current_tint () const
 
void set_alpha (float alpha)
 Instantly switches the tilemap's opacity to ""alpha"". More...
 
float get_alpha () const
 Returns the tilemap's opacity. More...
 
float get_target_alpha () const
 
void set_tileset (const TileSet *new_tileset)
 
const std::vector< uint32_t > & get_tiles () const
 
- Public Member Functions inherited from GameObject
 GameObject (const std::string &name)
 
 GameObject (const ReaderMapping &reader)
 
UID get_uid () const
 
virtual void save (Writer &writer)
 This function saves the object. More...
 
std::string save ()
 
virtual std::vector< std::string > get_patches () const
 Version checking/updating, patch information.
 
virtual void update_version ()
 
int get_version () const
 Returns the current version of the object.
 
int get_latest_version () const
 Returns the latest version of the object.
 
bool is_up_to_date () const
 Checks whether the object's current version is equal to its latest one.
 
virtual bool is_singleton () const
 If true only a single object of this type is allowed in a given GameObjectManager.
 
virtual bool has_variable_size () const
 Does this object have variable size (secret area trigger, wind, etc.)
 
virtual bool is_saveable () const
 Indicates if the object will be saved. More...
 
virtual bool track_state () const
 Indicates if the object's state should be tracked. More...
 
virtual bool has_object_manager_priority () const
 Indicates if the object should be added at the beginning of the object list. More...
 
virtual bool has_settings () const
 Indicates if get_settings() is implemented. More...
 
virtual GameObjectTypes get_types () const
 Get all types of the object, if available. More...
 
int get_type () const
 Returns the type index of the object.
 
virtual void remove_me ()
 schedules this object to be removed at the end of the frame
 
bool is_valid () const
 returns true if the object is not scheduled to be removed yet
 
void add_remove_listener (ObjectRemoveListener *listener)
 registers a remove listener which will be called if the object gets removed/destroyed
 
void del_remove_listener (ObjectRemoveListener *listener)
 unregisters a remove listener, so it will no longer be called if the object gets removed/destroyed
 
void set_name (const std::string &name)
 
const std::string & get_name () const
 Returns the name of the object.
 
virtual void stop_looping_sounds ()
 stops all looping sounds
 
virtual void play_looping_sounds ()
 continues all looping sounds
 
template<typename T >
T * get_component ()
 
void add_component (std::unique_ptr< GameObjectComponent > component)
 
void remove_component (GameObjectComponent *component)
 
virtual void editor_delete ()
 The editor requested the deletion of the object.
 
virtual void editor_select ()
 The user clicked on the object in the editor and selected it.
 
virtual void editor_deselect ()
 The object got deselected.
 
GameObjectManagerget_parent () const
 
- Public Member Functions inherited from PathObject
void init_path (const ReaderMapping &mapping, bool running_default)
 For compatibilty reasons this needs to get the GameObjects main mapping, not the (path ...) mapping.
 
void init_path_pos (const Vector &pos, bool running=false)
 
PathGameObjectget_path_gameobject () const
 
Pathget_path () const
 
PathWalkerget_walker () const
 
void editor_clone_path (PathGameObject *path_object)
 
std::string get_path_ref () const
 
void editor_set_path_by_ref (const std::string &new_ref)
 
void goto_node (int node_idx)
 Moves the path object until at given node, then stops. More...
 
void set_node (int node_idx)
 Jumps instantly to the given node. More...
 
void start_moving ()
 Starts moving the path object automatically.
 
void stop_moving ()
 Stops moving the path object.
 

Static Public Member Functions

static void register_class (ssq::VM &vm)
 
static std::string class_name ()
 
static std::string display_name ()
 
- Static Public Member Functions inherited from GameObject
static void register_class (ssq::VM &vm)
 

Public Attributes

bool m_editor_active
 

Additional Inherited Members

- Protected Types inherited from GameObject
enum  TypeChange { INITIAL = -1 }
 When the type has been changed from the editor. More...
 
- Protected Member Functions inherited from GameObject
void parse_type (const ReaderMapping &reader)
 Parse object type. More...
 
virtual void on_type_change (int old_type)
 
int type_id_to_value (const std::string &id) const
 Conversion between type ID and value. More...
 
std::string type_value_to_id (int value) const
 
- Protected Member Functions inherited from PathObject
void save_state () const
 
void check_state () const
 
void on_flip ()
 
- Static Protected Member Functions inherited from PathObject
static void register_members (ssq::Class &cls)
 
- Protected Attributes inherited from GameObject
std::string m_name
 a name for the gameobject, this is mostly a hint for scripts and for debugging, don't rely on names being set or being unique
 
int m_type
 Type of the GameObject. More...
 
std::vector< std::unique_ptr< FadeHelper > > m_fade_helpers
 Fade Helpers are for easing/fading script functions.
 
bool m_track_undo
 Track the following creation/deletion of this object for undo. More...
 
- Protected Attributes inherited from PathObject
PathWalker::Handle m_path_handle
 

Detailed Description

This class is responsible for managing an array of tiles.

A ""TileMap"" that was given a name can be controlled by scripts. The tilemap can be moved by specifying a path for it. A ""TileMap"" is instantiated by placing a definition inside a level. It can then be accessed by its name from a script or via ""sector.name"" from the console.

Member Function Documentation

◆ change()

void TileMap::change ( int  x,
int  y,
uint32_t  newtile 
)

Changes the tile at the given coordinates to ""newtile"".

The origin is at the top left.

Parameters
int$x
int$y
int$newtile

◆ change_all()

void TileMap::change_all ( uint32_t  oldtile,
uint32_t  newtile 
)

Changes all tiles with the given ID.

Parameters
int$oldtile
int$newtile

◆ change_at()

void TileMap::change_at ( float  x,
float  y,
uint32_t  newtile 
)

Changes the tile at the given position (in-world coordinates) to ""newtile"".

Parameters
float$x
float$y
int$newtile

◆ draw()

void TileMap::draw ( DrawingContext context)
overridevirtual

The GameObject should draw itself onto the provided DrawingContext if this function is called.

Implements GameObject.

◆ editor_update()

void TileMap::editor_update ( )
overridevirtual

Called each frame in the editor, used to keep linked objects together (e.g.

platform on a path)

Reimplemented from GameObject.

◆ fade()

void TileMap::fade ( float  alpha,
float  time 
)

Starts fading the tilemap to the opacity given by ""alpha"".

Destination opacity will be reached after ""time"" seconds. Also influences solidity.

Parameters
float$alpha
float$time

◆ finish_construction()

void TileMap::finish_construction ( )
overridevirtual

Called after all objects have been added to the Sector and the Sector is fully constructed.

If objects refer to other objects by name, those connection can be resolved here.

Reimplemented from GameObject.

◆ get_alpha()

float TileMap::get_alpha ( ) const

Returns the tilemap's opacity.

${SRG_TABLENEWPARAGRAPH} Note: While the tilemap is fading in or out, this will return the current alpha value, not the target alpha.

◆ get_class_types()

virtual GameObjectClasses TileMap::get_class_types ( ) const
inlineoverridevirtual

List notable classes in inheritance hierarchy of class.

This makes it possible to efficiently look up all objects deriving from a particular intermediate class

Reimplemented from GameObject.

◆ get_movement()

Vector TileMap::get_movement ( bool  actual) const
inline

Get the movement of this tilemap.

The collision detection code may need a non-negative y-movement. Passing `false' as the `actual' argument will provide that. Used exclusively in src/supertux/sector.cpp.

◆ get_tile_id()

uint32_t TileMap::get_tile_id ( int  x,
int  y 
) const

Returns the ID of the tile at the given coordinates or 0 if out of bounds.

The origin is at the top left.

Parameters
int$x
int$y

◆ get_tile_id_at()

uint32_t TileMap::get_tile_id_at ( float  x,
float  y 
) const

Returns the ID of the tile at the given position (in world coordinates).

Parameters
float$x
float$y

◆ get_tile_position()

Vector TileMap::get_tile_position ( int  x,
int  y 
) const
inline

Returns the position of the upper-left corner of tile (x, y) in the sector.

◆ get_tiles_overlapping()

Rect TileMap::get_tiles_overlapping ( const Rectf rect) const

Returns the half-open rectangle of (x, y) tile indices that overlap the given rectangle in the sector.

◆ hits_object_bottom()

void TileMap::hits_object_bottom ( CollisionObject object)

Called by the collision mechanism to indicate that this tilemap has been hit on the top, i.e.

has hit a moving object on the bottom of its collision rectangle.

◆ save_state()

void TileMap::save_state ( )
overridevirtual

Save/check the current state of the object.

Reimplemented from GameObject.

◆ set_alpha()

void TileMap::set_alpha ( float  alpha)

Instantly switches the tilemap's opacity to ""alpha"".

Also influences solidity.

Parameters
float$alpha

◆ set_solid()

void TileMap::set_solid ( bool  solid = true)

Switches the tilemap's real solidity to ""solid"".

${SRG_TABLENEWPARAGRAPH} Note: The effective solidity is also influenced by the alpha of the tilemap.

Parameters
bool$solid

◆ tint_fade() [1/2]

void TileMap::tint_fade ( const Color new_tint,
float  time = 0.f 
)

Start fading the tilemap to tint given by RGBA.

Destination opacity will be reached after seconds seconds. Doesn't influence solidity.

◆ tint_fade() [2/2]

void TileMap::tint_fade ( float  time,
float  red,
float  green,
float  blue,
float  alpha 
)

Starts fading the tilemap to tint given by RGBA.

Destination opacity will be reached after ""time"" seconds. Doesn't influence solidity.

Parameters
float$time
float$red
float$green
float$blue
float$alpha

◆ update()

void TileMap::update ( float  dt_sec)
overridevirtual

This function is called once per frame and allows the object to update it's state.

The dt_sec is the time that has passed since the last frame in seconds and should be the base for all timed calculations (don't use SDL_GetTicks directly as this will fail in pause mode). This function is not called in the Editor.

Implements GameObject.


The documentation for this class was generated from the following files: