From 60c8317b208d6318d381be3c4958917ec3660795 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Thu, 22 Jun 2023 23:28:16 -0700 Subject: [PATCH] Detect connected tile groups and allow for fade out of the foreground layer when the player gets in range. These groups are initialized on level loading and self-expand. --- Crawler/Crawler.cpp | 54 +++++++++++++++++++++++++++++---- Crawler/Crawler.h | 1 + Crawler/Crawler.vcxproj | 1 + Crawler/Crawler.vcxproj.filters | 3 ++ Crawler/Map.cpp | 30 ++++++++++++++++++ Crawler/Map.h | 12 ++++++++ Crawler/Version.h | 2 +- 7 files changed, 96 insertions(+), 7 deletions(-) create mode 100644 Crawler/Map.cpp diff --git a/Crawler/Crawler.cpp b/Crawler/Crawler.cpp index ce4479c8..f8bbb9df 100644 --- a/Crawler/Crawler.cpp +++ b/Crawler/Crawler.cpp @@ -609,7 +609,6 @@ void Crawler::HurtEnemies(vf2d pos,float radius,int damage){ void Crawler::RenderWorld(float fElapsedTime){ Clear({100,180,100}); - std::vectorforegroundTiles; for (int x = view.GetTopLeftTile().x/24-1; x <= view.GetBottomRightTile().x/24; x++){ for (int y = view.GetTopLeftTile().y/24-1; y <= view.GetBottomRightTile().y/24; y++){ if(x>=0&&x=0&&yDecal(),vi2d{x,y}*24,vi2d{tileSheetX,tileSheetY}*24}); - } else { + if(!IsForegroundTile(tileSheet,tileSheetIndex)){ view.DrawPartialDecal(vi2d{x,y}*24,{24,24},tileSheet.tileset.tileset->Decal(),vi2d{tileSheetX,tileSheetY}*24,{24,24}); } } @@ -665,8 +662,17 @@ void Crawler::RenderWorld(float fElapsedTime){ for(Bullet&b:PLAYER_BULLET_LIST){ b.Draw(); } - for(TileRenderData&foregroundTile:foregroundTiles){ - view.DrawPartialDecal(foregroundTile.pos,{24,24},foregroundTile.tileset,foregroundTile.tileSheetPos,{24,24},{255,255,255,uint8_t(std::clamp(geom2d::line(foregroundTile.pos+vi2d{12,12},player.GetPos()).length()*5,0.f,255.f))}); + for(TileGroup&group:foregroundTileGroups){ + if(geom2d::overlaps(group.GetRange(),player.pos)){ + group.playerBehind=true; + } else { + group.playerBehind=false; + } + if(view.IsRectVisible(group.GetRange().pos,group.GetRange().size)){ + for(TileRenderData&tile:group.GetTiles()){ + view.DrawPartialDecal(tile.pos,{24,24},tile.tileset,tile.tileSheetPos,{24,24},{255,255,255,uint8_t(group.playerBehind?128:255)}); + } + } } for(std::vector::iterator it=DAMAGENUMBER_LIST.begin();it!=DAMAGENUMBER_LIST.end();++it){ DamageNumber&dn=*it; @@ -798,6 +804,7 @@ void Crawler::InitializeLevel(std::string mapFile,MapName map){ void Crawler::LoadLevel(MapName map){ SPAWNER_LIST.clear(); + foregroundTileGroups.clear(); currentLevel=map; WORLD_SIZE={MAP_DATA[map].MapData.width,MAP_DATA[map].MapData.height}; for(SpawnerTag&spawner:MAP_DATA[map].SpawnerData){ @@ -811,6 +818,41 @@ void Crawler::LoadLevel(MapName map){ } SPAWNER_LIST.push_back(MonsterSpawner{{spawner.ObjectData.GetFloat("x")+spawnerRadius.x,spawner.ObjectData.GetFloat("y")+spawnerRadius.y},spawnerRadius,monster_list}); } + for(int x=0;xSprite()->width/24; + int tileSheetHeight=tileSheet.tileset.tileset->Sprite()->height/24; + int tileSheetIndex=tileID-(tileSheet.firstgid-1); + int tileSheetX=tileSheetIndex%tileSheetWidth; + int tileSheetY=tileSheetIndex/tileSheetWidth; + if(IsForegroundTile(tileSheet,tileSheetIndex)){ + TileRenderData tile={tileSheet.tileset.tileset->Decal(),vi2d{x,y}*24,vi2d{tileSheetX,tileSheetY}*24}; + std::cout<<"Tile "<{vi2d{x,y}*24-vi2d{1,1},{26,26}},group.GetRange())){ + std::cout<<" Group found: "<foregroundTileGroups; public: Crawler(); diff --git a/Crawler/Crawler.vcxproj b/Crawler/Crawler.vcxproj index d1946e90..4544f812 100644 --- a/Crawler/Crawler.vcxproj +++ b/Crawler/Crawler.vcxproj @@ -193,6 +193,7 @@ + diff --git a/Crawler/Crawler.vcxproj.filters b/Crawler/Crawler.vcxproj.filters index e1f8416d..dc5d3b2e 100644 --- a/Crawler/Crawler.vcxproj.filters +++ b/Crawler/Crawler.vcxproj.filters @@ -119,6 +119,9 @@ Source Files + + Source Files + diff --git a/Crawler/Map.cpp b/Crawler/Map.cpp new file mode 100644 index 00000000..14c87ad6 --- /dev/null +++ b/Crawler/Map.cpp @@ -0,0 +1,30 @@ +#include "Map.h" + +void TileGroup::InsertTile(TileRenderData tile){ + if(tiles.size()==0){ + range={tile.pos,{24,24}}; + } + tiles.push_back(tile); + if(tile.pos.xrange.pos.x+range.size.x){ + range.size.x+=(tile.pos.x+24)-(range.pos.x+range.size.x); + } + if(tile.pos.yrange.pos.y+range.size.y){ + range.size.y+=(tile.pos.y+24)-(range.pos.y+range.size.y); + } +} + +geom2d::rectTileGroup::GetRange(){ + return range; +} + +std::vector&TileGroup::GetTiles(){ + return tiles; +} \ No newline at end of file diff --git a/Crawler/Map.h b/Crawler/Map.h index eee7c528..22db9fdd 100644 --- a/Crawler/Map.h +++ b/Crawler/Map.h @@ -1,5 +1,6 @@ #pragma once #include "TSXParser.h" +#include "olcUTIL_Geometry2D.h" enum MapName{ LEVEL1, @@ -16,4 +17,15 @@ struct TileRenderData{ Decal*tileset; vi2d pos; vi2d tileSheetPos; +}; + +struct TileGroup{ +private: + geom2d::rectrange; + std::vectortiles; +public: + geom2d::rectGetRange(); + std::vector&GetTiles(); + void InsertTile(TileRenderData tile); + bool playerBehind=false; }; \ No newline at end of file diff --git a/Crawler/Version.h b/Crawler/Version.h index 3fb2818d..ce35d897 100644 --- a/Crawler/Version.h +++ b/Crawler/Version.h @@ -2,7 +2,7 @@ #define VERSION_MAJOR 0 #define VERSION_MINOR 2 #define VERSION_PATCH 0 -#define VERSION_BUILD 204 +#define VERSION_BUILD 217 #define stringify(a) stringify_(a) #define stringify_(a) #a