Building Game Engines
TileMapEditor Class Reference

This class serves as a gameobject to edit, save or load tilemaps. More...

#include <TileMapEditor.hpp>

Inheritance diagram for TileMapEditor:
Inheritance graph
Collaboration diagram for TileMapEditor:
Collaboration graph

Public Member Functions

 TileMapEditor ()=default
 Default constructor. More...
 
 ~TileMapEditor ()=default
 Default destructor. More...
 
void processInput (SDL_Event e) override
 Process user input. More...
 
void respondToInput (int mouseX, int mouseY, int clicked, int current_level)
 
void Render (SDL_Renderer *ren) override
 Render something to the active viewport. More...
 
void Update (int x, int y, int *params) override
 Update something and then call Render() function. More...
 
void SaveMap (const char *const fileName)
 Save tilemap to a local file. More...
 
void SaveEnemy (const char *const fileName)
 Save enemies data to a local file. More...
 
void LoadEnemy (const char *const fileName)
 Load enemies data from local file. More...
 
void drawRightGrids (SDL_Renderer *renderer)
 Draw right grids. More...
 
void drawLeftGrids (SDL_Renderer *renderer)
 Draw left grids. More...
 
void getCurrentPath ()
 Get current source file of the tilemap. More...
 
void addEnemy (int row, int col, int id, int HP, bool isAct)
 Add enemy into the map. More...
 
std::vector< GameObject * > getAllEnemies ()
 Get all the enemies stored in the editor. More...
 
void setPlayer (GameObject *player)
 Set the player in the editor. More...
 
void setAvailableEnemies (std::vector< GameObject * > &enemies)
 Refresh enemies stored in the editor. More...
 
- Public Member Functions inherited from GameObject
 GameObject ()
 Constructor. More...
 
 ~GameObject ()
 Destructor. More...
 
void removeComponent (std::string key)
 Remove a component in this gameobject. More...
 
void addComponent (std::string key, Component *component)
 Add a component in this gameobject. More...
 
ComponentgetComponent (std::string key)
 Get an reference of a component. More...
 
void setActive (bool newState)
 activate / deactivate game object. inactive object won't be updated and rendered More...
 
bool isActive ()
 Get the state of the game. More...
 
int getID ()
 Get the unique id of the gameobject. More...
 

Additional Inherited Members

- Static Public Attributes inherited from GameObject
static int idCounter = 0
 
- Protected Attributes inherited from GameObject
std::map< std::string, Component * > m_components
 Store all the game components in a map. More...
 
bool objState
 deactivated objects won't get updated/rendered More...
 
int id
 the unique id More...
 

Detailed Description

This class serves as a gameobject to edit, save or load tilemaps.

The properties in this class are inherited from the GameObject class and add some new functions to allow users to edit,save or load tilemaps. The left grids display all the available tiles and the right grids show the preview of the edited tilemap.

Constructor & Destructor Documentation

◆ TileMapEditor()

TileMapEditor::TileMapEditor ( )
default

Default constructor.

◆ ~TileMapEditor()

TileMapEditor::~TileMapEditor ( )
default

Default destructor.

Member Function Documentation

◆ addEnemy()

void TileMapEditor::addEnemy ( int  row,
int  col,
int  id,
int  HP,
bool  isAct 
)

Add enemy into the map.

Parameters
rowThe row number of the enemy.
colThe column number of the enemy.
idThe id of the enemy. Mainly used when switching levels or load local enemy data. -1 when add enemy by using the tile map editor.
HPThe amount of health points of this enemy.
isActWhether this enemy should be active.

◆ drawLeftGrids()

void TileMapEditor::drawLeftGrids ( SDL_Renderer *  renderer)

Draw left grids.

Parameters
rendererA structure that contains a rendering state.

◆ drawRightGrids()

void TileMapEditor::drawRightGrids ( SDL_Renderer *  renderer)

Draw right grids.

Parameters
rendererA structure that contains a rendering state.

◆ getAllEnemies()

std::vector<GameObject*> TileMapEditor::getAllEnemies ( )
inline

Get all the enemies stored in the editor.

◆ getCurrentPath()

void TileMapEditor::getCurrentPath ( )

Get current source file of the tilemap.

◆ LoadEnemy()

void TileMapEditor::LoadEnemy ( const char *const  fileName)

Load enemies data from local file.

Parameters
fileNameThe file name.

◆ processInput()

void TileMapEditor::processInput ( SDL_Event  e)
overridevirtual

Process user input.

Parameters
eA SDL_Event that contains structures for the different event types.

Reimplemented from GameObject.

◆ Render()

void TileMapEditor::Render ( SDL_Renderer *  ren)
overridevirtual

Render something to the active viewport.

Parameters
renReference to SDL renderer.

Reimplemented from GameObject.

◆ respondToInput()

void TileMapEditor::respondToInput ( int  mouseX,
int  mouseY,
int  clicked,
int  current_level 
)

◆ SaveEnemy()

void TileMapEditor::SaveEnemy ( const char *const  fileName)

Save enemies data to a local file.

Parameters
fileNameThe file name.

◆ SaveMap()

void TileMapEditor::SaveMap ( const char *const  fileName)

Save tilemap to a local file.

Parameters
fileNameThe file name of the edited tilemap.

◆ setAvailableEnemies()

void TileMapEditor::setAvailableEnemies ( std::vector< GameObject * > &  enemies)
inline

Refresh enemies stored in the editor.

Parameters
enemiesThe new gameobject vector contains all the enemies.

◆ setPlayer()

void TileMapEditor::setPlayer ( GameObject player)
inline

Set the player in the editor.

Parameters
playerNew player object.

◆ Update()

void TileMapEditor::Update ( int  x,
int  y,
int *  params 
)
overridevirtual

Update something and then call Render() function.

Parameters
xAn int variable.
yAn int variable.
paramsA dynamic array to store multiple int values.

Reimplemented from GameObject.