diff --git a/Crawler/Crawler.cpp b/Crawler/Crawler.cpp index 5231d031..29756e52 100644 --- a/Crawler/Crawler.cpp +++ b/Crawler/Crawler.cpp @@ -91,7 +91,7 @@ bool Crawler::OnUserCreate(){ camera=Camera2D{WINDOW_SIZE}; camera.SetMode(olc::utils::Camera2D::Mode::LazyFollow); camera.SetTarget(player->GetPos()); - camera.SetWorldBoundary({0,0},WORLD_SIZE*24); + camera.SetWorldBoundary({0,0},GetCurrentMap().MapSize*24); camera.EnableWorldBoundary(false); InitializeGraphics(); @@ -612,7 +612,7 @@ void Crawler::RenderWorld(float fElapsedTime){ SetDecalMode(DecalMode::ADDITIVE); float reflectionHeight=(float(player->GetFrame().GetSourceRect().size.y)-8)*player->GetSizeMult(); float reflectionBottom=player->GetPos().y+reflectionHeight; - float cutOff=reflectionBottom-WORLD_SIZE.y*24; + float cutOff=reflectionBottom-GetCurrentMap().height*24; float multiplierX=0.9; multiplierX*=(1-abs(sin(reflectionStepTime))*"water_reflection_scale_factor"_F); multiplierX*=(1-abs(cos(1.5*reflectionStepTime))*"water_reflection_scale_factor"_F); @@ -625,7 +625,7 @@ void Crawler::RenderWorld(float fElapsedTime){ } 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&&y=0&&x=0&&y=0&&x=0&&y=0&&x=0&&ytiles[y][x]-1; if(tileID!=-1){ TilesheetData tileSheet=GetTileSheet(currentLevel,tileID); @@ -1150,7 +1151,6 @@ void Crawler::LoadLevel(MapName map){ SPAWNER_LIST.clear(); foregroundTileGroups.clear(); currentLevel=map; - WORLD_SIZE={MAP_DATA[map].MapData.width,MAP_DATA[map].MapData.height}; levelTime=0; bossName=""; encounterDuration=0; @@ -1204,8 +1204,8 @@ void Crawler::LoadLevel(MapName map){ #pragma region Foreground and Upper Foreground Tile Fade Group Setup std::setforegroundTilesAdded,upperForegroundTilesAdded; - for(int x=0;x0&&foregroundTilesIncluded.find(vi2d{x,y}+vi2d{-1,0})==foregroundTilesIncluded.end())tileGroupChecks.push({x-1,y}); - if(x0&&foregroundTilesIncluded.find(vi2d{x,y}+vi2d{0,-1})==foregroundTilesIncluded.end())tileGroupChecks.push({x,y-1}); - if(y0&&foregroundTilesIncluded.find(targetPos)==foregroundTilesIncluded.end()){tileGroupChecks.push(targetPos);foregroundTilesIncluded.insert(targetPos);} targetPos=pos+vi2d{1,0}; - if(pos.x0&&foregroundTilesIncluded.find(targetPos)==foregroundTilesIncluded.end()){tileGroupChecks.push(targetPos);foregroundTilesIncluded.insert(targetPos);} targetPos=pos+vi2d{0,1}; - if(pos.y=1000000; } @@ -1356,7 +1352,7 @@ bool Crawler::IsBridgeLayer(LayerTag&layer){ } geom2d::rectCrawler::GetTileCollision(MapName map,vf2d pos,bool upperLevel){ - if(pos.x<0||pos.y<0||pos.x>=WORLD_SIZE.x*24||pos.y>=WORLD_SIZE.y*24)return NO_COLLISION; + if(pos.x<0||pos.y<0||pos.x>=GetCurrentMap().width*24||pos.y>=GetCurrentMap().height*24)return NO_COLLISION; #pragma region Lower Bridge Collision Check if(!upperLevel){ //We are looking for lower bridge collisions. for(geom2d::rect&zone:MAP_DATA[map].ZoneData["LowerBridgeCollision"]){ @@ -1738,4 +1734,8 @@ void Crawler::InitializeGraphics(){ std::cout<NO_COLLISION={}; - vi2d WORLD_SIZE={120,8}; TileTransformedView view; void InitializeLevel(std::string mapFile,MapName map); void LoadLevel(MapName map); @@ -91,7 +90,6 @@ public: bool DownReleased(); Player*GetPlayer(); void SetupWorldShake(float duration); - vi2d GetWorldSize(); //tileID is the tile number from the tilesets. bool IsForegroundTile(TilesheetData sheet,int tileID); //tileID is the tile number from the tilesets. @@ -131,6 +129,7 @@ public: void BossDamageDealt(int damage); void ReduceBossEncounterMobCount(); void InitializeGraphics(); + MapTag GetCurrentMap(); struct TileGroupData{ vi2d tilePos; diff --git a/Crawler/Monster.cpp b/Crawler/Monster.cpp index ced39ee0..48f63c33 100644 --- a/Crawler/Monster.cpp +++ b/Crawler/Monster.cpp @@ -78,14 +78,14 @@ bool Monster::SetX(float x){ vi2d tilePos=vi2d(newPos/24)*24; geom2d::rectcollisionRect=game->GetTileCollision(game->GetCurrentLevel(),newPos,upperLevel); if(collisionRect.pos==vi2d{0,0}&&collisionRect.size==vi2d{1,1}){ - pos.x=std::clamp(x,12.f*GetSizeMult(),float(game->WORLD_SIZE.x*24-12*GetSizeMult())); + pos.x=std::clamp(x,12.f*GetSizeMult(),float(game->GetCurrentMap().width*24-12*GetSizeMult())); Moved(); return true; } else { geom2d::rectcollision={collisionRect.pos,collisionRect.size}; collision.pos+=tilePos; if(!geom2d::overlaps(geom2d::circle(newPos,12*GetSizeMult()),collision)){ - pos.x=std::clamp(x,12.f*GetSizeMult(),float(game->WORLD_SIZE.x*24-12*GetSizeMult())); + pos.x=std::clamp(x,12.f*GetSizeMult(),float(game->GetCurrentMap().width*24-12*GetSizeMult())); Moved(); return true; } @@ -97,14 +97,14 @@ bool Monster::SetY(float y){ vi2d tilePos=vi2d(newPos/24)*24; geom2d::rectcollisionRect=game->GetTileCollision(game->GetCurrentLevel(),newPos,upperLevel); if(collisionRect.pos==vi2d{0,0}&&collisionRect.size==vi2d{1,1}){ - pos.y=std::clamp(y,12.f*GetSizeMult(),float(game->WORLD_SIZE.y*24-12*GetSizeMult())); + pos.y=std::clamp(y,12.f*GetSizeMult(),float(game->GetCurrentMap().height*24-12*GetSizeMult())); Moved(); return true; } else { geom2d::rectcollision={collisionRect.pos,collisionRect.size}; collision.pos+=tilePos; if(!geom2d::overlaps(geom2d::circle(newPos,12*GetSizeMult()),collision)){ - pos.y=std::clamp(y,12.f*GetSizeMult(),float(game->WORLD_SIZE.y*24-12*GetSizeMult())); + pos.y=std::clamp(y,12.f*GetSizeMult(),float(game->GetCurrentMap().height*24-12*GetSizeMult())); Moved(); return true; } diff --git a/Crawler/Pathfinding.cpp b/Crawler/Pathfinding.cpp index a1c7a646..7a49ddfd 100644 --- a/Crawler/Pathfinding.cpp +++ b/Crawler/Pathfinding.cpp @@ -8,68 +8,68 @@ void Pathfinding::Initialize(){ if(nodes!=nullptr){ delete[] nodes; } - nodes = new sNode[game->WORLD_SIZE.x * game->WORLD_SIZE.y]; - for (int x = 0; x < game->WORLD_SIZE.x; x++) - for (int y = 0; y < game->WORLD_SIZE.y; y++) + nodes = new sNode[game->GetCurrentMap().width * game->GetCurrentMap().height]; + for (int x = 0; x < game->GetCurrentMap().width; x++) + for (int y = 0; y < game->GetCurrentMap().height; y++) { - nodes[y * game->WORLD_SIZE.x + x].x = x; // ...because we give each node its own coordinates - nodes[y * game->WORLD_SIZE.x + x].y = y; + nodes[y * game->GetCurrentMap().width + x].x = x; // ...because we give each node its own coordinates + nodes[y * game->GetCurrentMap().width + x].y = y; geom2d::recttile=game->GetTileCollision(game->GetCurrentLevel(),{float(x*24),float(y*24)}); - nodes[y * game->WORLD_SIZE.x + x].bObstacle = tile.pos!=game->NO_COLLISION.pos||tile.size!=game->NO_COLLISION.size; + nodes[y * game->GetCurrentMap().width + x].bObstacle = tile.pos!=game->NO_COLLISION.pos||tile.size!=game->NO_COLLISION.size; tile=game->GetTileCollision(game->GetCurrentLevel(),{float(x*24),float(y*24)},true); - nodes[y * game->WORLD_SIZE.x + x].bObstacleUpper = tile.pos!=game->NO_COLLISION.pos||tile.size!=game->NO_COLLISION.size; - nodes[y * game->WORLD_SIZE.x + x].parent = nullptr; - nodes[y * game->WORLD_SIZE.x + x].bVisited = false; + nodes[y * game->GetCurrentMap().width + x].bObstacleUpper = tile.pos!=game->NO_COLLISION.pos||tile.size!=game->NO_COLLISION.size; + nodes[y * game->GetCurrentMap().width + x].parent = nullptr; + nodes[y * game->GetCurrentMap().width + x].bVisited = false; } - for (int x = 0; x < game->WORLD_SIZE.x; x++) - for (int y = 0; y < game->WORLD_SIZE.y; y++) + for (int x = 0; x < game->GetCurrentMap().width; x++) + for (int y = 0; y < game->GetCurrentMap().height; y++) { if(y>0) - nodes[y*game->WORLD_SIZE.x + x].vecNeighbours.push_back(&nodes[(y - 1) * game->WORLD_SIZE.x + (x + 0)]); - if(yWORLD_SIZE.y-1) - nodes[y*game->WORLD_SIZE.x + x].vecNeighbours.push_back(&nodes[(y + 1) * game->WORLD_SIZE.x + (x + 0)]); + nodes[y*game->GetCurrentMap().width + x].vecNeighbours.push_back(&nodes[(y - 1) * game->GetCurrentMap().width + (x + 0)]); + if(yGetCurrentMap().height-1) + nodes[y*game->GetCurrentMap().width + x].vecNeighbours.push_back(&nodes[(y + 1) * game->GetCurrentMap().width + (x + 0)]); if (x>0) - nodes[y*game->WORLD_SIZE.x + x].vecNeighbours.push_back(&nodes[(y + 0) * game->WORLD_SIZE.x + (x - 1)]); - if(xWORLD_SIZE.x-1) - nodes[y*game->WORLD_SIZE.x + x].vecNeighbours.push_back(&nodes[(y + 0) * game->WORLD_SIZE.x + (x + 1)]); + nodes[y*game->GetCurrentMap().width + x].vecNeighbours.push_back(&nodes[(y + 0) * game->GetCurrentMap().width + (x - 1)]); + if(xGetCurrentMap().width-1) + nodes[y*game->GetCurrentMap().width + x].vecNeighbours.push_back(&nodes[(y + 0) * game->GetCurrentMap().width + (x + 1)]); if (y>0 && x>0) - nodes[y*game->WORLD_SIZE.x + x].vecNeighbours.push_back(&nodes[(y - 1) * game->WORLD_SIZE.x + (x - 1)]); - if (yWORLD_SIZE.y-1 && x>0) - nodes[y*game->WORLD_SIZE.x + x].vecNeighbours.push_back(&nodes[(y + 1) * game->WORLD_SIZE.x + (x - 1)]); - if (y>0 && xWORLD_SIZE.x-1) - nodes[y*game->WORLD_SIZE.x + x].vecNeighbours.push_back(&nodes[(y - 1) * game->WORLD_SIZE.x + (x + 1)]); - if (yWORLD_SIZE.y - 1 && xWORLD_SIZE.x-1) - nodes[y*game->WORLD_SIZE.x + x].vecNeighbours.push_back(&nodes[(y + 1) * game->WORLD_SIZE.x + (x + 1)]); + nodes[y*game->GetCurrentMap().width + x].vecNeighbours.push_back(&nodes[(y - 1) * game->GetCurrentMap().width + (x - 1)]); + if (yGetCurrentMap().height-1 && x>0) + nodes[y*game->GetCurrentMap().width + x].vecNeighbours.push_back(&nodes[(y + 1) * game->GetCurrentMap().width + (x - 1)]); + if (y>0 && xGetCurrentMap().width-1) + nodes[y*game->GetCurrentMap().width + x].vecNeighbours.push_back(&nodes[(y - 1) * game->GetCurrentMap().width + (x + 1)]); + if (yGetCurrentMap().height - 1 && xGetCurrentMap().width-1) + nodes[y*game->GetCurrentMap().width + x].vecNeighbours.push_back(&nodes[(y + 1) * game->GetCurrentMap().width + (x + 1)]); } // Manually position the start and end markers so they are not nullptr - nodeStart = &nodes[(game->WORLD_SIZE.y / 2) * game->WORLD_SIZE.x + 1]; - nodeEnd = &nodes[(game->WORLD_SIZE.y / 2) * game->WORLD_SIZE.x + game->WORLD_SIZE.x-2]; + nodeStart = &nodes[(game->GetCurrentMap().height / 2) * game->GetCurrentMap().width + 1]; + nodeEnd = &nodes[(game->GetCurrentMap().height / 2) * game->GetCurrentMap().width + game->GetCurrentMap().width-2]; } std::vector Pathfinding::Solve_AStar(vf2d startPos,vf2d endPos,float maxRange,bool upperLevel){ float dist=sqrt(pow(endPos.x-startPos.x,2)+pow(endPos.y-startPos.y,2)); if(dist>maxRange*24)return {}; - nodeStart=&nodes[int(startPos.y/24)*game->WORLD_SIZE.x+int(startPos.x/24)]; - nodeEnd=&nodes[int(endPos.y/24)*game->WORLD_SIZE.x+int(endPos.x/24)]; + nodeStart=&nodes[int(startPos.y/24)*game->GetCurrentMap().width+int(startPos.x/24)]; + nodeEnd=&nodes[int(endPos.y/24)*game->GetCurrentMap().width+int(endPos.x/24)]; geom2d::rectposPerimeter{{int(std::min(startPos.x,endPos.x)),int(std::min(startPos.y,endPos.y))},{int(abs(endPos.x-startPos.x)),int(abs(endPos.y-startPos.y))}}; - posPerimeter.pos={int(std::clamp(posPerimeter.pos.x-maxRange*24,0.f,game->WORLD_SIZE.x*24.f)),int(std::clamp(posPerimeter.pos.y-maxRange*24,0.f,game->WORLD_SIZE.y*24.f))}; - posPerimeter.size={int(std::clamp(posPerimeter.size.x+maxRange*24*2,0.f,game->WORLD_SIZE.x*24.f-posPerimeter.pos.x)),int(std::clamp(posPerimeter.size.y+maxRange*24*2,0.f,game->WORLD_SIZE.y*24.f-posPerimeter.pos.y))}; + posPerimeter.pos={int(std::clamp(posPerimeter.pos.x-maxRange*24,0.f,game->GetCurrentMap().width*24.f)),int(std::clamp(posPerimeter.pos.y-maxRange*24,0.f,game->GetCurrentMap().height*24.f))}; + posPerimeter.size={int(std::clamp(posPerimeter.size.x+maxRange*24*2,0.f,game->GetCurrentMap().width*24.f-posPerimeter.pos.x)),int(std::clamp(posPerimeter.size.y+maxRange*24*2,0.f,game->GetCurrentMap().height*24.f-posPerimeter.pos.y))}; - for (int x = 0; x < game->WORLD_SIZE.x; x++){ - for (int y = 0; y < game->WORLD_SIZE.y; y++){ + for (int x = 0; x < game->GetCurrentMap().width; x++){ + for (int y = 0; y < game->GetCurrentMap().height; y++){ if(geom2d::overlaps(posPerimeter,vi2d{x*24,y*24})){ - nodes[y*game->WORLD_SIZE.x + x].bVisited = false; + nodes[y*game->GetCurrentMap().width + x].bVisited = false; } else { - nodes[y*game->WORLD_SIZE.x + x].bVisited = true; + nodes[y*game->GetCurrentMap().width + x].bVisited = true; } - nodes[y*game->WORLD_SIZE.x + x].fGlobalGoal = INFINITY; - nodes[y*game->WORLD_SIZE.x + x].fLocalGoal = INFINITY; - nodes[y*game->WORLD_SIZE.x + x].parent = nullptr; // No parents + nodes[y*game->GetCurrentMap().width + x].fGlobalGoal = INFINITY; + nodes[y*game->GetCurrentMap().width + x].fLocalGoal = INFINITY; + nodes[y*game->GetCurrentMap().width + x].parent = nullptr; // No parents } } diff --git a/Crawler/Player.cpp b/Crawler/Player.cpp index ab393d70..ef4083b8 100644 --- a/Crawler/Player.cpp +++ b/Crawler/Player.cpp @@ -49,7 +49,7 @@ bool Player::SetX(float x){ auto NoTileCollisionExistsHere=[&](){return collisionRect.pos==game->NO_COLLISION.pos&&collisionRect.size==game->NO_COLLISION.size;}; #pragma endregion if(NoTileCollisionExistsHere()){ - pos.x=std::clamp(x,12.f*GetSizeMult(),float(game->WORLD_SIZE.x*24-12*GetSizeMult())); + pos.x=std::clamp(x,12.f*GetSizeMult(),float(game->GetCurrentMap().width*24-12*GetSizeMult())); Moved(); return true; } else { @@ -59,7 +59,7 @@ bool Player::SetX(float x){ #pragma endregion collision.pos+=tilePos; if(NoPlayerCollisionWithTile()){ - pos.x=std::clamp(x,12.f*GetSizeMult(),float(game->WORLD_SIZE.x*24-12*GetSizeMult())); + pos.x=std::clamp(x,12.f*GetSizeMult(),float(game->GetCurrentMap().width*24-12*GetSizeMult())); Moved(); return true; } @@ -75,7 +75,7 @@ bool Player::SetY(float y){ auto NoTileCollisionExistsHere=[&](){return collisionRect.pos==game->NO_COLLISION.pos&&collisionRect.size==game->NO_COLLISION.size;}; #pragma endregion if(NoTileCollisionExistsHere()){ - pos.y=std::clamp(y,12.f*GetSizeMult(),float(game->WORLD_SIZE.y*24-12*GetSizeMult())); + pos.y=std::clamp(y,12.f*GetSizeMult(),float(game->GetCurrentMap().height*24-12*GetSizeMult())); Moved(); return true; } else { @@ -85,7 +85,7 @@ bool Player::SetY(float y){ #pragma endregion collision.pos+=tilePos; if(NoPlayerCollisionWithTile()){ - pos.y=std::clamp(y,12.f*GetSizeMult(),float(game->WORLD_SIZE.y*24-12*GetSizeMult())); + pos.y=std::clamp(y,12.f*GetSizeMult(),float(game->GetCurrentMap().height*24-12*GetSizeMult())); Moved(); return true; } @@ -662,6 +662,7 @@ CastInfo&Player::GetCastInfo(){ } bool Player::CanPathfindTo(vf2d pos,vf2d targetPos,float range){ + if(targetPos.x<0||targetPos.y<0||targetPos.x>game->GetCurrentMap().width*game->GetCurrentMap().tilewidth||targetPos.y>game->GetCurrentMap().height*game->GetCurrentMap().tileheight)return false; std::vectorpathing=game->pathfinder.Solve_AStar(pos,targetPos,range,upperLevel); return pathing.size()>0&&pathing.size()=5){ m.I(A::PHASE_REPEAT_COUNT)=0; - float jumpAngle=util::angleTo(m.GetPos(),game->GetWorldSize()*24/2); //We jump towards the center to keep the player from constantly dealing with a stuck boss. + float jumpAngle=util::angleTo(m.GetPos(),game->GetCurrentMap().MapSize*24/2); //We jump towards the center to keep the player from constantly dealing with a stuck boss. float jumpDistance=ConfigFloat("Phase4.JumpDistance")/100*24; float jumpSpd=jumpDistance/ConfigFloat("Phase4.JumpDuration"); StartJump(ConfigFloat("Phase4.JumpDuration"),m.GetPos()+vf2d{cos(jumpAngle)*jumpDistance,sin(jumpAngle)*jumpDistance},0,jumpSpd); diff --git a/Crawler/TMXParser.h b/Crawler/TMXParser.h index e47d9ddc..72c62b89 100644 --- a/Crawler/TMXParser.h +++ b/Crawler/TMXParser.h @@ -19,7 +19,12 @@ struct XMLTag{ struct MapTag{ int width=0,height=0; + int tilewidth=0,tileheight=0; vi2d playerSpawnLocation; + vi2d MapSize; //The number of tiles in width and height of this map. + vi2d TileSize; //How large in pixels the map's tiles are. + MapTag(); + MapTag(int width,int height,int tilewidth,int tileheight); friend std::ostream& operator << (std::ostream& os, MapTag& rhs); }; @@ -88,7 +93,7 @@ typedef std::map>> ZoneData; } std::ostream& operator << (std::ostream& os, MapTag& rhs){ os << - "(width:"<>> ZoneData; return true; } } + MapTag::MapTag(){} + MapTag::MapTag(int width,int height,int tilewidth,int tileheight) + :width(width),height(height),tilewidth(tilewidth),tileheight(tileheight),MapSize({width,height}),TileSize({tilewidth,tileheight}){} std::string XMLTag::str() { return tag+"\n"; } @@ -217,7 +225,7 @@ typedef std::map>> ZoneData; infiniteMap=true; return; } - parsedMapInfo.MapData={stoi(newTag.data["width"]),stoi(newTag.data["height"])}; + parsedMapInfo.MapData={stoi(newTag.data["width"]),stoi(newTag.data["height"]),stoi(newTag.data["tilewidth"]),stoi(newTag.data["tileheight"])}; } else if (newTag.tag=="tileset") { parsedMapInfo.TilesetData.push_back(newTag); diff --git a/Crawler/Version.h b/Crawler/Version.h index 7efdda34..378b486b 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 1719 +#define VERSION_BUILD 1735 #define stringify(a) stringify_(a) #define stringify_(a) #a