diff --git a/assets/HamsterGame.tiled-project b/assets/HamsterGame.tiled-project
index fab86e7..2a46977 100644
--- a/assets/HamsterGame.tiled-project
+++ b/assets/HamsterGame.tiled-project
@@ -13,9 +13,10 @@
{
"id": 1,
"name": "TerrainType",
- "storageType": "string",
+ "storageType": "int",
"type": "enum",
"values": [
+ "Void",
"Rock",
"Grass",
"Sand",
@@ -42,8 +43,8 @@
{
"name": "Terrain Type",
"propertyType": "TerrainType",
- "type": "string",
- "value": "Rock"
+ "type": "int",
+ "value": 0
}
],
"name": "TileProps",
diff --git a/assets/HamsterGame.tiled-session b/assets/HamsterGame.tiled-session
index f905270..f9ac0fe 100644
--- a/assets/HamsterGame.tiled-session
+++ b/assets/HamsterGame.tiled-session
@@ -26,6 +26,7 @@
},
"frame.defaultDuration": 200,
"last.imagePath": "C:/Users/sigon/source/repos/hamster/assets",
+ "last.objectTypesPath": "C:/Users/sigon/source/repos/hamster/assets/propertytypes.json",
"map.lastUsedFormat": "tmx",
"map.tileHeight": 16,
"map.tileWidth": 16,
diff --git a/assets/Terrain.tsx b/assets/Terrain.tsx
index a780b24..9473bd9 100644
--- a/assets/Terrain.tsx
+++ b/assets/Terrain.tsx
@@ -4,3565 +4,3565 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
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-
+
-
+
-
+
-
+
-
+
-
+
-
+
@@ -6016,7 +6020,7 @@
-
+
@@ -6024,49 +6028,49 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
@@ -6084,22 +6088,22 @@
-
+
-
+
-
+
-
+
@@ -6127,77 +6131,77 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
@@ -6213,42 +6217,42 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
@@ -6263,47 +6267,47 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
@@ -6321,24 +6325,24 @@
-
+
-
+
-
+
-
+
@@ -6354,42 +6358,42 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
@@ -6409,7 +6413,7 @@
-
+
@@ -6441,7 +6445,7 @@
-
+
diff --git a/assets/propertytypes.json b/assets/propertytypes.json
new file mode 100644
index 0000000..6dae751
--- /dev/null
+++ b/assets/propertytypes.json
@@ -0,0 +1,53 @@
+[
+ {
+ "id": 1,
+ "name": "TerrainType",
+ "storageType": "int",
+ "type": "enum",
+ "values": [
+ "Void",
+ "Rock",
+ "Grass",
+ "Sand",
+ "Swamp",
+ "Lava",
+ "Shore",
+ "Ocean",
+ "Forest",
+ "Tunnel",
+ "Ice"
+ ],
+ "valuesAsFlags": false
+ },
+ {
+ "color": "#ffa0a0a4",
+ "drawFill": true,
+ "id": 2,
+ "members": [
+ {
+ "name": "Solid",
+ "type": "bool",
+ "value": false
+ },
+ {
+ "name": "Terrain Type",
+ "propertyType": "TerrainType",
+ "type": "int",
+ "value": 10
+ }
+ ],
+ "name": "TileProps",
+ "type": "class",
+ "useAs": [
+ "property",
+ "map",
+ "layer",
+ "object",
+ "tile",
+ "tileset",
+ "wangcolor",
+ "wangset",
+ "project"
+ ]
+ }
+]
diff --git a/hamster.vcxproj b/hamster.vcxproj
index cd0067e..1a4ac96 100644
--- a/hamster.vcxproj
+++ b/hamster.vcxproj
@@ -329,6 +329,10 @@ if %errorlevel% neq 0 goto :VCEnd
+
+
+
+
@@ -366,6 +370,10 @@ if %errorlevel% neq 0 goto :VCEnd
+
+
+
+
diff --git a/hamster.vcxproj.filters b/hamster.vcxproj.filters
index 207f8ab..38aa74e 100644
--- a/hamster.vcxproj.filters
+++ b/hamster.vcxproj.filters
@@ -19,6 +19,9 @@
Source Files
+
+ Source Files
+
@@ -82,5 +85,8 @@
Header Files
+
+ Header Files
+
\ No newline at end of file
diff --git a/src/Hamster.cpp b/src/Hamster.cpp
index 7331df5..5326f49 100644
--- a/src/Hamster.cpp
+++ b/src/Hamster.cpp
@@ -180,4 +180,8 @@ void Hamster::HandleCollision(){
const float Hamster::GetRadius()const{
return collisionRadius;
+}
+
+const Terrain::TerrainType Hamster::GetTerrainStandingOn()const{
+ return HamsterGame::Game().GetTerrainTypeAtPos(GetPos());
}
\ No newline at end of file
diff --git a/src/Hamster.h b/src/Hamster.h
index 82757ab..ac3af13 100644
--- a/src/Hamster.h
+++ b/src/Hamster.h
@@ -40,6 +40,7 @@ All rights reserved.
#include
#include "olcUTIL_Geometry2D.h"
#include "olcUTIL_Animate2D.h"
+#include "Terrain.h"
class Hamster{
enum PlayerControlled{
@@ -90,4 +91,5 @@ public:
void MoveHamster();
void HandleCollision();
const float GetRadius()const;
+ const Terrain::TerrainType GetTerrainStandingOn()const;
};
\ No newline at end of file
diff --git a/src/HamsterGame.cpp b/src/HamsterGame.cpp
index f02644f..f446547 100644
--- a/src/HamsterGame.cpp
+++ b/src/HamsterGame.cpp
@@ -7,7 +7,7 @@ geom2d::rectHamsterGame::SCREEN_FRAME{{96,0},{320,288}};
std::unordered_map>HamsterGame::ANIMATIONS;
std::unordered_mapHamsterGame::GFX;
const std::string HamsterGame::ASSETS_DIR{"assets/"};
-PixelGameEngine*HamsterGame::self{nullptr};
+HamsterGame*HamsterGame::self{nullptr};
std::unordered_mapHamsterGame::ANIMATED_TILE_IDS;
HamsterGame::HamsterGame(){
@@ -71,6 +71,7 @@ void HamsterGame::LoadLevel(const std::string_view mapName){
const vf2d levelSpawnLoc{50,50}; //TEMPORARY
currentMap=TMXParser{ASSETS_DIR+std::string(mapName)};
+ currentTileset=TSXParser{ASSETS_DIR+std::string("Terrain.tsx")};
Hamster::LoadHamsters(levelSpawnLoc);
camera.SetTarget(Hamster::GetPlayer().GetPos());
@@ -87,6 +88,21 @@ void HamsterGame::DrawGame(){
DrawLevelTiles();
Hamster::DrawHamsters(tv);
border.Draw();
+ DrawStringDecal(SCREEN_FRAME.pos+vf2d{1,1},"Terrain Type: "+Terrain::TerrainToString(Hamster::GetPlayer().GetTerrainStandingOn()),BLACK);
+ DrawStringDecal(SCREEN_FRAME.pos,"Terrain Type: "+Terrain::TerrainToString(Hamster::GetPlayer().GetTerrainStandingOn()));
+}
+
+const Terrain::TerrainType HamsterGame::GetTerrainTypeAtPos(const vf2d pos)const{
+ Terrain::TerrainType tileType{Terrain::VOID};
+ if(pos.x<=0.f||pos.y<=0.f||pos.x>=currentMap.value().GetData().GetMapData().width*16||pos.y>=currentMap.value().GetData().GetMapData().height*16)return tileType;
+ for(const LayerTag&layer:currentMap.value().GetData().GetLayers()){
+ int tileX{int(floor(pos.x)/16)};
+ int tileY{int(floor(pos.y)/16)};
+ int tileID{layer.tiles[tileY][tileX]-1};
+ if(tileID==-1)continue;
+ if(currentTileset.value().GetData().GetTerrainData().count(tileID))tileType=currentTileset.value().GetData().GetTerrainData().at(tileID).second;
+ }
+ return tileType;
}
void HamsterGame::DrawLevelTiles(){
@@ -138,7 +154,7 @@ bool HamsterGame::OnUserDestroy(){
return true;
}
-PixelGameEngine&HamsterGame::Game(){
+HamsterGame&HamsterGame::Game(){
return *self;
}
diff --git a/src/HamsterGame.h b/src/HamsterGame.h
index 5879d93..bead40a 100644
--- a/src/HamsterGame.h
+++ b/src/HamsterGame.h
@@ -43,6 +43,8 @@ All rights reserved.
#include "olcUTIL_Camera2D.h"
#include "Border.h"
#include "TMXParser.h"
+#include "TSXParser.h"
+#include "Terrain.h"
class HamsterGame : public olc::PixelGameEngine
{
@@ -62,9 +64,10 @@ public:
static const Renderable&GetGFX(const std::string_view img);
static const Animate2D::Animation&GetAnimations(const std::string_view img);
- static PixelGameEngine&Game();
+ static HamsterGame&Game();
static std::unordered_mapANIMATED_TILE_IDS;
const double GetRuntime()const;
+ const Terrain::TerrainType GetTerrainTypeAtPos(const vf2d pos)const;
private:
void UpdateGame(const float fElapsedTime);
void DrawGame();
@@ -75,9 +78,10 @@ private:
void _LoadImage(const std::string_view img);
static std::unordered_mapGFX;
static std::unordered_map>ANIMATIONS;
- static PixelGameEngine*self;
+ static HamsterGame*self;
Border border;
void DrawLevelTiles();
std::optionalcurrentMap;
+ std::optionalcurrentTileset;
double runTime{};
};
\ No newline at end of file
diff --git a/src/TMXParser.h b/src/TMXParser.h
index 521da4a..41fbb65 100644
--- a/src/TMXParser.h
+++ b/src/TMXParser.h
@@ -129,7 +129,7 @@ struct Property{
class TMXParser{
public:
- Map&GetData();
+ const Map&GetData()const;
private:
Map parsedMapInfo;
std::string fileName;
@@ -256,7 +256,7 @@ class TMXParser{
rhs.FormatLayerData(os,rhs.LayerData) <<"\n";
return os;
}
- Map&TMXParser::GetData() {
+ const Map&TMXParser::GetData()const{
return parsedMapInfo;
}
void TMXParser::ParseTag(std::string tag) {
diff --git a/src/TSXParser.h b/src/TSXParser.h
index 98bd8af..14cf5f5 100644
--- a/src/TSXParser.h
+++ b/src/TSXParser.h
@@ -38,6 +38,7 @@ All rights reserved.
#pragma once
#include
#include "TMXParser.h"
+#include "Terrain.h"
using namespace olc;
@@ -53,17 +54,20 @@ struct Tileset{
bool isTerrain=false;
std::unordered_mapCollisionData;
std::unordered_map>AnimationData;
+ std::unordered_map>TerrainData;
friend std::ostream& operator << (std::ostream& os, Tileset& rhs);
+public:
+ const std::unordered_map>&GetTerrainData()const;
};
class TSXParser{
public:
- Tileset&GetData();
+ const Tileset&GetData()const;
private:
Tileset parsedTilesetInfo;
void ParseTag(std::string tag);
- std::string previousTag;
- int previousTagID;
+ std::vector previousTag;
+ std::vector previousTagID;
public:
TSXParser(std::string file);
};
@@ -73,13 +77,16 @@ class TSXParser{
#ifdef TSX_PARSER_SETUP
#undef TSX_PARSER_SETUP
extern bool _DEBUG_MAP_LOAD_INFO;
- Tileset&TSXParser::GetData() {
+ const Tileset&TSXParser::GetData()const{
return parsedTilesetInfo;
}
std::ostream&operator<<(std::ostream& os, Tileset& rhs){
os<>&Tileset::GetTerrainData()const{
+ return TerrainData;
+ }
void TSXParser::ParseTag(std::string tag) {
XMLTag newTag;
//First character is a '<' so we discard it.
@@ -138,25 +145,42 @@ class TSXParser{
parsedTilesetInfo.imageheight=newTag.GetInteger("height");
} else
if (newTag.tag=="tile"){
- previousTag=newTag.tag;
- previousTagID=newTag.GetInteger("id");
+ previousTag.emplace_back(newTag.tag);
+ previousTagID.emplace_back(newTag.GetInteger("id"));
+ } else
+ if(newTag.tag=="frame"){
+ //The way animation data is stored is every "animation_tile_precision" ms indicating which frame we should be on.
+ for(int&tagID:previousTagID){
+ for(int i=0;i&tileData{parsedTilesetInfo.TerrainData[tagID]};
+ tileData.second=Terrain::TerrainType(newTag.GetInteger("value"));
+ }
+ } else
+ if(newTag.tag=="property"&&newTag.data["propertytype"]=="Solid"){
+ //The way animation data is stored is every "animation_tile_precision" ms indicating which frame we should be on.
+ for(int&tagID:previousTagID){
+ std::pair&tileData{parsedTilesetInfo.TerrainData[tagID]};
+ tileData.first=Terrain::SolidType(newTag.GetBool("value"));
}
}
- if (newTag.tag=="object"&&previousTag=="tile"){
- TileCollisionData data;
- data.collision=geom2d::rect{{newTag.GetFloat("x"),newTag.GetFloat("y")},{newTag.GetFloat("width"),newTag.GetFloat("height")}};
- if(!parsedTilesetInfo.CollisionData.count(previousTagID)){
- parsedTilesetInfo.CollisionData[previousTagID]=data;
+ if (newTag.tag=="object"&&previousTag.size()>0&&previousTag[0]=="tile"){
+ for(int&tagID:previousTagID){
+ TileCollisionData data;
+ data.collision=geom2d::rect{{newTag.GetFloat("x"),newTag.GetFloat("y")},{newTag.GetFloat("width"),newTag.GetFloat("height")}};
+ if(!parsedTilesetInfo.CollisionData.count(tagID)){
+ parsedTilesetInfo.CollisionData[tagID]=data;
+ }
}
}
}
- TSXParser::TSXParser(std::string file)
- :previousTagID(-1){
+ TSXParser::TSXParser(std::string file){
std::ifstream f(file,std::ios::in);
std::string accumulator="";
@@ -178,6 +202,10 @@ class TSXParser{
//Beginning of XML tag.
accumulator=data;
if(accumulator.length()>1&&accumulator.at(1)=='/'){
+ if(accumulator.starts_with("")){
+ previousTag.clear();
+ previousTagID.clear();
+ }
accumulator=""; //Restart because this is an end tag.
}
if(accumulator.length()>1&&accumulator.find('>')!=std::string::npos){
diff --git a/src/Terrain.cpp b/src/Terrain.cpp
new file mode 100644
index 0000000..32d7f72
--- /dev/null
+++ b/src/Terrain.cpp
@@ -0,0 +1,76 @@
+#pragma region License
+/*
+License (OLC-3)
+~~~~~~~~~~~~~~~
+
+Copyright 2024 Joshua Sigona
+
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+1. Redistributions or derivations of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+
+2. Redistributions or derivative works in binary form must reproduce the above
+copyright notice. This list of conditions and the following disclaimer must be
+reproduced in the documentation and/or other materials provided with the distribution.
+
+3. Neither the name of the copyright holder nor the names of its contributors may
+be used to endorse or promote products derived from this software without specific
+prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
+SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
+
+Portions of this software are copyright © 2024 The FreeType
+Project (www.freetype.org). Please see LICENSE_FT.txt for more information.
+All rights reserved.
+*/
+#pragma endregion
+#include "Terrain.h"
+
+const std::string Terrain::TerrainToString(const TerrainType type){
+ switch(type){
+ case ROCK:{
+ return "Rock";
+ }break;
+ case GRASS:{
+ return "Grass";
+ }break;
+ case SAND:{
+ return "Sand";
+ }break;
+ case SWAMP:{
+ return "Swamp";
+ }break;
+ case LAVA:{
+ return "Lava";
+ }break;
+ case SHORE:{
+ return "Shore";
+ }break;
+ case OCEAN:{
+ return "Ocean";
+ }break;
+ case FOREST:{
+ return "Forest";
+ }break;
+ case TUNNEL:{
+ return "Tunnel";
+ }break;
+ case ICE:{
+ return "Ice";
+ }break;
+ default:{
+ return "Void";
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Terrain.h b/src/Terrain.h
new file mode 100644
index 0000000..4ec7d06
--- /dev/null
+++ b/src/Terrain.h
@@ -0,0 +1,61 @@
+#pragma region License
+/*
+License (OLC-3)
+~~~~~~~~~~~~~~~
+
+Copyright 2024 Joshua Sigona
+
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+1. Redistributions or derivations of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+
+2. Redistributions or derivative works in binary form must reproduce the above
+copyright notice. This list of conditions and the following disclaimer must be
+reproduced in the documentation and/or other materials provided with the distribution.
+
+3. Neither the name of the copyright holder nor the names of its contributors may
+be used to endorse or promote products derived from this software without specific
+prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
+SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
+
+Portions of this software are copyright © 2024 The FreeType
+Project (www.freetype.org). Please see LICENSE_FT.txt for more information.
+All rights reserved.
+*/
+#pragma endregion
+#pragma once
+#include
+
+namespace Terrain{
+ enum class SolidType{
+ SOLID=true,
+ WALKABLE=false,
+ };
+ #undef VOID
+ enum TerrainType{
+ VOID,
+ ROCK,
+ GRASS,
+ SAND,
+ SWAMP,
+ LAVA,
+ SHORE,
+ OCEAN,
+ FOREST,
+ TUNNEL,
+ ICE,
+ };
+ const std::string TerrainToString(const TerrainType type);
+}
\ No newline at end of file