diff --git a/Crawler/Class.cpp b/Crawler/Class.cpp index f2b14c50..77ccb902 100644 --- a/Crawler/Class.cpp +++ b/Crawler/Class.cpp @@ -300,7 +300,21 @@ bool Wizard::Ability3(){ } bool Wizard::RightClickAbility(){ - return true; + ACCESS_PLAYER + float pointMouseDirection=atan2(game->GetWorldMousePos().y-p.GetPos().y,game->GetWorldMousePos().x-p.GetPos().x); + vf2d pointTowardsMouse={cos(pointMouseDirection),sin(pointMouseDirection)}; + float dist=std::clamp(geom2d::line{p.GetPos(),game->GetWorldMousePos()}.length(),0.f,650.f); + vf2d teleportPoint=p.GetPos()+pointTowardsMouse*dist; + while(dist>0&&game->HasTileCollision(game->GetCurrentLevel(),teleportPoint)){ + dist--; + teleportPoint=p.GetPos()+pointTowardsMouse*dist; + } + if(dist>0){ + p.SetPos(teleportPoint); + return true; + } else { + return false; + } } Witch::Witch(std::string name,Class cl,Ability rightClickAbility,Ability ability1,Ability ability2,Ability ability3, diff --git a/Crawler/Crawler.cpp b/Crawler/Crawler.cpp index b30b3386..80e54544 100644 --- a/Crawler/Crawler.cpp +++ b/Crawler/Crawler.cpp @@ -107,11 +107,10 @@ bool Crawler::OnUserCreate(){ player.AddAnimation(AnimationState::WIZARD_ATTACK_W); view=TileTransformedView{GetScreenSize(),{1,1}}; - player.SetClass(WARRIOR); - player.SetPos({4*24,4*24}); - LoadLevel(CAMPAIGN_1_1); + player.SetClass(WARRIOR); + return true; } @@ -875,7 +874,6 @@ void Crawler::LoadLevel(MapName map){ SPAWNER_LIST.clear(); foregroundTileGroups.clear(); currentLevel=map; - player.SetPos(MAP_DATA[map].MapData.playerSpawnLocation); WORLD_SIZE={MAP_DATA[map].MapData.width,MAP_DATA[map].MapData.height}; for(SpawnerTag&spawner:MAP_DATA[map].SpawnerData){ std::vector>monster_list; @@ -919,6 +917,7 @@ void Crawler::LoadLevel(MapName map){ } } } + player.SetPos(MAP_DATA[map].MapData.playerSpawnLocation); } vi2d Crawler::GetWorldSize(){ @@ -949,6 +948,11 @@ TilesheetData Crawler::GetTileSheet(MapName map,int tileID){ } } +bool Crawler::HasTileCollision(MapName map,vf2d pos){ + geom2d::rectcollisionRect=GetTileCollision(map,pos); + return collisionRect.pos==NO_COLLISION.pos&&collisionRect.size==NO_COLLISION.size; +} + geom2d::rectCrawler::GetTileCollision(MapName map,vf2d pos){ for(LayerTag&layer:MAP_DATA[map].LayerData){ int tileID=layer.tiles[int(pos.y)/24][int(pos.x)/24]-1; diff --git a/Crawler/Crawler.h b/Crawler/Crawler.h index a191e080..edbaf851 100644 --- a/Crawler/Crawler.h +++ b/Crawler/Crawler.h @@ -42,6 +42,7 @@ public: Crawler(); public: + geom2d::rectNO_COLLISION={{0,0},{1,1}}; vi2d WORLD_SIZE={120,8}; TileTransformedView view; bool OnUserCreate() override; @@ -76,5 +77,6 @@ public: //tileID is the tile number from the tilesets. TilesheetData GetTileSheet(MapName map,int tileID); geom2d::rectGetTileCollision(MapName map,vf2d pos); + bool HasTileCollision(MapName map,vf2d pos); MapName GetCurrentLevel(); }; \ No newline at end of file diff --git a/Crawler/Player.cpp b/Crawler/Player.cpp index 15523afa..bd588c76 100644 --- a/Crawler/Player.cpp +++ b/Crawler/Player.cpp @@ -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::rectcollisionRect=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::rectcollision={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::rectcollisionRect=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::rectcollision={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(){ diff --git a/Crawler/Player.h b/Crawler/Player.h index f8c851a2..1fa5b8f9 100644 --- a/Crawler/Player.h +++ b/Crawler/Player.h @@ -51,10 +51,13 @@ struct Player{ void SetFacingDirection(Key direction); void SetLastReleasedMovementKey(Key k); void Spin(float duration,float spinSpd); - void SetX(float x); - void SetY(float y); + //Returns true if the move was valid and successful. + bool SetX(float x); + //Returns true if the move was valid and successful. + bool SetY(float y); void SetZ(float z); - void SetPos(vf2d pos); + //Returns true if the move was valid and successful. + bool SetPos(vf2d pos); void SetClass(Class cl); std::vectorbuffList; protected: diff --git a/Crawler/Version.h b/Crawler/Version.h index 515af79c..aad294b3 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 391 +#define VERSION_BUILD 406 #define stringify(a) stringify_(a) #define stringify_(a) #a