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.

pull/28/head
sigonasr2 1 year ago
parent 5ffcf3126a
commit 60c8317b20
  1. 54
      Crawler/Crawler.cpp
  2. 1
      Crawler/Crawler.h
  3. 1
      Crawler/Crawler.vcxproj
  4. 3
      Crawler/Crawler.vcxproj.filters
  5. 30
      Crawler/Map.cpp
  6. 12
      Crawler/Map.h
  7. 2
      Crawler/Version.h

@ -609,7 +609,6 @@ void Crawler::HurtEnemies(vf2d pos,float radius,int damage){
void Crawler::RenderWorld(float fElapsedTime){
Clear({100,180,100});
std::vector<TileRenderData>foregroundTiles;
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<WORLD_SIZE.x&&y>=0&&y<WORLD_SIZE.y){
@ -622,9 +621,7 @@ void Crawler::RenderWorld(float fElapsedTime){
int tileSheetIndex=tileID-(tileSheet.firstgid-1);
int tileSheetX=tileSheetIndex%tileSheetWidth;
int tileSheetY=tileSheetIndex/tileSheetWidth;
if(IsForegroundTile(tileSheet,tileSheetIndex)){
foregroundTiles.push_back({tileSheet.tileset.tileset->Decal(),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<float>(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<DamageNumber>::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;x<WORLD_SIZE.x;x++){
for(int y=0;y<WORLD_SIZE.y;y++){
for(LayerTag&layer:MAP_DATA[currentLevel].LayerData){
int tileID=layer.tiles[y][x]-1;
if(tileID!=-1){
TilesheetData tileSheet=GetTileSheet(currentLevel,tileID);
int tileSheetWidth=tileSheet.tileset.tileset->Sprite()->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}<<" w/Tile ID "<<tileSheetIndex<<" is foreground tile."<<std::endl;
bool foundGroup=false;
for(TileGroup&group:foregroundTileGroups){
if(geom2d::overlaps(geom2d::rect<int>{vi2d{x,y}*24-vi2d{1,1},{26,26}},group.GetRange())){
std::cout<<" Group found: "<<group.GetRange().pos<<"/"<<group.GetRange().size<<std::endl;
group.InsertTile(tile);
std::cout<<" After: "<<group.GetRange().pos<<"/"<<group.GetRange().size<<std::endl;
foundGroup=true;
break;
}
}
if(!foundGroup){
TileGroup group;
group.InsertTile(tile);
std::cout<<" No Group found. New group: "<<group.GetRange().pos<<"/"<<group.GetRange().size<<std::endl;
foregroundTileGroups.push_back(group);
}
}
}
}
}
}
}
vi2d Crawler::GetWorldSize(){

@ -33,6 +33,7 @@ class Crawler : public olc::PixelGameEngine
const float WORLD_SHAKE_ADJUST_MAX_TIME=0.4;
MapName currentLevel=MapName::CAMPAIGN_1_1;
vi2d WORLD_SIZE={120,8};
std::vector<TileGroup>foregroundTileGroups;
public:
Crawler();

@ -193,6 +193,7 @@
<ClCompile Include="Crawler.cpp" />
<ClCompile Include="DamageNumber.cpp" />
<ClCompile Include="Effect.cpp" />
<ClCompile Include="Map.cpp" />
<ClCompile Include="pixelGameEngine.cpp" />
<ClCompile Include="Player.cpp" />
<ClCompile Include="Monster.cpp" />

@ -119,6 +119,9 @@
<ClCompile Include="Class.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Map.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="cpp.hint" />

@ -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.x<range.pos.x){
range.pos.x=tile.pos.x;
range.size.x+=range.pos.x-tile.pos.x;
}
if(tile.pos.x+24>range.pos.x+range.size.x){
range.size.x+=(tile.pos.x+24)-(range.pos.x+range.size.x);
}
if(tile.pos.y<range.pos.y){
range.pos.y=tile.pos.y;
range.size.y+=range.pos.y-tile.pos.y;
}
if(tile.pos.y+24>range.pos.y+range.size.y){
range.size.y+=(tile.pos.y+24)-(range.pos.y+range.size.y);
}
}
geom2d::rect<int>TileGroup::GetRange(){
return range;
}
std::vector<TileRenderData>&TileGroup::GetTiles(){
return tiles;
}

@ -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::rect<int>range;
std::vector<TileRenderData>tiles;
public:
geom2d::rect<int>GetRange();
std::vector<TileRenderData>&GetTiles();
void InsertTile(TileRenderData tile);
bool playerBehind=false;
};

@ -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

Loading…
Cancel
Save