diff --git a/Crawler/Class.h b/Crawler/Class.h index 1f011a34..d3103d7a 100644 --- a/Crawler/Class.h +++ b/Crawler/Class.h @@ -14,6 +14,7 @@ struct ClassData{ static void InitializeClassData(); ClassData(std::string name,Class cl,Ability rightClickAbility,Ability ability1,Ability ability2,Ability ability3, AnimationState walk_n,AnimationState walk_e,AnimationState walk_s,AnimationState walk_w,AnimationState idle_n,AnimationState idle_e,AnimationState idle_s,AnimationState idle_w); + virtual ~ClassData()=default; virtual void Update(float fElapsedTime)=0; virtual bool AutoAttack()=0; virtual bool Ability1()=0; diff --git a/Crawler/Crawler.cpp b/Crawler/Crawler.cpp index c54c3b1e..4c2c4456 100644 --- a/Crawler/Crawler.cpp +++ b/Crawler/Crawler.cpp @@ -851,14 +851,16 @@ void Crawler::RenderWorld(float fElapsedTime){ } #pragma region Foreground Rendering 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)){ + if(geom2d::overlaps(group.GetFadeRange(),player.pos)){ + group.playerBehind=true; + group.fadeFactor=std::min(group.fadeFactor+fElapsedTime,TileGroup::FADE_TIME); + } else { + group.playerBehind=false; + group.fadeFactor=std::max(group.fadeFactor-fElapsedTime,0.f); + } 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)}); + view.DrawPartialDecal(tile.pos,{24,24},tile.tileset,tile.tileSheetPos,{24,24},{255,255,255,uint8_t(255-group.fadeFactor/TileGroup::FADE_TIME*TileGroup::FADE_AMT)}); } } } diff --git a/Crawler/Map.cpp b/Crawler/Map.cpp index bfe4a7fe..2373621a 100644 --- a/Crawler/Map.cpp +++ b/Crawler/Map.cpp @@ -1,5 +1,8 @@ #include "Map.h" +float TileGroup::FADE_TIME=0.3; +uint8_t TileGroup::FADE_AMT=160; + void TileGroup::InsertTile(TileRenderData tile){ if(tiles.size()==0){ range={tile.pos,{24,24}}; @@ -29,6 +32,10 @@ geom2d::rectTileGroup::GetRange(){ return range; } +geom2d::rectTileGroup::GetFadeRange(){ + return {range.pos+vi2d{-24,-24},range.size+vi2d{48,48}}; +} + std::vector&TileGroup::GetTiles(){ return tiles; } \ No newline at end of file diff --git a/Crawler/Map.h b/Crawler/Map.h index 50771735..f7285add 100644 --- a/Crawler/Map.h +++ b/Crawler/Map.h @@ -33,8 +33,14 @@ private: std::vectortiles; int minX=0,minY=0,maxX=0,maxY=0; public: + static float FADE_TIME; + //0-255. 255 indicates fully invisible. + static uint8_t FADE_AMT; geom2d::rectGetRange(); + //The fade range is the bounds in which this tile group will be considered "in range" of a player, one tile in each direction further than its actual range. + geom2d::rectGetFadeRange(); std::vector&GetTiles(); void InsertTile(TileRenderData tile); bool playerBehind=false; + float fadeFactor=0.f; }; \ No newline at end of file diff --git a/Crawler/olcUTIL_Geometry2D.h b/Crawler/olcUTIL_Geometry2D.h index 36f50962..1d66f41b 100644 --- a/Crawler/olcUTIL_Geometry2D.h +++ b/Crawler/olcUTIL_Geometry2D.h @@ -178,10 +178,10 @@ namespace olc::utils::geom2d // Get a line from an indexed side, starting top, going clockwise inline line side(const size_t i) const { - if (i & 0b11 == 0) return top(); - if (i & 0b11 == 1) return right(); - if (i & 0b11 == 2) return bottom(); - if (i & 0b11 == 3) return left(); + if (i & (0b11 == 0)) return top(); + if (i & (0b11 == 1)) return right(); + if (i & (0b11 == 2)) return bottom(); + if (i & (0b11 == 3)) return left(); } // Get area of rectangle