Skip to content
Snippets Groups Projects
Commit c86fc842 authored by Rachel Wil Sha Singh's avatar Rachel Wil Sha Singh :speech_balloon:
Browse files

Convering TMX data to terrain in map. Need to do object layer

parent 1bee318e
Branches
No related tags found
No related merge requests found
Pipeline #561609130 passed with warnings
Showing
with 468 additions and 102 deletions
design/tiled-levels/sheet-terrain.png

3.01 KiB | W: | H:

design/tiled-levels/sheet-terrain.png

4.15 KiB | W: | H:

design/tiled-levels/sheet-terrain.png
design/tiled-levels/sheet-terrain.png
design/tiled-levels/sheet-terrain.png
design/tiled-levels/sheet-terrain.png
  • 2-up
  • Swipe
  • Onion skin
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.2" tiledversion="1.3.2" orientation="orthogonal" renderorder="right-down" compressionlevel="-1" width="20" height="12" tilewidth="20" tileheight="20" infinite="0" nextlayerid="6" nextobjectid="1">
<map version="1.2" tiledversion="1.3.2" orientation="orthogonal" renderorder="right-down" compressionlevel="0" width="20" height="12" tilewidth="20" tileheight="20" infinite="0" nextlayerid="6" nextobjectid="1">
<tileset firstgid="1" source="sheet-terrain.tsx"/>
<tileset firstgid="193" source="sheet-objects.tsx"/>
<layer id="1" name="FLOOR-LAYER" width="20" height="12">
<layer id="1" name="FLOOR" width="20" height="12">
<data encoding="csv">
13,13,17,14,14,17,15,15,17,16,16,17,17,17,17,17,17,17,17,17,
13,13,17,14,14,17,15,15,17,16,16,17,17,17,17,17,17,17,17,17,
17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
66,66,17,42,42,17,56,56,17,68,68,17,17,17,17,17,17,17,17,17,
66,66,17,42,42,17,56,56,17,68,68,17,17,17,17,17,17,17,17,17,
17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
114,114,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
114,114,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
17,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,
17,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,
17,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,
17,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,
17,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,
17,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,
17,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,
17,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,
17,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,
17,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,
17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17
</data>
</layer>
<layer id="2" name="MIDDLE-LAYER1" width="20" height="12">
<layer id="2" name="WALL" width="20" height="12">
<data encoding="csv">
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,66,66,66,66,66,66,66,66,66,66,66,66,56,66,66,66,66,66,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,114,114,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,114,114,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
</data>
</layer>
<layer id="3" name="MIDDLE-LAYER2" width="20" height="12">
<layer id="3" name="DECOR" width="20" height="12">
<data encoding="csv">
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,21,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,114,114,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,114,114,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
</data>
</layer>
<layer id="4" name="OBJECT-LAYER" width="20" height="12">
<layer id="4" name="OBJECT" width="20" height="12" visible="0">
<data encoding="csv">
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,215,0,0,0,0,0,0,0,0,
......
......@@ -217,7 +217,7 @@ void MapEditorState::HandleClick_TileMenu( const sf::Vector2f& mousePos )
{
Logger::StackPush( s_className + "::" + __func__ );
Tile tileInfo;
ChaloTile tileInfo;
bool result = false;
if ( m_terrainTileset.TileClicked( mousePos, tileInfo ) )
......
......@@ -33,7 +33,7 @@ private:
RawrMap m_map;
Tile m_brush;
ChaloTile m_brush;
BrushType m_brushType;
ViewState m_viewState;
......
......@@ -465,7 +465,7 @@ void RawrMap::Load( const std::string& filename, bool mapEditor /*= false*/ )
Logger::StackPop();
}
void RawrMap::Editor_Click( const sf::Vector2f& mousePos, BrushType brushType, Tile& brush )
void RawrMap::Editor_Click( const sf::Vector2f& mousePos, BrushType brushType, ChaloTile& brush )
{
Logger::StackPush( s_className + "::" + __func__ );
......
#ifndef _RAWRMAP_HPP
#define _RAWRMAP_HPP
#include "Tile.hpp"
#include "ChaloTile.hpp"
#include "Enums.hpp"
#include "Object.hpp"
......@@ -29,12 +29,12 @@ public:
sf::Vector2f GetPositionFromIndices( sf::Vector2i tileIndices );
bool PushObject( sf::Vector2i pusherPosition, sf::Vector2i objectPosition );
void Editor_Click( const sf::Vector2f& mousePos, BrushType brushType, Tile& brush );
void Editor_Click( const sf::Vector2f& mousePos, BrushType brushType, ChaloTile& brush );
private:
Tile m_floor[20][12];
Tile m_terrainArray[20][12];
Tile m_itemArray[20][12];
ChaloTile m_floor[20][12];
ChaloTile m_terrainArray[20][12];
ChaloTile m_itemArray[20][12];
std::string m_name;
// TODO: Move player into this class
......
File moved
......@@ -4,10 +4,10 @@
#include <SFML/Graphics.hpp>
#include <string>
struct Tile
struct ChaloTile
{
public:
Tile& operator=( Tile other );
ChaloTile& operator=( ChaloTile other );
void SetFrameRect( sf::IntRect frameRect );
void SetFrameRectDimensions( int width, int height );
......
......@@ -30,7 +30,7 @@ void Tileset::LoadTileset( std::string tilesetSpecFile, std::string tilesetName,
std::string debugFileInfo = "";
for ( size_t row = 0; row < doc.rows.size(); row++ )
{
Tile newTile;
ChaloTile newTile;
newTile.SetDimensions( sf::IntRect( 0, 0, TILE_WIDTH, TILE_HEIGHT ) );
newTile.SetFrameRectDimensions( TILE_WIDTH, TILE_HEIGHT );
newTile.SetTexture( chalo::TextureManager::Get( tilesetName ) );
......@@ -73,7 +73,7 @@ void Tileset::Draw( sf::RenderTexture& window )
}
}
bool Tileset::TileClicked( const sf::Vector2f& mousePos, Tile& tileInfo )
bool Tileset::TileClicked( const sf::Vector2f& mousePos, ChaloTile& tileInfo )
{
Logger::StackPush( s_className + "::" + __func__ );
for ( auto& tile : m_tileset )
......
File moved
#include "ChaloEngineProgram.hpp"
#include "../States/StartupState.hpp"
#include "../States/MapEditorState.hpp"
#include "../States/GameState.hpp"
#include "../States/OptionsState.hpp"
#include "../States/HelpState.hpp"
......@@ -162,7 +161,6 @@ void ChaloEngineProgram::InitStates()
// TODO: I still need to fix this up
m_stateManager.AddState( "startupState", new StartupState );
m_stateManager.AddState( "mapEditorState", new MapEditorState );
m_stateManager.AddState( "gameState", new GameState );
m_stateManager.AddState( "optionsState", new OptionsState );
m_stateManager.AddState( "helpState", new HelpState );
......
source/Content/Graphics/Tilesets/sheet-terrain.png

3.01 KiB | W: | H:

source/Content/Graphics/Tilesets/sheet-terrain.png

4.15 KiB | W: | H:

source/Content/Graphics/Tilesets/sheet-terrain.png
source/Content/Graphics/Tilesets/sheet-terrain.png
source/Content/Graphics/Tilesets/sheet-terrain.png
source/Content/Graphics/Tilesets/sheet-terrain.png
  • 2-up
  • Swipe
  • Onion skin
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.2" tiledversion="1.3.2" orientation="orthogonal" renderorder="right-down" compressionlevel="0" width="20" height="12" tilewidth="20" tileheight="20" infinite="0" nextlayerid="5" nextobjectid="1">
<tileset firstgid="1" source="sheet-terrain.tsx"/>
<tileset firstgid="193" source="sheet-objects.tsx"/>
<layer id="1" name="FLOOR-LAYER" width="20" height="12">
<map version="1.2" tiledversion="1.3.2" orientation="orthogonal" renderorder="right-down" compressionlevel="0" width="20" height="12" tilewidth="20" tileheight="20" infinite="0" nextlayerid="6" nextobjectid="1">
<tileset firstgid="1" source="../../../design/tiled-levels/sheet-terrain.tsx"/>
<tileset firstgid="193" source="../../../design/tiled-levels/sheet-objects.tsx"/>
<layer id="1" name="FLOOR" width="20" height="12">
<data encoding="csv">
17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
17,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,
17,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,
17,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,
17,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,
17,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,
17,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,
17,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,
17,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,
17,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,
17,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,
17,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,17,
17,14,14,14,14,14,14,14,14,14,14,14,14,14,114,114,114,114,114,17,
17,14,14,14,14,14,14,14,14,14,14,14,14,14,114,114,114,114,114,17,
17,14,14,14,14,14,14,14,14,14,14,14,14,14,114,114,114,114,114,17,
17,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,17,
17,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,17,
17,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,17,
17,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,17,
17,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,17,
17,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,17,
17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17
</data>
</layer>
<layer id="2" name="MIDDLE-LAYER1" width="20" height="12">
<layer id="2" name="WALL" width="20" height="12">
<data encoding="csv">
17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
17,42,42,42,42,42,42,42,42,42,42,42,42,17,42,42,42,42,42,17,
17,0,0,0,0,0,0,0,0,0,0,0,0,17,0,0,0,0,0,17,
17,0,0,0,0,0,0,0,0,0,0,0,0,17,0,0,0,0,0,17,
17,0,0,0,0,0,0,0,0,0,0,0,0,17,0,0,0,0,0,17,
17,0,0,0,0,0,0,0,0,0,0,0,0,17,17,17,0,17,17,17,
17,0,0,0,0,0,0,0,0,0,0,0,0,42,42,42,0,42,42,17,
17,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,17,
17,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,17,
17,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,17,
17,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,17,
17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17
</data>
</layer>
<layer id="3" name="DECOR" width="20" height="12">
<data encoding="csv">
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,66,66,66,66,66,66,66,66,66,66,66,66,56,66,66,66,66,66,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,116,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,116,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,116,0,0,0,
0,0,0,0,0,0,0,0,0,137,138,138,138,138,138,138,127,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
</data>
</layer>
<layer id="3" name="MIDDLE-LAYER2" width="20" height="12">
<layer id="4" name="OBJECT" width="20" height="12">
<data encoding="csv">
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,21,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
</data>
</layer>
<layer id="4" name="OBJECT-LAYER" width="20" height="12">
<data encoding="csv">
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,215,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,241,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,220,0,0,
0,0,0,0,0,0,210,0,0,0,213,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,210,0,0,0,0,0,0,0,0,0,211,0,0,0,0,
0,0,0,0,0,0,0,209,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,230,0,0,0,0,0,0,0,0,0,206,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
</data>
......
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.2" tiledversion="1.3.2" orientation="orthogonal" renderorder="right-down" compressionlevel="0" width="20" height="12" tilewidth="20" tileheight="20" infinite="0" nextlayerid="5" nextobjectid="1">
<tileset firstgid="1" source="sheet-terrain.tsx"/>
<tileset firstgid="193" source="sheet-objects.tsx"/>
<layer id="1" name="FLOOR-LAYER" width="20" height="12">
<data encoding="csv">
17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
17,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,
17,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,
17,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,
17,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,
17,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,
17,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,
17,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,
17,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,
17,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,
17,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,
17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17
</data>
</layer>
<layer id="2" name="MIDDLE-LAYER1" width="20" height="12">
<data encoding="csv">
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,66,66,66,66,66,66,66,66,66,66,66,66,56,66,66,66,66,66,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
</data>
</layer>
<layer id="3" name="MIDDLE-LAYER2" width="20" height="12">
<data encoding="csv">
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,21,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
</data>
</layer>
<layer id="4" name="OBJECT-LAYER" width="20" height="12">
<data encoding="csv">
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,215,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,241,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,220,0,0,
0,0,0,0,0,0,210,0,0,0,213,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,210,0,0,0,0,0,0,0,0,0,211,0,0,0,0,
0,0,0,0,0,0,0,209,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,230,0,0,0,0,0,0,0,0,0,206,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
</data>
</layer>
</map>
......@@ -30,8 +30,8 @@ void GameState::Setup()
Logger::StackPush( s_className + "::" + __func__ );
IState::Setup();
chalo::TextureManager::Add( "sheet-items", "Content/Graphics/Tilesets/sheet-objects.png" );
chalo::TextureManager::Add( "sheet-terrain", "Content/Graphics/Tilesets/sheet-terrain.png" );
// chalo::TextureManager::Add( "sheet-items", "Content/Graphics/Tilesets/sheet-objects.png" );
// chalo::TextureManager::Add( "sheet-terrain", "Content/Graphics/Tilesets/sheet-terrain.png" );
// chalo::TextureManager::AddAndGet( "map-editor-buttons", "Content/Graphics/UI/map-editor-buttons.png" );
// chalo::TextureManager::AddAndGet( "menu-bar", "Content/Graphics/UI/menu-bar.png" );
// chalo::TextureManager::AddAndGet( "sheet-rawr", "Content/Graphics/Objects/sheet-rawr.png" );
......@@ -47,18 +47,12 @@ void GameState::Setup()
std::string levelFilename = "LEVEL_" + Helper::ToString( world + "-" + level ) + ".tmx";
Logger::OutValue( "levelFilename", levelFilename );
m_map.Load( "Content/Maps/", levelFilename );
m_map.Debug();
ChaloMap test;
test.ConvertFrom( m_map );
TmxMap tmxMap;
tmxMap.Load( "Content/Maps/", levelFilename );
tmxMap.Debug();
// XmlDocument doc = XmlParser::Parse( levelFilename );
// doc.Debug();
// m_map.Setup( "sheet-terrain", "sheet-items", "sheet-rawr" );
// m_map.Clear();
// m_map.Load( levelFilename );
m_map.ConvertFrom( tmxMap );
m_map.Debug();
m_inputCooldownMax = 10;
m_inputCooldown = 0;
......@@ -95,7 +89,7 @@ void GameState::Update()
void GameState::Draw( sf::RenderTexture& window )
{
Logger::StackPush( s_className + "::" + __func__ );
// Draw_Map( window );
Draw_Map( window );
// chalo::MenuManager::Draw( window );
Logger::StackPop();
}
......@@ -103,7 +97,7 @@ void GameState::Draw( sf::RenderTexture& window )
void GameState::Draw_Map( sf::RenderTexture& window )
{
Logger::StackPush( s_className + "::" + __func__ );
// m_map.Draw( window );
m_map.Draw( window );
Logger::StackPop();
}
......
......@@ -13,7 +13,6 @@
#include <vector>
#include "../Objects/RawrMap.hpp"
#include "../Objects/Enums.hpp"
class GameState : public chalo::IState
......@@ -35,8 +34,7 @@ private:
float m_inputCooldown;
float m_inputCooldownMax;
//RawrMap m_map;
TmxMap m_map;
ChaloMap m_map;
// sf::Sprite m_player;
......
#include "ChaloMap.hpp"
#include "../Managers/TextureManager.hpp"
#include "../Utilities/Logger.hpp"
#include "../Utilities_SFML/SFMLHelper.hpp"
std::string ChaloMap::s_className = "ChaloMap";
......@@ -8,10 +10,15 @@ void ChaloMap::ConvertFrom( const TmxMap& tmxMap )
{
Logger::StackPush( s_className + "::" + __func__ );
Logger::OutValue( "tmxMap.m_tileWidth", Helper::ToString( tmxMap.m_tileWidth ), s_className + "::" + __func__ );
Logger::OutValue( "tmxMap.m_tileHeight", Helper::ToString( tmxMap.m_tileHeight ), s_className + "::" + __func__ );
Logger::OutValue( "tmxMap.m_width", Helper::ToString( tmxMap.m_width ), s_className + "::" + __func__ );
Logger::OutValue( "tmxMap.m_height", Helper::ToString( tmxMap.m_height ), s_className + "::" + __func__ );
m_tileDimensions.x = tmxMap.m_tileWidth;
m_tileDimensions.y = tmxMap.m_tileHeight;
m_mapDimensions.x = tmxMap.m_width;
m_mapDimensions.x = tmxMap.m_height;
m_mapDimensions.y = tmxMap.m_height;
// Figure out spritesheet offsets; terrain can be used as-is,
// but objects are special items and require special loading.
......@@ -26,7 +33,7 @@ void ChaloMap::ConvertFrom( const TmxMap& tmxMap )
objectTileOffset = tileset.firstGid;
objectTileset = tileset;
}
else if ( Helper::Contains( tileset.tsxSource, "terrain", false ) )
else //if ( Helper::Contains( tileset.tsxSource, "terrain", false ) )
{
terrainTileOffset = tileset.firstGid;
terrainTileset = tileset;
......@@ -34,6 +41,8 @@ void ChaloMap::ConvertFrom( const TmxMap& tmxMap )
}
}
const sf::Texture& txTileset = chalo::TextureManager::AddAndGet( "tileset", "Content/Graphics/Tilesets/" + m_tilesetName );
for ( auto& layer : tmxMap.m_layers )
{
if ( Helper::Contains( layer.name, "object", false ) )
......@@ -42,29 +51,62 @@ void ChaloMap::ConvertFrom( const TmxMap& tmxMap )
}
else
{
ChaloMapLayer chaloLayer;
// Terrain layer
int zIndex = layer.id;
chaloLayer.name = layer.name;
chaloLayer.mapDimensions = sf::IntRect( 0, 0, tmxMap.m_width, tmxMap.m_height );
for ( size_t index = 0; index < layer.data.size(); index++ )
{
ChaloTile newTile;
newTile.m_dimensions.left = 0;
newTile.m_dimensions.top = 0;
newTile.m_dimensions.width = tmxMap.m_tileWidth;
newTile.m_dimensions.height = tmxMap.m_tileHeight;
// Position of the tile on the map
int xPos = index % layer.width;
int yPos = index / layer.width;
// Logger::Out( "Tile Index: " + Helper::ToString( index )
// + ", xPos: " + Helper::ToString( xPos )
// + ", yPos: " + Helper::ToString( yPos )
// , s_className + "::" + __func__ );
newTile.m_tmxIndex = index;
newTile.m_position.x = (index % layer.width) * newTile.m_dimensions.width;
newTile.m_position.y = (index / layer.width) * newTile.m_dimensions.height;
// Position of the tile's coordinates on the tileset
int tileId = layer.data[index] - terrainTileOffset;
int tilesetX = tileId % terrainTileset.columns;
int tilesetY = tileId / terrainTileset.columns;
newTile.m_tmxTileId = tileId;
int tileX = tileId % terrainTileset.columns;
int tileY = tileId / terrainTileset.columns;
newTile.m_frameRect.left = tileX * newTile.m_dimensions.width;
newTile.m_frameRect.top = tileY * newTile.m_dimensions.height;
newTile.m_frameRect.width = newTile.m_dimensions.width;
newTile.m_frameRect.height = newTile.m_dimensions.height;
// Logger::Out( "Tilesheet Index: " + Helper::ToString( tileId )
// + ", tilesetX: " + Helper::ToString( tilesetX )
// + ", tilesetY: " + Helper::ToString( tilesetY )
// , s_className + "::" + __func__ );
newTile.m_sprite.setTexture( txTileset );
newTile.m_sprite.setTextureRect( newTile.m_frameRect );
newTile.m_sprite.setPosition( newTile.m_position );
// TODO: Put this in an external file
if ( (tileX >= 0 || tileX <= 4) && tileY == 1 ) { newTile.m_name = "Floor" + Helper::ToString( tileX ); }
if ( newTile.m_frameRect.left < 0 || newTile.m_frameRect.top < 0 )
{
if ( chaloLayer.name == "FLOOR" )
{
Logger::Out( "SKIPPING " + chaloLayer.name + " TILE " + Helper::ToString( index )
+ ", TILEID: " + Helper::ToString( tileId )
+ ", FRAME: " + SFMLHelper::RectangleToString( newTile.m_frameRect )
+ ", TILEPOS: " + SFMLHelper::CoordinateToString( newTile.m_position )
);
}
// Empty tile
continue;
}
chaloLayer.tiles.push_back( newTile );
}
m_layers.push_back( chaloLayer );
}
}
......@@ -75,3 +117,50 @@ std::string ChaloMap::GetTilesetName()
{
return m_tilesetName;
}
void ChaloMap::Draw( sf::RenderTexture& window )
{
Logger::StackPush( s_className + "::" + __func__ );
for ( auto& layer : m_layers )
{
for ( auto& tile : layer.tiles )
{
window.draw( tile.m_sprite );
}
}
Logger::StackPop();
}
void ChaloMap::Debug()
{
Logger::StackPush( s_className + "::" + __func__ );
std::string debugInfo = "Tileset name: \"" + m_tilesetName + "\"<br>"
+ "m_tileDimensions:" + SFMLHelper::CoordinateToString( m_tileDimensions ) + "<br>"
+ "m_mapDimensions:" + SFMLHelper::CoordinateToString( m_mapDimensions ) + "<br>";
for ( auto& layer : m_layers )
{
debugInfo += "LAYER: " + layer.name + "<br>";
for ( auto& tile : layer.tiles )
{
debugInfo += "... TILE NAME: " + tile.m_name + ", ";
debugInfo += "TMX INDEX: " + Helper::ToString( tile.m_tmxIndex ) + ", ";
debugInfo += "TMX TILE ID: " + Helper::ToString( tile.m_tmxTileId ) + ", ";
debugInfo += "POS: (" + SFMLHelper::CoordinateToString( tile.m_sprite.getPosition() ) + "), ";
debugInfo += "FRAME: (" + SFMLHelper::RectangleToString( tile.m_sprite.getTextureRect() ) + "), ";
debugInfo += "DIMENSIONS: (" + SFMLHelper::RectangleToString( tile.m_dimensions ) + "), ";
debugInfo += "<br>";
}
debugInfo += "<br>";
}
Logger::Out( debugInfo, s_className + "::" + __func__ );
Logger::StackPop();
}
......@@ -2,16 +2,27 @@
#define _CHALO_MAP_HPP
#include "TmxMap.hpp"
#include "ChaloTile.hpp"
#include <SFML/Graphics.hpp>
// TODO: Create Tile class for ChaloMap
#include <vector>
struct ChaloMapLayer
{
std::string name;
std::vector<ChaloTile> tiles;
sf::IntRect mapDimensions;
};
class ChaloMap
{
public:
void ConvertFrom( const TmxMap& tmxMap );
std::string GetTilesetName();
void Draw( sf::RenderTexture& window );
void Debug();
private:
static std::string s_className;
......@@ -19,6 +30,10 @@ private:
std::string m_tilesetName;
sf::Vector2i m_tileDimensions;
sf::Vector2i m_mapDimensions;
std::vector<ChaloMapLayer> m_layers;
void ConvertTmxTerrain();
void ConvertTmxObjects();
};
#endif
#include "ChaloTile.hpp"
#include "../Utilities/Logger.hpp"
#include "../Utilities_SFML/SFMLHelper.hpp"
#include "../Utilities/Helper.hpp"
#include <string>
ChaloTile& ChaloTile::operator=( ChaloTile other )
{
if ( this == &other ) { return *this; }
m_position = other.m_position;
m_dimensions = other.m_dimensions;
m_frameRect = other.m_frameRect;
m_sprite = other.m_sprite;
m_name = other.m_name;
m_canWalkOn = other.m_canWalkOn;
return *this;
}
void ChaloTile::SetTexture( const sf::Texture& texture )
{
m_sprite.setTexture( texture );
}
void ChaloTile::SetPosition( sf::Vector2f position )
{
m_position = position;
m_sprite.setPosition( position );
}
void ChaloTile::SetPositionX( float value )
{
m_position.x = value;
}
void ChaloTile::SetPositionY( float value )
{
m_position.y = value;
}
void ChaloTile::SetFrameRect( sf::IntRect frameRect )
{
m_frameRect = frameRect;
}
void ChaloTile::SetFrameRectDimensions( int width, int height )
{
m_frameRect.width = width;
m_frameRect.height = height;
}
void ChaloTile::SetFrameRectLeft( int value )
{
m_frameRect.left = value;
}
void ChaloTile::SetFrameRectTop( int value )
{
m_frameRect.top = value;
}
void ChaloTile::SetDimensions( sf::IntRect dimensions )
{
m_dimensions = dimensions;
}
void ChaloTile::SetName( std::string value )
{
m_name = value;
}
void ChaloTile::SetCanWalkOn( bool value )
{
m_canWalkOn = value;
}
void ChaloTile::SetLayerIndex( int value )
{
m_layerIndex = value;
}
sf::Sprite ChaloTile::GetSprite()
{
m_sprite.setPosition( m_position );
m_sprite.setTextureRect( m_frameRect );
return m_sprite;
}
sf::RectangleShape ChaloTile::GetDebugRectangle()
{
m_debugShape.setPosition( m_position );
m_debugShape.setSize( sf::Vector2f( m_dimensions.width, m_dimensions.height ) );
m_debugShape.setFillColor( sf::Color( 0, 0, 0, 0 ) );
if ( !m_canWalkOn )
{
if ( m_layerIndex == 0 )
{
m_debugShape.setFillColor( sf::Color( 255, 0, 0, 100 ) );
}
else if ( m_layerIndex == 1 )
{
m_debugShape.setFillColor( sf::Color( 0, 255, 0, 100 ) );
}
else if ( m_layerIndex == 2 )
{
m_debugShape.setFillColor( sf::Color( 0, 0, 255, 100 ) );
}
}
return m_debugShape;
}
sf::IntRect ChaloTile::GetCollisionRegion()
{
sf::IntRect collisionRegion;
collisionRegion.left = m_position.x;
collisionRegion.top = m_position.y;
collisionRegion.width = m_dimensions.width;
collisionRegion.height = m_dimensions.height;
return collisionRegion;
}
const sf::Texture* ChaloTile::GetTexture()
{
return m_sprite.getTexture();
}
sf::IntRect ChaloTile::GetFrameRect()
{
return m_frameRect;
}
sf::Vector2f ChaloTile::GetPosition()
{
return m_position;
}
std::string ChaloTile::GetName()
{
return m_name;
}
bool ChaloTile::GetCanWalkOn()
{
return m_canWalkOn;
}
float ChaloTile::GetPositionX()
{
return m_position.x;
}
float ChaloTile::GetPositionY()
{
return m_position.y;
}
int ChaloTile::GetDimensionsWidth()
{
return m_dimensions.width;
}
int ChaloTile::GetDimensionsHeight()
{
return m_dimensions.height;
}
int ChaloTile::GetFrameRectTop()
{
return m_frameRect.top;
}
int ChaloTile::GetFrameRectLeft()
{
return m_frameRect.left;
}
int ChaloTile::GetFrameRectWidth()
{
return m_frameRect.width;
}
int ChaloTile::GetFrameRectHeight()
{
return m_frameRect.height;
}
void ChaloTile::Debug()
{
Logger::StackPush( "Tile::Debug" );
Logger::Out( "m_name: " + m_name
+ "<br>m_position: " + SFMLHelper::CoordinateToString( m_position )
+ "<br>m_dimensions: " + SFMLHelper::RectangleToString( m_dimensions )
+ "<br>m_frameRect: " + SFMLHelper::RectangleToString( m_frameRect )
+ "<br>m_canWalkOn: " + Helper::ToString( m_canWalkOn )
, "Tile::Debug" );
Logger::StackPop();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment