Convert all world size positions to use the map's direct map width and height values instead. Fix a bug where using teleport outside the map crashed the game.
This commit is contained in:
parent
9246852c25
commit
2f302f7370
@ -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<WORLD_SIZE.x&&y>=0&&y<WORLD_SIZE.y){
|
||||
if(x>=0&&x<GetCurrentMap().width&&y>=0&&y<GetCurrentMap().height){
|
||||
switch(mode){
|
||||
case RenderMode::NORMAL_TILES:{
|
||||
for(LayerTag&layer:MAP_DATA[currentLevel].LayerData){
|
||||
@ -696,7 +696,8 @@ void Crawler::RenderWorld(float fElapsedTime){
|
||||
}
|
||||
}break;
|
||||
}
|
||||
|
||||
}else{
|
||||
view.FillRectDecal(vi2d{x,y}*24,{24,24},{100,180,100});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -842,7 +843,7 @@ void Crawler::RenderWorld(float fElapsedTime){
|
||||
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++){
|
||||
if(x>=0&&x<WORLD_SIZE.x&&y>=0&&y<WORLD_SIZE.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);
|
||||
@ -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::set<vi2d>foregroundTilesAdded,upperForegroundTilesAdded;
|
||||
for(int x=0;x<WORLD_SIZE.x;x++){
|
||||
for(int y=0;y<WORLD_SIZE.y;y++){
|
||||
for(int x=0;x<GetCurrentMap().width;x++){
|
||||
for(int y=0;y<GetCurrentMap().height;y++){
|
||||
int layerID=0;
|
||||
for(LayerTag&layer:MAP_DATA[currentLevel].LayerData){
|
||||
int tileID=layer.tiles[y][x]-1;
|
||||
@ -1225,9 +1225,9 @@ void Crawler::LoadLevel(MapName map){
|
||||
foregroundTilesIncluded.insert({x,y});
|
||||
group.InsertTile(tile);
|
||||
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(x<GetCurrentMap().width-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});
|
||||
if(y<GetCurrentMap().height-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;
|
||||
@ -1259,11 +1259,11 @@ void Crawler::LoadLevel(MapName map){
|
||||
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);}
|
||||
if(pos.x<GetCurrentMap().width-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);}
|
||||
if(pos.y<GetCurrentMap().height-1&&foregroundTilesIncluded.find(targetPos)==foregroundTilesIncluded.end()){tileGroupChecks.push(targetPos);foregroundTilesIncluded.insert(targetPos);}
|
||||
}
|
||||
tileGroupChecks.pop();
|
||||
}
|
||||
@ -1312,10 +1312,6 @@ void Crawler::LoadLevel(MapName map){
|
||||
pathfinder.Initialize();
|
||||
}
|
||||
|
||||
vi2d Crawler::GetWorldSize(){
|
||||
return WORLD_SIZE;
|
||||
}
|
||||
|
||||
bool Crawler::IsUpperForegroundTile(int tileID){
|
||||
return tileID>=1000000;
|
||||
}
|
||||
@ -1356,7 +1352,7 @@ 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>=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<int>&zone:MAP_DATA[map].ZoneData["LowerBridgeCollision"]){
|
||||
@ -1739,3 +1735,7 @@ void Crawler::InitializeGraphics(){
|
||||
GFX.SetInitialized();
|
||||
std::cout<<GFX.size()<<" images have been loaded."<<std::endl;
|
||||
}
|
||||
|
||||
MapTag Crawler::GetCurrentMap(){
|
||||
return MAP_DATA[GetCurrentLevel()].MapData;
|
||||
}
|
||||
@ -65,7 +65,6 @@ public:
|
||||
bool OnUserDestroy() override;
|
||||
public:
|
||||
geom2d::rect<int>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;
|
||||
|
||||
@ -78,14 +78,14 @@ bool Monster::SetX(float x){
|
||||
vi2d tilePos=vi2d(newPos/24)*24;
|
||||
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->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::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->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::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->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::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->WORLD_SIZE.y*24-12*GetSizeMult()));
|
||||
pos.y=std::clamp(y,12.f*GetSizeMult(),float(game->GetCurrentMap().height*24-12*GetSizeMult()));
|
||||
Moved();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -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::rect<int>tile=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(y<game->WORLD_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(y<game->GetCurrentMap().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(x<game->WORLD_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(x<game->GetCurrentMap().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 (y<game->WORLD_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 && x<game->WORLD_SIZE.x-1)
|
||||
nodes[y*game->WORLD_SIZE.x + x].vecNeighbours.push_back(&nodes[(y - 1) * game->WORLD_SIZE.x + (x + 1)]);
|
||||
if (y<game->WORLD_SIZE.y - 1 && x<game->WORLD_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 (y<game->GetCurrentMap().height-1 && x>0)
|
||||
nodes[y*game->GetCurrentMap().width + x].vecNeighbours.push_back(&nodes[(y + 1) * game->GetCurrentMap().width + (x - 1)]);
|
||||
if (y>0 && x<game->GetCurrentMap().width-1)
|
||||
nodes[y*game->GetCurrentMap().width + x].vecNeighbours.push_back(&nodes[(y - 1) * game->GetCurrentMap().width + (x + 1)]);
|
||||
if (y<game->GetCurrentMap().height - 1 && x<game->GetCurrentMap().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<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 {};
|
||||
|
||||
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::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->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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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::vector<vf2d>pathing=game->pathfinder.Solve_AStar(pos,targetPos,range,upperLevel);
|
||||
return pathing.size()>0&&pathing.size()<range;//We'll say 7 tiles or less is close enough to 650 range. Have a little bit of wiggle room.
|
||||
}
|
||||
|
||||
@ -298,7 +298,7 @@ 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->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);
|
||||
|
||||
@ -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<std::string,std::vector<geom2d::rect<int>>> ZoneData;
|
||||
}
|
||||
std::ostream& operator << (std::ostream& os, MapTag& rhs){
|
||||
os <<
|
||||
"(width:"<<rhs.width<<", height:"<<rhs.height<<",playerSpawnLocation:"<<rhs.playerSpawnLocation<<")\n";
|
||||
"(width:"<<rhs.width<<", height:"<<rhs.height<<", Tile width:"<<rhs.tilewidth<<", Tile height:"<<rhs.tileheight<<",playerSpawnLocation:"<<rhs.playerSpawnLocation<<")\n";
|
||||
return os;
|
||||
}
|
||||
int XMLTag::GetInteger(std::string dataTag) {
|
||||
@ -107,6 +112,9 @@ typedef std::map<std::string,std::vector<geom2d::rect<int>>> 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<std::string,std::vector<geom2d::rect<int>>> 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);
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user