Mana
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes | Friends | List of all members
Map Class Reference

A tile map. More...

#include <map.h>

Inheritance diagram for Map:
Properties

Classes

struct  ParticleEffectData
 

Public Types

enum  BlockType {
  BLOCKTYPE_NONE = -1 , BLOCKTYPE_WALL , BLOCKTYPE_CHARACTER , BLOCKTYPE_MONSTER ,
  NB_BLOCKTYPES
}
 
enum  BlockMask { BLOCKMASK_WALL = 0x80 , BLOCKMASK_CHARACTER = 0x01 , BLOCKMASK_MONSTER = 0x02 , BLOCKMASK_ALL = 0xFF }
 
enum  DebugFlags {
  DEBUG_NONE = 0x0 , DEBUG_GRID = 0x1 , DEBUG_COLLISION_TILES = 0x2 , DEBUG_BEING_COLLISION_RADIUS = 0x4 ,
  DEBUG_BEING_POSITION = 0x8 , DEBUG_BEING_PATH = 0x10 , DEBUG_MOUSE_PATH = 0x20 , DEBUG_BEING_IDS = 0x40 ,
  DEBUG_SPECIAL1 = 0x80 , DEBUG_SPECIAL2 = 0x100 , DEBUG_SPECIAL3 = 0x200
}
 

Public Member Functions

 Map (int width, int height, int tileWidth, int tileHeight)
 Constructor, taking map and tile size as parameters.
 
 ~Map () override
 
void initializeAmbientLayers ()
 Initialize ambient layers.
 
void update (int dt)
 Updates animations.
 
void draw (Graphics *graphics, int scrollX, int scrollY)
 Draws the map to the given graphics output.
 
void drawCollision (Graphics *graphics, int scrollX, int scrollY, int debugFlags) const
 Visualizes collision layer for debugging.
 
void addLayer (MapLayer *layer)
 Adds a layer to this map.
 
void addTileset (Tileset *tileset)
 Adds a tileset to this map.
 
TilesetgetTilesetWithGid (unsigned gid) const
 Finds the tile set that a tile with the given global id is part of.
 
MetaTilegetMetaTile (int x, int y) const
 Get tile reference.
 
void blockTile (int x, int y, BlockType type)
 Marks a tile as occupied.
 
bool getWalk (int x, int y, unsigned char walkmask=BLOCKMASK_WALL) const
 Gets walkability for a tile with a blocking bitmask.
 
bool occupied (int x, int y) const
 Tells whether a tile is occupied by a being.
 
int getWidth () const
 Returns the width of this map in tiles.
 
int getHeight () const
 Returns the height of this map in tiles.
 
int getTileWidth () const
 Returns the tile width of this map.
 
int getTileHeight () const
 Returns the tile height used by this map.
 
Vector getTileCenter (int x, int y) const
 Returns the tile center position in pixel coordinates.
 
std::string getMusicFile () const
 
std::string getName () const
 
std::string getFilename () const
 Gives the map id based on filepath (ex: 009-1)
 
Position checkNodeOffsets (int radius, unsigned char walkMask, const Position &position) const
 Check the current position against surrounding blocking tiles, and correct the position offset within tile when needed.
 
Position checkNodeOffsets (int radius, unsigned char walkMask, int x, int y) const
 
Path findTilePath (int startPixelX, int startPixelY, int endPixelX, int endPixelY, unsigned char walkMask, int maxCost=20)
 Find a tile-centered path in pixel coordinates from one location to the next.
 
Path findPixelPath (int startPixelX, int startPixelY, int destPixelX, int destPixelY, int radius, unsigned char walkmask, int maxCost=20)
 Find a pixel path from one location to the next using free offsets.
 
void addParticleEffect (const std::string &effectFile, int x, int y, int w=0, int h=0)
 Adds a particle effect.
 
void initializeParticleEffects (Particle *particleEngine)
 Initializes all added particle effects.
 
void addAnimation (int gid, TileAnimation animation)
 Adds a tile animation to the map.
 
void setDebugFlags (int flags)
 
int getDebugFlags () const
 
TileAnimationgetAnimationForGid (int gid)
 Gets the tile animation for a specific gid.
 
void setMask (int mask)
 
- Public Member Functions inherited from Properties
virtual ~Properties ()=default
 
std::string getProperty (const std::string &name, const std::string &def=std::string()) const
 Get a map property.
 
float getFloatProperty (const std::string &name, float def=0.0f) const
 Gets a map property as a float.
 
float getIntProperty (const std::string &name, int def=0) const
 Gets a map property as an int.
 
bool getBoolProperty (const std::string &name, bool def=false) const
 Gets a map property as a boolean.
 
bool hasProperty (const std::string &name) const
 Returns whether a certain property is available.
 
void setProperty (const std::string &name, const std::string &value)
 Set a map property.
 

Protected Member Functions

Actors::iterator addActor (Actor *actor)
 Adds an actor to the map.
 
void removeActor (Actors::iterator iterator)
 Removes an actor from the map.
 

Private Types

enum  LayerType { FOREGROUND_LAYERS , BACKGROUND_LAYERS }
 

Private Member Functions

Path findPath (int startX, int startY, int destX, int destY, unsigned char walkmask, int maxCost=20)
 Find a path from one location to the next in tile coordinates.
 
void updateAmbientLayers (float scrollX, float scrollY)
 Updates scrolling of ambient layers.
 
void drawAmbientLayers (Graphics *graphics, LayerType type, float scrollX, float scrollY, int detail)
 Draws the foreground or background layers to the given graphics output.
 
bool contains (int x, int y) const
 Tells whether the given coordinates fall within the map boundaries.
 

Private Attributes

unsigned * mOccupation [NB_BLOCKTYPES]
 Blockmasks for different entities.
 
int mWidth
 
int mHeight
 
int mTileWidth
 
int mTileHeight
 
int mMaxTileHeight
 
int mMaxTileWidth
 
MetaTilemMetaTiles
 
std::vector< MapLayer * > mLayers
 
std::vector< Tileset * > mTilesets
 
Actors mActors
 
int mDebugFlags
 
unsigned mOnClosedList
 
unsigned mOnOpenList
 
std::vector< AmbientLayermBackgrounds
 
std::vector< AmbientLayermForegrounds
 
float mLastScrollX
 
float mLastScrollY
 
std::list< ParticleEffectDataparticleEffects
 
std::map< int, TileAnimationmTileAnimations
 
int mMask = 1
 

Friends

class Actor
 

Detailed Description

A tile map.

Definition at line 146 of file map.h.

Member Enumeration Documentation

◆ BlockMask

Enumerator
BLOCKMASK_WALL 
BLOCKMASK_CHARACTER 
BLOCKMASK_MONSTER 
BLOCKMASK_ALL 

Definition at line 158 of file map.h.

◆ BlockType

Enumerator
BLOCKTYPE_NONE 
BLOCKTYPE_WALL 
BLOCKTYPE_CHARACTER 
BLOCKTYPE_MONSTER 
NB_BLOCKTYPES 

Definition at line 149 of file map.h.

◆ DebugFlags

Enumerator
DEBUG_NONE 
DEBUG_GRID 
DEBUG_COLLISION_TILES 
DEBUG_BEING_COLLISION_RADIUS 
DEBUG_BEING_POSITION 
DEBUG_BEING_PATH 
DEBUG_MOUSE_PATH 
DEBUG_BEING_IDS 
DEBUG_SPECIAL1 
DEBUG_SPECIAL2 
DEBUG_SPECIAL3 

Definition at line 166 of file map.h.

◆ LayerType

enum Map::LayerType
private
Enumerator
FOREGROUND_LAYERS 
BACKGROUND_LAYERS 

Definition at line 361 of file map.h.

Constructor & Destructor Documentation

◆ Map()

Map::Map ( int  width,
int  height,
int  tileWidth,
int  tileHeight 
)

Constructor, taking map and tile size as parameters.

Definition at line 210 of file map.cpp.

◆ ~Map()

Map::~Map ( )
override

Definition at line 229 of file map.cpp.

Member Function Documentation

◆ addActor()

Actors::iterator Map::addActor ( Actor actor)
protected

Adds an actor to the map.

Definition at line 582 of file map.cpp.

◆ addAnimation()

void Map::addAnimation ( int  gid,
TileAnimation  animation 
)

Adds a tile animation to the map.

Definition at line 982 of file map.cpp.

◆ addLayer()

void Map::addLayer ( MapLayer layer)

Adds a layer to this map.

The map takes ownership of the layer.

Definition at line 284 of file map.cpp.

◆ addParticleEffect()

void Map::addParticleEffect ( const std::string &  effectFile,
int  x,
int  y,
int  w = 0,
int  h = 0 
)

Adds a particle effect.

Definition at line 953 of file map.cpp.

◆ addTileset()

void Map::addTileset ( Tileset tileset)

Adds a tileset to this map.

The map takes ownership of the tileset.

Definition at line 289 of file map.cpp.

◆ blockTile()

void Map::blockTile ( int  x,
int  y,
BlockType  type 
)

Marks a tile as occupied.

Definition at line 513 of file map.cpp.

◆ checkNodeOffsets() [1/2]

Position Map::checkNodeOffsets ( int  radius,
unsigned char  walkMask,
const Position position 
) const

Check the current position against surrounding blocking tiles, and correct the position offset within tile when needed.

Definition at line 615 of file map.cpp.

◆ checkNodeOffsets() [2/2]

Position Map::checkNodeOffsets ( int  radius,
unsigned char  walkMask,
int  x,
int  y 
) const
inline

Definition at line 296 of file map.h.

◆ contains()

bool Map::contains ( int  x,
int  y 
) const
private

Tells whether the given coordinates fall within the map boundaries.

Definition at line 572 of file map.cpp.

◆ draw()

void Map::draw ( Graphics graphics,
int  scrollX,
int  scrollY 
)

Draws the map to the given graphics output.

This method draws all layers, actors and overlay effects.

TODO: For efficiency reasons, this method could take into account the clipping rectangle set on the Graphics object. However, currently the map is always drawn full-screen.

Definition at line 308 of file map.cpp.

◆ drawAmbientLayers()

void Map::drawAmbientLayers ( Graphics graphics,
LayerType  type,
float  scrollX,
float  scrollY,
int  detail 
)
private

Draws the foreground or background layers to the given graphics output.

Definition at line 463 of file map.cpp.

◆ drawCollision()

void Map::drawCollision ( Graphics graphics,
int  scrollX,
int  scrollY,
int  debugFlags 
) const

Visualizes collision layer for debugging.

Definition at line 371 of file map.cpp.

◆ findPath()

Path Map::findPath ( int  startX,
int  startY,
int  destX,
int  destY,
unsigned char  walkmask,
int  maxCost = 20 
)
private

Find a path from one location to the next in tile coordinates.

Definition at line 750 of file map.cpp.

◆ findPixelPath()

Path Map::findPixelPath ( int  startPixelX,
int  startPixelY,
int  destPixelX,
int  destPixelY,
int  radius,
unsigned char  walkmask,
int  maxCost = 20 
)

Find a pixel path from one location to the next using free offsets.

Definition at line 700 of file map.cpp.

◆ findTilePath()

Path Map::findTilePath ( int  startPixelX,
int  startPixelY,
int  endPixelX,
int  endPixelY,
unsigned char  walkMask,
int  maxCost = 20 
)

Find a tile-centered path in pixel coordinates from one location to the next.

Definition at line 676 of file map.cpp.

◆ getAnimationForGid()

TileAnimation * Map::getAnimationForGid ( int  gid)

Gets the tile animation for a specific gid.

Definition at line 991 of file map.cpp.

◆ getDebugFlags()

int Map::getDebugFlags ( ) const
inline

Definition at line 332 of file map.h.

◆ getFilename()

std::string Map::getFilename ( ) const

Gives the map id based on filepath (ex: 009-1)

Definition at line 606 of file map.cpp.

◆ getHeight()

int Map::getHeight ( ) const
inline

Returns the height of this map in tiles.

Definition at line 260 of file map.h.

◆ getMetaTile()

MetaTile * Map::getMetaTile ( int  x,
int  y 
) const

Get tile reference.

Definition at line 577 of file map.cpp.

◆ getMusicFile()

std::string Map::getMusicFile ( ) const

Definition at line 593 of file map.cpp.

◆ getName()

std::string Map::getName ( ) const

Definition at line 598 of file map.cpp.

◆ getTileCenter()

Vector Map::getTileCenter ( int  x,
int  y 
) const

Returns the tile center position in pixel coordinates.

Parameters
xthe horizontal tile position
ythe vertical tile position

Definition at line 563 of file map.cpp.

◆ getTileHeight()

int Map::getTileHeight ( ) const
inline

Returns the tile height used by this map.

Definition at line 271 of file map.h.

◆ getTilesetWithGid()

Tileset * Map::getTilesetWithGid ( unsigned  gid) const

Finds the tile set that a tile with the given global id is part of.

Definition at line 500 of file map.cpp.

◆ getTileWidth()

int Map::getTileWidth ( ) const
inline

Returns the tile width of this map.

Definition at line 265 of file map.h.

◆ getWalk()

bool Map::getWalk ( int  x,
int  y,
unsigned char  walkmask = BLOCKMASK_WALL 
) const

Gets walkability for a tile with a blocking bitmask.

When called without walkmask, only blocks against colliding tiles.

Definition at line 541 of file map.cpp.

◆ getWidth()

int Map::getWidth ( ) const
inline

Returns the width of this map in tiles.

Definition at line 255 of file map.h.

◆ initializeAmbientLayers()

void Map::initializeAmbientLayers ( )

Initialize ambient layers.

Has to be called after all the properties are set.

Definition at line 241 of file map.cpp.

◆ initializeParticleEffects()

void Map::initializeParticleEffects ( Particle particleEngine)

Initializes all added particle effects.

Definition at line 964 of file map.cpp.

◆ occupied()

bool Map::occupied ( int  x,
int  y 
) const

Tells whether a tile is occupied by a being.

Definition at line 551 of file map.cpp.

◆ removeActor()

void Map::removeActor ( Actors::iterator  iterator)
protected

Removes an actor from the map.

Definition at line 588 of file map.cpp.

◆ setDebugFlags()

void Map::setDebugFlags ( int  flags)
inline

Definition at line 330 of file map.h.

◆ setMask()

void Map::setMask ( int  mask)

Definition at line 997 of file map.cpp.

◆ update()

void Map::update ( int  dt)

Updates animations.

Called as needed.

Definition at line 299 of file map.cpp.

◆ updateAmbientLayers()

void Map::updateAmbientLayers ( float  scrollX,
float  scrollY 
)
private

Updates scrolling of ambient layers.

Has to be called each game tick.

Definition at line 432 of file map.cpp.

Friends And Related Symbol Documentation

◆ Actor

friend class Actor
friend

Definition at line 342 of file map.h.

Member Data Documentation

◆ mActors

Actors Map::mActors
private

Definition at line 394 of file map.h.

◆ mBackgrounds

std::vector<AmbientLayer> Map::mBackgrounds
private

Definition at line 403 of file map.h.

◆ mDebugFlags

int Map::mDebugFlags
private

Definition at line 397 of file map.h.

◆ mForegrounds

std::vector<AmbientLayer> Map::mForegrounds
private

Definition at line 404 of file map.h.

◆ mHeight

int Map::mHeight
private

Definition at line 388 of file map.h.

◆ mLastScrollX

float Map::mLastScrollX
private

Definition at line 405 of file map.h.

◆ mLastScrollY

float Map::mLastScrollY
private

Definition at line 406 of file map.h.

◆ mLayers

std::vector<MapLayer *> Map::mLayers
private

Definition at line 392 of file map.h.

◆ mMask

int Map::mMask = 1
private

Definition at line 421 of file map.h.

◆ mMaxTileHeight

int Map::mMaxTileHeight
private

Definition at line 390 of file map.h.

◆ mMaxTileWidth

int Map::mMaxTileWidth
private

Definition at line 390 of file map.h.

◆ mMetaTiles

MetaTile* Map::mMetaTiles
private

Definition at line 391 of file map.h.

◆ mOccupation

unsigned* Map::mOccupation[NB_BLOCKTYPES]
private

Blockmasks for different entities.

Definition at line 386 of file map.h.

◆ mOnClosedList

unsigned Map::mOnClosedList
private

Definition at line 400 of file map.h.

◆ mOnOpenList

unsigned Map::mOnOpenList
private

Definition at line 400 of file map.h.

◆ mTileAnimations

std::map<int, TileAnimation> Map::mTileAnimations
private

Definition at line 419 of file map.h.

◆ mTileHeight

int Map::mTileHeight
private

Definition at line 389 of file map.h.

◆ mTilesets

std::vector<Tileset *> Map::mTilesets
private

Definition at line 393 of file map.h.

◆ mTileWidth

int Map::mTileWidth
private

Definition at line 389 of file map.h.

◆ mWidth

int Map::mWidth
private

Definition at line 388 of file map.h.

◆ particleEffects

std::list<ParticleEffectData> Map::particleEffects
private

Definition at line 417 of file map.h.


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