Fix incorrect ordering of fade layers.

pull/28/head
sigonasr2 1 year ago
parent 9811644207
commit ee16393f85
  1. 75
      Crawler/Crawler.cpp
  2. 2
      Crawler/Map.h
  3. 21
      Crawler/TMXParser.h
  4. 2
      Crawler/Version.h
  5. 2
      Crawler/assets/Campaigns/1_1_v2.tmx
  6. 2
      Crawler/assets/config/MonsterStrategies.txt

@ -884,10 +884,11 @@ void Crawler::LoadLevel(MapName map){
}
SPAWNER_LIST.push_back(MonsterSpawner{{spawnData.ObjectData.GetFloat("x"),spawnData.ObjectData.GetFloat("y")},spawnerRadius*2,monster_list,spawnData.upperLevel});
}
//165,124
std::set<vi2d>foregroundTilesAdded,upperForegroundTilesAdded;
for(int x=0;x<WORLD_SIZE.x;x++){
for(int y=0;y<WORLD_SIZE.y;y++){
int layerID=0;
for(LayerTag&layer:MAP_DATA[currentLevel].LayerData){
int tileID=layer.tiles[y][x]-1;
if(tileID!=-1){
@ -899,20 +900,20 @@ void Crawler::LoadLevel(MapName map){
int tileSheetY=tileSheetIndex/tileSheetWidth;
#pragma region TileGroupShenanigans
auto SetupTileGroups=[&](std::function<bool(TilesheetData,int)>IsForeground,TileRenderData tile,std::set<vi2d>&foregroundTilesIncluded,std::vector<TileGroup>&groups){
int layerID=layer.tag.GetInteger("id");
if(IsForeground(tileSheet,tileSheetIndex)&&foregroundTilesIncluded.find({x,y})==foregroundTilesIncluded.end()){
if(foregroundTilesIncluded.find({x,y})==foregroundTilesIncluded.end()&&IsForeground(tileSheet,tileSheetIndex)){
std::queue<vi2d>tileGroupChecks;
TileGroup group;
foregroundTilesIncluded.insert({x,y});
group.originatingLayer=layerID;
group.InsertTile(tile);
if(x>0)tileGroupChecks.push({x-1,y});
if(x<WORLD_SIZE.x-1)tileGroupChecks.push({x+1,y});
if(y>0)tileGroupChecks.push({x,y-1});
if(y<WORLD_SIZE.y-1)tileGroupChecks.push({x,y+1});
auto IterateThroughOtherLayers=[&](vi2d pos){
if(x>0&&foregroundTilesIncluded.find(vi2d{x,y}+vi2d{-1,0})==foregroundTilesIncluded.end())tileGroupChecks.push({x-1,y});
if(x<WORLD_SIZE.x-1&&foregroundTilesIncluded.find(vi2d{x,y}+vi2d{1,0})==foregroundTilesIncluded.end())tileGroupChecks.push({x+1,y});
if(y>0&&foregroundTilesIncluded.find(vi2d{x,y}+vi2d{0,-1})==foregroundTilesIncluded.end())tileGroupChecks.push({x,y-1});
if(y<WORLD_SIZE.y-1&&foregroundTilesIncluded.find(vi2d{x,y}+vi2d{0,1})==foregroundTilesIncluded.end())tileGroupChecks.push({x,y+1});
auto IterateThroughOtherLayers=[&](vi2d pos,bool loopAll=false){
int layer2ID=0;
bool hadForeground=false;
for(LayerTag&layer2:MAP_DATA[currentLevel].LayerData){
if(&layer==&layer2)continue;
if(!loopAll&&&layer==&layer2){layer2ID++;continue;};
int tileID=layer2.tiles[pos.y][pos.x]-1;
TilesheetData tileSheet=GetTileSheet(currentLevel,tileID);
int tileSheetWidth=tileSheet.tileset.tileset->Sprite()->width/24;
@ -920,45 +921,61 @@ void Crawler::LoadLevel(MapName map){
int tileSheetIndex=tileID-(tileSheet.firstgid-1);
int tileSheetX=tileSheetIndex%tileSheetWidth;
int tileSheetY=tileSheetIndex/tileSheetWidth;
TileRenderData tile={tileSheet.tileset.tileset->Decal(),vi2d{pos.x,pos.y}*24,vi2d{tileSheetX,tileSheetY}*24};
TileRenderData tile={tileSheet.tileset.tileset->Decal(),vi2d{pos.x,pos.y}*24,vi2d{tileSheetX,tileSheetY}*24,layer2ID};
if(IsForeground(tileSheet,tileSheetIndex)){
foregroundTilesIncluded.insert({pos.x,pos.y});
group.InsertTile(tile);
hadForeground=true;
}
layer2ID++;
}
return hadForeground;
};
IterateThroughOtherLayers({x,y});
while(!tileGroupChecks.empty()){
vi2d&pos=tileGroupChecks.front();
tileGroupChecks.pop();
int tileID=layer.tiles[pos.y][pos.x]-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;
TileRenderData tile={tileSheet.tileset.tileset->Decal(),pos*24,vi2d{tileSheetX,tileSheetY}*24};
if(IsForeground(tileSheet,tileSheetIndex)&&foregroundTilesIncluded.find(pos)==foregroundTilesIncluded.end()){
foregroundTilesIncluded.insert(pos);
group.InsertTile(tile);
if(pos.x>0)tileGroupChecks.push(pos+vi2d{-1,0});
if(pos.x<WORLD_SIZE.x-1)tileGroupChecks.push(pos+vi2d{1,0});
if(pos.y>0)tileGroupChecks.push(pos+vi2d{0,-1});
if(pos.y<WORLD_SIZE.y-1)tileGroupChecks.push(pos+vi2d{0,1});
IterateThroughOtherLayers(pos);
if(IterateThroughOtherLayers(pos,true)){
foregroundTilesIncluded.insert({pos.x,pos.y}); //Regardless of if we found a foreground tile or not, we need to add this to not get stuck in an infinite loop.
vi2d targetPos=pos+vi2d{-1,0};
if(pos.x>0&&foregroundTilesIncluded.find(targetPos)==foregroundTilesIncluded.end()){tileGroupChecks.push(targetPos);foregroundTilesIncluded.insert(targetPos);}
targetPos=pos+vi2d{1,0};
if(pos.x<WORLD_SIZE.x-1&&foregroundTilesIncluded.find(targetPos)==foregroundTilesIncluded.end()){tileGroupChecks.push(targetPos);foregroundTilesIncluded.insert(targetPos);}
targetPos=pos+vi2d{0,-1};
if(pos.y>0&&foregroundTilesIncluded.find(targetPos)==foregroundTilesIncluded.end()){tileGroupChecks.push(targetPos);foregroundTilesIncluded.insert(targetPos);}
targetPos=pos+vi2d{0,1};
if(pos.y<WORLD_SIZE.y-1&&foregroundTilesIncluded.find(targetPos)==foregroundTilesIncluded.end()){tileGroupChecks.push(targetPos);foregroundTilesIncluded.insert(targetPos);}
}
tileGroupChecks.pop();
}
groups.push_back(group);
}
};
TileRenderData tile={tileSheet.tileset.tileset->Decal(),vi2d{x,y}*24,vi2d{tileSheetX,tileSheetY}*24};
TileRenderData tile={tileSheet.tileset.tileset->Decal(),vi2d{x,y}*24,vi2d{tileSheetX,tileSheetY}*24,layerID};
SetupTileGroups([&](TilesheetData sheet,int tileID){return IsForegroundTile(sheet,tileID);},tile,foregroundTilesAdded,foregroundTileGroups);
SetupTileGroups([&](TilesheetData sheet,int tileID){return IsUpperForegroundTile(sheet,tileID);},tile,upperForegroundTilesAdded,upperForegroundTileGroups);
#pragma endregion
}
layerID++;
}
}
}
for(TileGroup&group:foregroundTileGroups){
for(TileRenderData&dat:group.GetTiles()){
if(dat.pos==vi2d{165,124}*24){
std::cout<<dat.layerID<<std::endl;
std::cout<<"=========="<<std::endl<<"After Sort:"<<std::endl;
}
}
std::sort(group.GetTiles().begin(),group.GetTiles().end(),[](TileRenderData&t1,TileRenderData&t2){return t1.layerID<t2.layerID;});
for(TileRenderData&dat:group.GetTiles()){
if(dat.pos==vi2d{165,124}*24){
std::cout<<dat.layerID<<std::endl;
}
}
}
for(TileGroup&group:upperForegroundTileGroups){
std::sort(group.GetTiles().begin(),group.GetTiles().end(),[](TileRenderData&t1,TileRenderData&t2){return t1.layerID<t2.layerID;});
}
int counter=0;

@ -26,6 +26,7 @@ struct TileRenderData{
Decal*tileset;
vi2d pos;
vi2d tileSheetPos;
int layerID;
};
struct TileGroup{
@ -44,5 +45,4 @@ public:
void InsertTile(TileRenderData tile);
bool playerBehind=false;
float fadeFactor=0.f;
int originatingLayer=-1;
};

@ -223,10 +223,6 @@ typedef std::map<std::string,std::vector<geom2d::rect<int>>> ZoneData;
LayerTag l = {newTag};
parsedMapInfo.LayerData.push_back(l);
}else
if (newTag.tag=="object"&&newTag.data["type"]=="UpperSpawnGroup") {
parsedMapInfo.SpawnerData[newTag.GetInteger("id")]={newTag};
parsedMapInfo.SpawnerData[newTag.GetInteger("id")].upperLevel=true;
} else
if (newTag.tag=="object"&&newTag.data["type"]=="SpawnGroup") {
parsedMapInfo.SpawnerData[newTag.GetInteger("id")]={newTag};
} else
@ -318,6 +314,23 @@ typedef std::map<std::string,std::vector<geom2d::rect<int>>> ZoneData;
for(XMLTag&monster:accumulatedMonsterTags){
parsedMapInfo.SpawnerData[monster.GetInteger("spawnerLink")].monsters.push_back(monster);
}
for(auto&spawnerData:parsedMapInfo.SpawnerData){
SpawnerTag&spawner=spawnerData.second;
for(auto&zoneData:parsedMapInfo.ZoneData){
if(zoneData.first=="UpperZone"){
std::vector<geom2d::rect<int>>&zones=zoneData.second;
for(geom2d::rect<int>&zone:zones){
if(geom2d::overlaps(zone,geom2d::rect<int>{{spawner.ObjectData.GetInteger("x"),spawner.ObjectData.GetInteger("y")},{spawner.ObjectData.GetInteger("width"),spawner.ObjectData.GetInteger("height")}})){
spawner.upperLevel=true;
goto continueSpawnerLoop;
}
}
}
}
continueSpawnerLoop:
continue;
}
std::cout<<"Parsed Map Data:\n"<<parsedMapInfo<<"\n";
}
#endif

@ -2,7 +2,7 @@
#define VERSION_MAJOR 0
#define VERSION_MINOR 2
#define VERSION_PATCH 0
#define VERSION_BUILD 1147
#define VERSION_BUILD 1172
#define stringify(a) stringify_(a)
#define stringify_(a) #a

@ -211,7 +211,7 @@
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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="2" name="Layer 2" width="205" height="205">
<layer id="2" name="Layer 2" width="205" height="205" opacity="0.99">
<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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

@ -63,7 +63,7 @@ MonsterStrategy
# How far away the monster starts shooting from
Range = 800
# How often the enemy shoots.
ShootingSpeed = 0.6
ShootingSpeed = 2
BulletSpeed = 450
BulletSize = 30
BulletColor = 0, 255, 0, 255

Loading…
Cancel
Save