diff --git a/Crawler/ClassDiagram2.cd b/Crawler/ClassDiagram2.cd index 30adf5c5..37e947b4 100644 --- a/Crawler/ClassDiagram2.cd +++ b/Crawler/ClassDiagram2.cd @@ -197,7 +197,9 @@ - + AAAAIAAAAAAAAAAAAAAEAAAAAAEAAAAAAAAQAAAAAAA= olcUTIL_DataFile.h diff --git a/Crawler/Crawler.cpp b/Crawler/Crawler.cpp index 29756e52..26cb2e01 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},GetCurrentMap().MapSize*24); + camera.SetWorldBoundary({0,0},GetCurrentMap().MapSize*GetCurrentMap().TileSize); camera.EnableWorldBoundary(false); InitializeGraphics(); @@ -199,8 +199,8 @@ void Crawler::HandleUserInput(float fElapsedTime){ if(player->GetVelocity()==vf2d{0,0}&&player->CanMove()){ auto GetPlayerStaircaseDirection=[&](){ for(LayerTag&layer:MAP_DATA[GetCurrentLevel()].LayerData){ - int truncatedPlayerX=int(player->GetX())/24; - int truncatedPlayerY=int(player->GetY())/24; + int truncatedPlayerX=int(player->GetX())/game->GetCurrentMap().tilewidth; + int truncatedPlayerY=int(player->GetY())/game->GetCurrentMap().tilewidth; int tileID=layer.tiles[truncatedPlayerY][truncatedPlayerX]; TilesheetData dat=GetTileSheet(GetCurrentLevel(),tileID); if (dat.tileset->staircaseTiles.find(tileID)!=dat.tileset->staircaseTiles.end()){ @@ -547,12 +547,12 @@ void Crawler::RenderTile(vi2d pos,TilesheetData tileSheet,int tileSheetIndex,vi2 if(tileSheet.tileset->animationData.count(tileSheetIndex)){ int animationDuration_ms=tileSheet.tileset->animationData[tileSheetIndex].size()*"animation_tile_precision"_I; int animatedIndex=tileSheet.tileset->animationData[tileSheetIndex][int(fmod(levelTime*1000,animationDuration_ms)/"animation_tile_precision"_I)]; - int tileSheetWidth=tileSheet.tileset->tileset->Sprite()->width/24; + int tileSheetWidth=tileSheet.tileset->tileset->Sprite()->width/tileSheet.tileset->tilewidth; int tileSheetX=animatedIndex%tileSheetWidth; int tileSheetY=animatedIndex/tileSheetWidth; - view.DrawPartialDecal(pos*24,{24,24},tileSheet.tileset->tileset->Decal(),vi2d{tileSheetX,tileSheetY}*24,{24,24}); + view.DrawPartialDecal(pos*game->GetCurrentMap().tilewidth,{float(tileSheet.tileset->tilewidth),float(tileSheet.tileset->tileheight)},tileSheet.tileset->tileset->Decal(),vi2d{tileSheetX,tileSheetY}*tileSheet.tileset->tilewidth,{float(tileSheet.tileset->tilewidth),float(tileSheet.tileset->tileheight)}); }else{ - view.DrawPartialDecal(pos*24,{24,24},tileSheet.tileset->tileset->Decal(),tileSheetPos*24,{24,24}); + view.DrawPartialDecal(pos*game->GetCurrentMap().tilewidth,{float(tileSheet.tileset->tilewidth),float(tileSheet.tileset->tileheight)},tileSheet.tileset->tileset->Decal(),tileSheetPos*tileSheet.tileset->tilewidth,{float(tileSheet.tileset->tilewidth),float(tileSheet.tileset->tileheight)}); } } @@ -560,12 +560,12 @@ void Crawler::RenderTile(TileRenderData&tileSheet,Pixel col){ if(tileSheet.tileSheet.tileset->animationData.count(tileSheet.tileID%1000000)){ int animationDuration_ms=tileSheet.tileSheet.tileset->animationData[tileSheet.tileID%1000000].size()*"animation_tile_precision"_I; int animatedIndex=tileSheet.tileSheet.tileset->animationData[tileSheet.tileID%1000000][int(fmod(levelTime*1000,animationDuration_ms)/"animation_tile_precision"_I)]; - int tileSheetWidth=tileSheet.tileSheet.tileset->tileset->Sprite()->width/24; + int tileSheetWidth=tileSheet.tileSheet.tileset->tileset->Sprite()->width/tileSheet.tileSheet.tileset->tilewidth; int tileSheetX=animatedIndex%tileSheetWidth; int tileSheetY=animatedIndex/tileSheetWidth; - view.DrawPartialDecal(tileSheet.pos,{24,24},tileSheet.tileSheet.tileset->tileset->Decal(),vi2d{tileSheetX,tileSheetY},{24,24},col); + view.DrawPartialDecal(tileSheet.pos,{float(tileSheet.tileSheet.tileset->tilewidth),float(tileSheet.tileSheet.tileset->tileheight)},tileSheet.tileSheet.tileset->tileset->Decal(),vi2d{tileSheetX,tileSheetY},{float(tileSheet.tileSheet.tileset->tilewidth),float(tileSheet.tileSheet.tileset->tileheight)},col); }else{ - view.DrawPartialDecal(tileSheet.pos,{24,24},tileSheet.tileSheet.tileset->tileset->Decal(),tileSheet.tileSheetPos,{24,24},col); + view.DrawPartialDecal(tileSheet.pos,{float(tileSheet.tileSheet.tileset->tilewidth),float(tileSheet.tileSheet.tileset->tileheight)},tileSheet.tileSheet.tileset->tileset->Decal(),tileSheet.tileSheetPos,{float(tileSheet.tileSheet.tileset->tilewidth),float(tileSheet.tileSheet.tileset->tileheight)},col); } } @@ -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-GetCurrentMap().height*24; + float cutOff=reflectionBottom-GetCurrentMap().height*GetCurrentMap().tileheight; 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); @@ -623,8 +623,8 @@ void Crawler::RenderWorld(float fElapsedTime){ } SetDecalMode(DecalMode::NORMAL); } - 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++){ + for (int x = view.GetTopLeftTile().x/GetCurrentMap().tilewidth-1; x <= view.GetBottomRightTile().x/GetCurrentMap().tilewidth; x++){ + for (int y = view.GetTopLeftTile().y/GetCurrentMap().tilewidth-1; y <= view.GetBottomRightTile().y/GetCurrentMap().tilewidth; y++){ if(x>=0&&x=0&&yupperLevel){ int tileID=layer.tiles[y][x]-1; if(tileID!=-1){ - int playerXTruncated=int(player->GetPos().x)/24; - int playerYTruncated=int(player->GetPos().y)/24; + int playerXTruncated=int(player->GetPos().x)/GetCurrentMap().tilewidth; + int playerYTruncated=int(player->GetPos().y)/GetCurrentMap().tilewidth; if(playerXTruncated==x&&playerYTruncated==y){ bridgeLayerFade=true; } @@ -646,8 +646,8 @@ void Crawler::RenderWorld(float fElapsedTime){ 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 tileSheetWidth=tileSheet.tileset->tileset->Sprite()->width/tileSheet.tileset->tilewidth; + int tileSheetHeight=tileSheet.tileset->tileset->Sprite()->height/tileSheet.tileset->tileheight; int tileSheetIndex=tileID-(tileSheet.firstgid-1); int tileSheetX=tileSheetIndex%tileSheetWidth; int tileSheetY=tileSheetIndex/tileSheetWidth; @@ -657,8 +657,8 @@ void Crawler::RenderWorld(float fElapsedTime){ if("debug_collision_boxes"_I){ if(tileSheet.tileset->collision.find(tileSheetIndex)!=tileSheet.tileset->collision.end()){ geom2d::rectcollision=tileSheet.tileset->collision[tileSheetIndex].collision; - view.FillRectDecal(vi2d{x,y}*24+collision.pos,collision.size,{0,0,0,128}); - view.DrawRectDecal(vi2d{x,y}*24+collision.pos,collision.size,GREY); + view.FillRectDecal(vi2d{x,y}*GetCurrentMap().tilewidth+collision.pos,collision.size,{0,0,0,128}); + view.DrawRectDecal(vi2d{x,y}*GetCurrentMap().tilewidth+collision.pos,collision.size,GREY); } } } @@ -671,8 +671,8 @@ void Crawler::RenderWorld(float fElapsedTime){ 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 tileSheetWidth=tileSheet.tileset->tileset->Sprite()->width/tileSheet.tileset->tilewidth; + int tileSheetHeight=tileSheet.tileset->tileset->Sprite()->height/tileSheet.tileset->tileheight; int tileSheetIndex=tileID-(tileSheet.firstgid-1); int tileSheetX=tileSheetIndex%tileSheetWidth; int tileSheetY=tileSheetIndex/tileSheetWidth; @@ -683,8 +683,8 @@ void Crawler::RenderWorld(float fElapsedTime){ if("debug_collision_boxes"_I){ if(tileSheet.tileset->collision.find(tileSheetIndex)!=tileSheet.tileset->collision.end()){ geom2d::rectcollision=tileSheet.tileset->collision[tileSheetIndex].collision; - view.FillRectDecal(vi2d{x,y}*24+collision.pos,collision.size,{0,0,0,128}); - view.DrawRectDecal(vi2d{x,y}*24+collision.pos,collision.size,GREY); + view.FillRectDecal(vi2d{x,y}*GetCurrentMap().tilewidth+collision.pos,collision.size,{0,0,0,128}); + view.DrawRectDecal(vi2d{x,y}*GetCurrentMap().tilewidth+collision.pos,collision.size,GREY); } } } @@ -692,12 +692,12 @@ void Crawler::RenderWorld(float fElapsedTime){ }break; case RenderMode::EMPTY_TILES:{ if(visibleTiles.count({x,y})){ - view.FillRectDecal(vi2d{x,y}*24,{24,24},{100,180,100}); + view.FillRectDecal(vi2d{x,y}*GetCurrentMap().tilewidth,{float(GetCurrentMap().tilewidth),float(GetCurrentMap().tilewidth)},{100,180,100}); } }break; } }else{ - view.FillRectDecal(vi2d{x,y}*24,{24,24},{100,180,100}); + view.FillRectDecal(vi2d{x,y}*GetCurrentMap().tilewidth,{float(GetCurrentMap().tilewidth),float(GetCurrentMap().tilewidth)},{100,180,100}); } } } @@ -841,23 +841,23 @@ void Crawler::RenderWorld(float fElapsedTime){ #pragma region Bridge Layer Rendering if(bridgeLayer!=nullptr){ - 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++){ + for (int x = view.GetTopLeftTile().x/game->GetCurrentMap().tilewidth-1; x <= view.GetBottomRightTile().x/game->GetCurrentMap().tilewidth; x++){ + for (int y = view.GetTopLeftTile().y/game->GetCurrentMap().tilewidth-1; y <= view.GetBottomRightTile().y/game->GetCurrentMap().tilewidth; y++){ if(x>=0&&x=0&&ytiles[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 tileSheetWidth=tileSheet.tileset->tileset->Sprite()->width/tileSheet.tileset->tilewidth; + int tileSheetHeight=tileSheet.tileset->tileset->Sprite()->height/tileSheet.tileset->tileheight; int tileSheetIndex=tileID-(tileSheet.firstgid-1); int tileSheetX=tileSheetIndex%tileSheetWidth; int tileSheetY=tileSheetIndex/tileSheetWidth; - view.DrawPartialDecal(vi2d{x,y}*24,{24,24},tileSheet.tileset->tileset->Decal(),vi2d{tileSheetX,tileSheetY}*24,{24,24},{255,255,255,uint8_t(255-bridgeFadeFactor/TileGroup::FADE_TIME*TileGroup::FADE_AMT)}); + view.DrawPartialDecal(vi2d{x,y}*game->GetCurrentMap().tilewidth,{float(tileSheet.tileset->tilewidth),float(tileSheet.tileset->tileheight)},tileSheet.tileset->tileset->Decal(),vi2d{tileSheetX,tileSheetY}*game->GetCurrentMap().tilewidth,{float(tileSheet.tileset->tilewidth),float(tileSheet.tileset->tileheight)},{255,255,255,uint8_t(255-bridgeFadeFactor/TileGroup::FADE_TIME*TileGroup::FADE_AMT)}); #ifdef DEBUG_COLLISIONS if(tileSheet.tileset.collision.find(tileSheetIndex)!=tileSheet.tileset.collision.end()){ geom2d::rectcollision=tileSheet.tileset.collision[tileSheetIndex].collision; - view.FillRectDecal(vi2d{x,y}*24+collision.pos,collision.size,{0,0,0,128}); - view.DrawRectDecal(vi2d{x,y}*24+collision.pos,collision.size,GREY); + view.FillRectDecal(vi2d{x,y}*game->GetCurrentMap().tilewidth+collision.pos,collision.size,{0,0,0,128}); + view.DrawRectDecal(vi2d{x,y}*game->GetCurrentMap().tilewidth+collision.pos,collision.size,GREY); } #endif } @@ -990,7 +990,7 @@ void Crawler::RenderWorld(float fElapsedTime){ if(DEBUG_PATHFINDING){ std::vectorpathing=game->pathfinder.Solve_AStar(player.get()->GetPos(),GetWorldMousePos(),8,player.get()->OnUpperLevel()); for(vf2d&square:pathing){ - view.FillRectDecal(square*24,{24,24},DARK_GREEN); + view.FillRectDecal(square*game->GetCurrentMap().tilewidth,{float(game->GetCurrentMap().tilewidth),float(game->GetCurrentMap().tilewidth)},DARK_GREEN); } } } @@ -1134,6 +1134,8 @@ void Crawler::InitializeLevel(std::string mapFile,MapName map){ if(MAP_TILESETS.find("assets/maps/"+baseSourceDir)==MAP_TILESETS.end()){ TSXParser tileset(baseDir+tag.data["source"]); Renderable*r=new Renderable(); + MAP_TILESETS["assets/maps/"+baseSourceDir].tilewidth=tileset.GetData().tilewidth; + MAP_TILESETS["assets/maps/"+baseSourceDir].tileheight=tileset.GetData().tileheight; MAP_TILESETS["assets/maps/"+baseSourceDir].tileset=r; MAP_TILESETS["assets/maps/"+baseSourceDir].foregroundTiles=tileset.GetData().ForegroundTileData; MAP_TILESETS["assets/maps/"+baseSourceDir].upperForegroundTiles=tileset.GetData().UpperForegroundTileData; @@ -1183,10 +1185,10 @@ void Crawler::LoadLevel(MapName map){ }; for(geom2d::rect&zone:GetUpperZones()){ - int zoneX=zone.pos.x/24; //snap to grid - int zoneY=zone.pos.y/24; - int zoneW=zone.right().start.x/24-zoneX; - int zoneH=zone.bottom().start.y/24-zoneY; + int zoneX=zone.pos.x/game->GetCurrentMap().tilewidth; //snap to grid + int zoneY=zone.pos.y/game->GetCurrentMap().tilewidth; + int zoneW=zone.right().start.x/game->GetCurrentMap().tilewidth-zoneX; + int zoneH=zone.bottom().start.y/game->GetCurrentMap().tilewidth-zoneY; for(int x=zoneX;xtileset->Sprite()->width/24; - int tileSheetHeight=tileSheet.tileset->tileset->Sprite()->height/24; + int tileSheetWidth=tileSheet.tileset->tileset->Sprite()->width/tileSheet.tileset->tilewidth; + int tileSheetHeight=tileSheet.tileset->tileset->Sprite()->height/tileSheet.tileset->tileheight; int tileSheetIndex=tileID-(tileSheet.firstgid-1); int realTileSheetIndex=(tileID%1000000)-(tileSheet.firstgid-1); int tileSheetX=realTileSheetIndex%tileSheetWidth; @@ -1235,13 +1237,13 @@ void Crawler::LoadLevel(MapName map){ if(!loopAll&&&layer==&layer2){layer2ID++;continue;}; int tileID=layer2.tiles[pos.y][pos.x]-1; TilesheetData tileSheet=GetTileSheet(currentLevel,tileID%1000000); - int tileSheetWidth=tileSheet.tileset->tileset->Sprite()->width/24; - int tileSheetHeight=tileSheet.tileset->tileset->Sprite()->height/24; + int tileSheetWidth=tileSheet.tileset->tileset->Sprite()->width/tileSheet.tileset->tilewidth; + int tileSheetHeight=tileSheet.tileset->tileset->Sprite()->height/tileSheet.tileset->tileheight; int tileSheetIndex=tileID-(tileSheet.firstgid-1); int realTileSheetIndex=(tileID%1000000)-(tileSheet.firstgid-1); int tileSheetX=realTileSheetIndex%tileSheetWidth; int tileSheetY=realTileSheetIndex/tileSheetWidth; - TileRenderData tile={tileSheet,vi2d{pos.x,pos.y}*24,vi2d{tileSheetX,tileSheetY}*24,realTileSheetIndex,layer2ID}; + TileRenderData tile={tileSheet,vi2d{pos.x,pos.y}*game->GetCurrentMap().tilewidth,vi2d{tileSheetX,tileSheetY}*game->GetCurrentMap().tilewidth,realTileSheetIndex,layer2ID}; if(IsForeground(tileSheet,tileSheetIndex)){ foregroundTilesIncluded.insert({pos.x,pos.y}); group.InsertTile(tile); @@ -1270,7 +1272,7 @@ void Crawler::LoadLevel(MapName map){ groups.push_back(group); } }; - TileRenderData tile={tileSheet,vi2d{x,y}*24,vi2d{tileSheetX,tileSheetY}*24,tileID,layerID}; + TileRenderData tile={tileSheet,vi2d{x,y}*game->GetCurrentMap().tilewidth,vi2d{tileSheetX,tileSheetY}*game->GetCurrentMap().tilewidth,tileID,layerID}; SetupTileGroups([&](TilesheetData sheet,int tileID){return IsForegroundTile(sheet,tileID);},tile,foregroundTilesAdded,foregroundTileGroups); SetupTileGroups([&](TilesheetData sheet,int tileID){return IsUpperForegroundTile(tileID);},tile,upperForegroundTilesAdded,upperForegroundTileGroups); #pragma endregion @@ -1342,7 +1344,7 @@ TilesheetData Crawler::GetTileSheet(MapName map,int tileID){ bool Crawler::HasTileCollision(MapName map,vf2d pos,bool upperLevel){ geom2d::rectcollisionRect=GetTileCollision(map,pos,upperLevel); - vi2d collisionRectSnapPos=vi2d{pos/24}*24; + vi2d collisionRectSnapPos=vi2d{pos/game->GetCurrentMap().tilewidth}*game->GetCurrentMap().tilewidth; collisionRect.pos+=collisionRectSnapPos; return geom2d::overlaps(collisionRect,pos); } @@ -1352,19 +1354,19 @@ bool Crawler::IsBridgeLayer(LayerTag&layer){ } geom2d::rectCrawler::GetTileCollision(MapName map,vf2d pos,bool upperLevel){ - if(pos.x<0||pos.y<0||pos.x>=GetCurrentMap().width*24||pos.y>=GetCurrentMap().height*24)return NO_COLLISION; + if(pos.x<0||pos.y<0||pos.x>=GetCurrentMap().width*game->GetCurrentMap().tilewidth||pos.y>=GetCurrentMap().height*game->GetCurrentMap().tilewidth)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"]){ if(geom2d::contains(zone,pos)){ - return {{0,0},{24,24}}; + return {{0,0},{game->GetCurrentMap().tilewidth,game->GetCurrentMap().tilewidth}}; } } } #pragma endregion //The logic here is, if there's a tile on the bridge, we respect that tile instead if we're on the upper level. So we don't check other layers when we are on the upper level and there is a tile below us. if(upperLevel&&bridgeLayerIndex!=-1){ - int tileID=MAP_DATA[map].LayerData[bridgeLayerIndex].tiles[int(pos.y)/24][int(pos.x)/24]-1; + int tileID=MAP_DATA[map].LayerData[bridgeLayerIndex].tiles[int(pos.y)/game->GetCurrentMap().tilewidth][int(pos.x)/game->GetCurrentMap().tilewidth]-1; if(tileID!=-1){ if (GetTileSheet(map,tileID%1000000).tileset->collision.find(tileID%1000000-GetTileSheet(map,tileID%1000000).firstgid+1)!=GetTileSheet(map,tileID%1000000).tileset->collision.end()){ return GetTileSheet(map,tileID%1000000).tileset->collision[tileID%1000000-GetTileSheet(map,tileID%1000000).firstgid+1].collision; @@ -1377,7 +1379,7 @@ geom2d::rectCrawler::GetTileCollision(MapName map,vf2d pos,bool upperLevel) for(LayerTag&layer:MAP_DATA[map].LayerData){ //auto HasNoClass=[&](){return layer.tag.data.find("class")==layer.tag.data.end();}; if(counter!=bridgeLayerIndex){ - int tileID=layer.tiles[int(pos.y)/24][int(pos.x)/24]-1; + int tileID=layer.tiles[int(pos.y)/game->GetCurrentMap().tilewidth][int(pos.x)/game->GetCurrentMap().tilewidth]-1; if(tileID!=-1&&GetTileSheet(map,tileID%1000000).tileset->collision.find(tileID%1000000-GetTileSheet(map,tileID%1000000).firstgid+1)!=GetTileSheet(map,tileID%1000000).tileset->collision.end()){ geom2d::rectcollisionRect=GetTileSheet(map,tileID%1000000).tileset->collision[tileID%1000000-GetTileSheet(map,tileID%1000000).firstgid+1].collision; if(foundRect.pos==NO_COLLISION.pos&&foundRect.size==NO_COLLISION.size){ diff --git a/Crawler/Map.cpp b/Crawler/Map.cpp index f7cf5182..43ba50be 100644 --- a/Crawler/Map.cpp +++ b/Crawler/Map.cpp @@ -1,27 +1,30 @@ #include "Map.h" +#include "Crawler.h" + +INCLUDE_game 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}}; + range={tile.pos,{game->GetCurrentMap().tilewidth,game->GetCurrentMap().tilewidth}}; minX=tile.pos.x; - maxX=minX+24; + maxX=minX+game->GetCurrentMap().tilewidth; minY=tile.pos.y; - maxY=minY+24; + maxY=minY+game->GetCurrentMap().tilewidth; } else { if(tile.pos.xmaxX){ - maxX=tile.pos.x+24; + if(tile.pos.x+game->GetCurrentMap().tilewidth>maxX){ + maxX=tile.pos.x+game->GetCurrentMap().tilewidth; } if(tile.pos.ymaxY){ - maxY=tile.pos.y+24; + if(tile.pos.y+game->GetCurrentMap().tilewidth>maxY){ + maxY=tile.pos.y+game->GetCurrentMap().tilewidth; } range={{minX,minY},{maxX-minX,maxY-minY}}; } diff --git a/Crawler/Map.h b/Crawler/Map.h index c2bad31d..0f3bd237 100644 --- a/Crawler/Map.h +++ b/Crawler/Map.h @@ -17,6 +17,7 @@ struct TileCollisionData{ struct TilesetData{ Renderable*tileset=nullptr; + int tilewidth,tileheight; std::mapforegroundTiles; std::mapupperForegroundTiles; std::mapcollision; diff --git a/Crawler/Monster.cpp b/Crawler/Monster.cpp index 48f63c33..30622e73 100644 --- a/Crawler/Monster.cpp +++ b/Crawler/Monster.cpp @@ -75,17 +75,17 @@ void Monster::PerformIdleAnimation(){ } bool Monster::SetX(float x){ vf2d newPos={x,pos.y}; - vi2d tilePos=vi2d(newPos/24)*24; + vi2d tilePos=vi2d(newPos/game->GetCurrentMap().tilewidth)*game->GetCurrentMap().tilewidth; 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->GetCurrentMap().width*24-12*GetSizeMult())); + pos.x=std::clamp(x,game->GetCurrentMap().tilewidth/2*GetSizeMult(),float(game->GetCurrentMap().width*game->GetCurrentMap().tilewidth-game->GetCurrentMap().tilewidth/2*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->GetCurrentMap().width*24-12*GetSizeMult())); + pos.x=std::clamp(x,game->GetCurrentMap().tilewidth/2*GetSizeMult(),float(game->GetCurrentMap().width*game->GetCurrentMap().tilewidth-game->GetCurrentMap().tilewidth/2*GetSizeMult())); Moved(); return true; } @@ -94,17 +94,17 @@ bool Monster::SetX(float x){ } bool Monster::SetY(float y){ vf2d newPos={pos.x,y}; - vi2d tilePos=vi2d(newPos/24)*24; + vi2d tilePos=vi2d(newPos/game->GetCurrentMap().tilewidth)*game->GetCurrentMap().tilewidth; 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->GetCurrentMap().height*24-12*GetSizeMult())); + pos.y=std::clamp(y,game->GetCurrentMap().tilewidth/2*GetSizeMult(),float(game->GetCurrentMap().height*game->GetCurrentMap().tilewidth-game->GetCurrentMap().tilewidth/2*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->GetCurrentMap().height*24-12*GetSizeMult())); + if(!geom2d::overlaps(geom2d::circle(newPos,game->GetCurrentMap().tilewidth/2*GetSizeMult()),collision)){ + pos.y=std::clamp(y,game->GetCurrentMap().tilewidth/2*GetSizeMult(),float(game->GetCurrentMap().height*game->GetCurrentMap().tilewidth-game->GetCurrentMap().tilewidth/2*GetSizeMult())); Moved(); return true; } @@ -333,7 +333,7 @@ void Monster::StartPathfinding(float pathingTime){ void Monster::PathAroundBehavior(float fElapsedTime){ if(path.size()>0){ //Move towards the new path. - geom2d::line moveTowardsLine=geom2d::line(pos,path[pathIndex]*24); + geom2d::line moveTowardsLine=geom2d::line(pos,path[pathIndex]*game->GetCurrentMap().tilewidth); if(moveTowardsLine.length()>2){ SetPos(pos+moveTowardsLine.vector().norm()*100*fElapsedTime*GetMoveSpdMult()); if(moveTowardsLine.vector().x>0){ diff --git a/Crawler/Pathfinding.cpp b/Crawler/Pathfinding.cpp index 7a49ddfd..25aa3d05 100644 --- a/Crawler/Pathfinding.cpp +++ b/Crawler/Pathfinding.cpp @@ -14,9 +14,9 @@ void Pathfinding::Initialize(){ { 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)}); + geom2d::recttile=game->GetTileCollision(game->GetCurrentLevel(),{float(x*game->GetCurrentMap().tilewidth),float(y*game->GetCurrentMap().tilewidth)}); 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); + tile=game->GetTileCollision(game->GetCurrentLevel(),{float(x*game->GetCurrentMap().tilewidth),float(y*game->GetCurrentMap().tilewidth)},true); 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; @@ -50,19 +50,19 @@ void Pathfinding::Initialize(){ 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 {}; + if(dist>maxRange*game->GetCurrentMap().tilewidth)return {}; - 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)]; + nodeStart=&nodes[int(startPos.y/game->GetCurrentMap().tilewidth)*game->GetCurrentMap().width+int(startPos.x/game->GetCurrentMap().tilewidth)]; + nodeEnd=&nodes[int(endPos.y/game->GetCurrentMap().tilewidth)*game->GetCurrentMap().width+int(endPos.x/game->GetCurrentMap().tilewidth)]; 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->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))}; + posPerimeter.pos={int(std::clamp(posPerimeter.pos.x-maxRange*game->GetCurrentMap().tilewidth,0.f,game->GetCurrentMap().width*float(game->GetCurrentMap().tilewidth))),int(std::clamp(posPerimeter.pos.y-maxRange*game->GetCurrentMap().tilewidth,0.f,game->GetCurrentMap().height*float(game->GetCurrentMap().tilewidth)))}; + posPerimeter.size={int(std::clamp(posPerimeter.size.x+maxRange*game->GetCurrentMap().tilewidth*2,0.f,game->GetCurrentMap().width*float(game->GetCurrentMap().tilewidth)-posPerimeter.pos.x)),int(std::clamp(posPerimeter.size.y+maxRange*game->GetCurrentMap().tilewidth*2,0.f,game->GetCurrentMap().height*float(game->GetCurrentMap().tilewidth)-posPerimeter.pos.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})){ + if(geom2d::overlaps(posPerimeter,vi2d{x*game->GetCurrentMap().tilewidth,y*game->GetCurrentMap().tilewidth})){ nodes[y*game->GetCurrentMap().width + x].bVisited = false; } else { nodes[y*game->GetCurrentMap().width + x].bVisited = true; diff --git a/Crawler/Player.cpp b/Crawler/Player.cpp index ef4083b8..5a7d70c3 100644 --- a/Crawler/Player.cpp +++ b/Crawler/Player.cpp @@ -43,13 +43,13 @@ void Player::Initialize(){ bool Player::SetX(float x){ vf2d newPos={x,pos.y}; - vi2d tilePos=vi2d(newPos/24)*24; + vi2d tilePos=vi2d(newPos/game->GetCurrentMap().tilewidth)*game->GetCurrentMap().tilewidth; geom2d::rectcollisionRect=game->GetTileCollision(game->GetCurrentLevel(),newPos,upperLevel); #pragma region lambdas 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->GetCurrentMap().width*24-12*GetSizeMult())); + pos.x=std::clamp(x,game->GetCurrentMap().tilewidth/2*GetSizeMult(),float(game->GetCurrentMap().width*game->GetCurrentMap().tilewidth-game->GetCurrentMap().tilewidth/2*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->GetCurrentMap().width*24-12*GetSizeMult())); + pos.x=std::clamp(x,game->GetCurrentMap().tilewidth/2*GetSizeMult(),float(game->GetCurrentMap().width*game->GetCurrentMap().tilewidth-game->GetCurrentMap().tilewidth/2*GetSizeMult())); Moved(); return true; } @@ -69,13 +69,13 @@ bool Player::SetX(float x){ bool Player::SetY(float y){ vf2d newPos={pos.x,y}; - vi2d tilePos=vi2d(newPos/24)*24; + vi2d tilePos=vi2d(newPos/game->GetCurrentMap().tilewidth)*game->GetCurrentMap().tilewidth; geom2d::rectcollisionRect=game->GetTileCollision(game->GetCurrentLevel(),newPos,upperLevel); #pragma region lambdas 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->GetCurrentMap().height*24-12*GetSizeMult())); + pos.y=std::clamp(y,game->GetCurrentMap().tilewidth/2*GetSizeMult(),float(game->GetCurrentMap().height*game->GetCurrentMap().tilewidth-game->GetCurrentMap().tilewidth/2*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->GetCurrentMap().height*24-12*GetSizeMult())); + pos.y=std::clamp(y,game->GetCurrentMap().tilewidth/2*GetSizeMult(),float(game->GetCurrentMap().height*game->GetCurrentMap().tilewidth-game->GetCurrentMap().tilewidth/2*GetSizeMult())); Moved(); return true; } diff --git a/Crawler/SlimeKing.cpp b/Crawler/SlimeKing.cpp index 75054f09..7aa38609 100644 --- a/Crawler/SlimeKing.cpp +++ b/Crawler/SlimeKing.cpp @@ -298,8 +298,8 @@ void Monster::STRATEGY::SLIMEKING(Monster&m,float fElapsedTime,int strategyNumbe } if(m.I(A::PHASE_REPEAT_COUNT)>=5){ m.I(A::PHASE_REPEAT_COUNT)=0; - 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 jumpAngle=util::angleTo(m.GetPos(),game->GetCurrentMap().MapSize*game->GetCurrentMap().tilewidth/2); //We jump towards the center to keep the player from constantly dealing with a stuck boss. + float jumpDistance=ConfigFloat("Phase4.JumpDistance")/100*game->GetCurrentMap().tilewidth; float jumpSpd=jumpDistance/ConfigFloat("Phase4.JumpDuration"); StartJump(ConfigFloat("Phase4.JumpDuration"),m.GetPos()+vf2d{cos(jumpAngle)*jumpDistance,sin(jumpAngle)*jumpDistance},0,jumpSpd); }else diff --git a/Crawler/TSXParser.h b/Crawler/TSXParser.h index 240800c7..3a1706d3 100644 --- a/Crawler/TSXParser.h +++ b/Crawler/TSXParser.h @@ -10,6 +10,7 @@ using namespace olc; struct Tileset{ XMLTag ImageData; + int tilewidth,tileheight; std::map ForegroundTileData; std::map UpperForegroundTileData; std::map CollisionData; @@ -89,6 +90,10 @@ class TSXParser{ } } + if (newTag.tag=="tileset") { + parsedTilesetInfo.tilewidth=stoi(newTag.data["tilewidth"]); + parsedTilesetInfo.tileheight=stoi(newTag.data["tileheight"]); + } else if (newTag.tag=="image") { parsedTilesetInfo.ImageData=newTag; } else diff --git a/Crawler/Version.h b/Crawler/Version.h index 378b486b..cc541fbb 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 1735 +#define VERSION_BUILD 1741 #define stringify(a) stringify_(a) #define stringify_(a) #a diff --git a/Crawler/assets/Campaigns/World_Map.tmx b/Crawler/assets/Campaigns/World_Map.tmx index 18fbd88f..4cbf64d5 100644 --- a/Crawler/assets/Campaigns/World_Map.tmx +++ b/Crawler/assets/Campaigns/World_Map.tmx @@ -1,10 +1,11 @@ - + + 713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,0,0,0,0,0,0,0,0,0,0,0,0,0,0, @@ -545,4 +546,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 + + + diff --git a/Crawler/assets/config/configuration.txt b/Crawler/assets/config/configuration.txt index 81949743..aef3b484 100644 --- a/Crawler/assets/config/configuration.txt +++ b/Crawler/assets/config/configuration.txt @@ -16,7 +16,7 @@ Interface map_config = levels.txt # Starting map when loading the game. -starting_map = BOSS_1 +starting_map = WORLD_MAP # Player Properties Loading Config player_config = Player.txt diff --git a/x64/Release/Crawler.exe b/x64/Release/Crawler.exe index 17c7daed..25f47042 100644 Binary files a/x64/Release/Crawler.exe and b/x64/Release/Crawler.exe differ