Added detection of tile sizes and world sizes so different sizes of maps can be rendered.

pull/28/head
sigonasr2 1 year ago
parent 2f302f7370
commit ee5f6f9598
  1. 4
      Crawler/ClassDiagram2.cd
  2. 96
      Crawler/Crawler.cpp
  3. 17
      Crawler/Map.cpp
  4. 1
      Crawler/Map.h
  5. 16
      Crawler/Monster.cpp
  6. 16
      Crawler/Pathfinding.cpp
  7. 12
      Crawler/Player.cpp
  8. 4
      Crawler/SlimeKing.cpp
  9. 5
      Crawler/TSXParser.h
  10. 2
      Crawler/Version.h
  11. 6
      Crawler/assets/Campaigns/World_Map.tmx
  12. 2
      Crawler/assets/config/configuration.txt
  13. BIN
      x64/Release/Crawler.exe

@ -197,7 +197,9 @@
</TypeIdentifier>
</Class>
<Class Name="olc::utils::datafiledoubledata" Collapsed="true">
<Position X="24.25" Y="0.5" Width="1.5" />
<Position X="
.25" Y="0.5" Width="1.5" />
<TypeIdentifier>
<HashCode>AAAAIAAAAAAAAAAAAAAEAAAAAAEAAAAAAAAQAAAAAAA=</HashCode>
<FileName>olcUTIL_DataFile.h</FileName>

@ -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<GetCurrentMap().width&&y>=0&&y<GetCurrentMap().height){
switch(mode){
case RenderMode::NORMAL_TILES:{
@ -634,8 +634,8 @@ void Crawler::RenderWorld(float fElapsedTime){
if(!bridgeLayerFade&&!player->upperLevel){
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::rect<int>collision=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::rect<int>collision=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<GetCurrentMap().width&&y>=0&&y<GetCurrentMap().height){
int tileID=bridgeLayer->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;
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::rect<int>collision=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::vector<vf2d>pathing=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<int>&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;x<zoneX+zoneW;x++){
for(int y=zoneY;y<zoneY+zoneH;y++){
for(LayerTag&layer:MAP_DATA[map].LayerData){
@ -1211,8 +1213,8 @@ void Crawler::LoadLevel(MapName map){
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 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::rect<int>collisionRect=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::rect<int>Crawler::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<int>&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::rect<int>Crawler::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::rect<int>collisionRect=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){

@ -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.x<minX){
minX=tile.pos.x;
}
if(tile.pos.x+24>maxX){
maxX=tile.pos.x+24;
if(tile.pos.x+game->GetCurrentMap().tilewidth>maxX){
maxX=tile.pos.x+game->GetCurrentMap().tilewidth;
}
if(tile.pos.y<minY){
minY=tile.pos.y;
}
if(tile.pos.y+24>maxY){
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}};
}

@ -17,6 +17,7 @@ struct TileCollisionData{
struct TilesetData{
Renderable*tileset=nullptr;
int tilewidth,tileheight;
std::map<int,XMLTag>foregroundTiles;
std::map<int,XMLTag>upperForegroundTiles;
std::map<int,TileCollisionData>collision;

@ -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::rect<int>collisionRect=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::rect<float>collision={collisionRect.pos,collisionRect.size};
collision.pos+=tilePos;
if(!geom2d::overlaps(geom2d::circle<float>(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::rect<int>collisionRect=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::rect<float>collision={collisionRect.pos,collisionRect.size};
collision.pos+=tilePos;
if(!geom2d::overlaps(geom2d::circle<float>(newPos,12*GetSizeMult()),collision)){
pos.y=std::clamp(y,12.f*GetSizeMult(),float(game->GetCurrentMap().height*24-12*GetSizeMult()));
if(!geom2d::overlaps(geom2d::circle<float>(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){

@ -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::rect<int>tile=game->GetTileCollision(game->GetCurrentLevel(),{float(x*24),float(y*24)});
geom2d::rect<int>tile=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<vf2d> 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::rect<int>posPerimeter{{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;

@ -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::rect<int>collisionRect=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::rect<int>collisionRect=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;
}

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

@ -10,6 +10,7 @@ using namespace olc;
struct Tileset{
XMLTag ImageData;
int tilewidth,tileheight;
std::map<int,XMLTag> ForegroundTileData;
std::map<int,XMLTag> UpperForegroundTileData;
std::map<int,TileCollisionData> 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

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

@ -1,10 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.10" tiledversion="1.10.1" orientation="orthogonal" renderorder="right-down" width="142" height="176" tilewidth="4" tileheight="4" infinite="0" nextlayerid="4" nextobjectid="1">
<map version="1.10" tiledversion="1.10.1" orientation="orthogonal" renderorder="left-down" width="142" height="176" tilewidth="4" tileheight="4" infinite="0" nextlayerid="5" nextobjectid="3">
<tileset firstgid="1" source="../maps/Minifantasy_TinyOverworldAllTiles.tsx"/>
<tileset firstgid="8138" source="../maps/Minifantasy_TinyOverworldConstructions.tsx"/>
<tileset firstgid="9286" source="../maps/Minifantasy_TinyOverworldAllProps.tsx"/>
<tileset firstgid="10806" source="../maps/Stage_Plate.tsx"/>
<tileset firstgid="11066" source=":/automap-tiles.tsx"/>
<tileset firstgid="11071" source="../maps/Tilesheet_No_Shadow24x24.tsx"/>
<layer id="1" name="Layer 1" width="142" height="176">
<data encoding="csv">
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
</data>
</layer>
<objectgroup id="4" name="Object Layer 1">
<object id="2" name="Temp Player Spawn" type="PlayerSpawnLocation" x="200" y="325" width="20" height="20"/>
</objectgroup>
</map>

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

Binary file not shown.
Loading…
Cancel
Save