|
|
|
@ -29,42 +29,60 @@ void Player::SetClass(Class cl){ |
|
|
|
|
UpdateIdleAnimation(DOWN); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Player::SetX(float x){ |
|
|
|
|
bool Player::SetX(float x){ |
|
|
|
|
vf2d newPos={x,pos.y}; |
|
|
|
|
vi2d tilePos=vi2d(newPos/24)*24; |
|
|
|
|
geom2d::rect<int>collisionRect=game->GetTileCollision(game->GetCurrentLevel(),newPos); |
|
|
|
|
if(collisionRect.pos==vi2d{0,0}&&collisionRect.size==vi2d{1,1}){ |
|
|
|
|
#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->WORLD_SIZE.x*24-12*GetSizeMult())); |
|
|
|
|
return true; |
|
|
|
|
} else { |
|
|
|
|
geom2d::rect<float>collision={collisionRect.pos,collisionRect.size}; |
|
|
|
|
#pragma region lambdas |
|
|
|
|
auto NoPlayerCollisionWithTile=[&](){return !geom2d::overlaps(newPos,collision);}; |
|
|
|
|
#pragma endregion |
|
|
|
|
collision.pos+=tilePos; |
|
|
|
|
if(!geom2d::overlaps(newPos,collision)){ |
|
|
|
|
if(NoPlayerCollisionWithTile()){ |
|
|
|
|
pos.x=std::clamp(x,12.f*GetSizeMult(),float(game->WORLD_SIZE.x*24-12*GetSizeMult())); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
void Player::SetY(float y){ |
|
|
|
|
bool Player::SetY(float y){ |
|
|
|
|
vf2d newPos={pos.x,y}; |
|
|
|
|
vi2d tilePos=vi2d(newPos/24)*24; |
|
|
|
|
geom2d::rect<int>collisionRect=game->GetTileCollision(game->GetCurrentLevel(),newPos); |
|
|
|
|
if(collisionRect.pos==vi2d{0,0}&&collisionRect.size==vi2d{1,1}){ |
|
|
|
|
#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->WORLD_SIZE.y*24-12*GetSizeMult())); |
|
|
|
|
return true; |
|
|
|
|
} else { |
|
|
|
|
geom2d::rect<float>collision={collisionRect.pos,collisionRect.size}; |
|
|
|
|
#pragma region lambdas |
|
|
|
|
auto NoPlayerCollisionWithTile=[&](){return !geom2d::overlaps(newPos,collision);}; |
|
|
|
|
#pragma endregion |
|
|
|
|
collision.pos+=tilePos; |
|
|
|
|
if(!geom2d::overlaps(newPos,collision)){ |
|
|
|
|
if(NoPlayerCollisionWithTile()){ |
|
|
|
|
pos.y=std::clamp(y,12.f*GetSizeMult(),float(game->WORLD_SIZE.y*24-12*GetSizeMult())); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Player::SetZ(float z){ |
|
|
|
|
this->z=z; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Player::SetPos(vf2d pos){ |
|
|
|
|
this->pos=pos; |
|
|
|
|
bool Player::SetPos(vf2d pos){ |
|
|
|
|
return SetX(pos.x)|SetY(pos.y); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
vf2d&Player::GetPos(){ |
|
|
|
|