From d658bb99736e11942591f44526c84a5632ea8610 Mon Sep 17 00:00:00 2001 From: "sigonasr2, Sig, Sigo" Date: Wed, 5 Jul 2023 18:29:04 +0000 Subject: [PATCH] Fix teleport ability, reverse logic in has tile collision. Also use precise collision checking for tiles. Teleporting distance clamping is now proper (650 range) --- Crawler/Class.cpp | 2 +- Crawler/Crawler.cpp | 6 ++++-- Crawler/Crawler.h | 4 +++- Crawler/monSlimeA.cpp | 7 ------- 4 files changed, 8 insertions(+), 11 deletions(-) delete mode 100644 Crawler/monSlimeA.cpp diff --git a/Crawler/Class.cpp b/Crawler/Class.cpp index 77ccb902..ec55216f 100644 --- a/Crawler/Class.cpp +++ b/Crawler/Class.cpp @@ -303,7 +303,7 @@ bool Wizard::RightClickAbility(){ 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); + float dist=std::clamp(geom2d::line{p.GetPos(),game->GetWorldMousePos()}.length(),0.f,6.5f*24); vf2d teleportPoint=p.GetPos()+pointTowardsMouse*dist; while(dist>0&&game->HasTileCollision(game->GetCurrentLevel(),teleportPoint)){ dist--; diff --git a/Crawler/Crawler.cpp b/Crawler/Crawler.cpp index 80e54544..d4f33410 100644 --- a/Crawler/Crawler.cpp +++ b/Crawler/Crawler.cpp @@ -950,7 +950,9 @@ 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; + vi2d collisionRectSnapPos=vi2d{pos/24}*24; + collisionRect.pos+=collisionRectSnapPos; + return geom2d::overlaps(collisionRect,pos); } geom2d::rectCrawler::GetTileCollision(MapName map,vf2d pos){ @@ -960,7 +962,7 @@ geom2d::rectCrawler::GetTileCollision(MapName map,vf2d pos){ return GetTileSheet(map,tileID).tileset.collision[tileID].collision; } } - return {}; + return NO_COLLISION; } MapName Crawler::GetCurrentLevel(){ diff --git a/Crawler/Crawler.h b/Crawler/Crawler.h index edbaf851..ca1a9368 100644 --- a/Crawler/Crawler.h +++ b/Crawler/Crawler.h @@ -42,7 +42,7 @@ public: Crawler(); public: - geom2d::rectNO_COLLISION={{0,0},{1,1}}; + geom2d::rectNO_COLLISION={}; vi2d WORLD_SIZE={120,8}; TileTransformedView view; bool OnUserCreate() override; @@ -76,7 +76,9 @@ public: bool IsForegroundTile(TilesheetData sheet,int tileID); //tileID is the tile number from the tilesets. TilesheetData GetTileSheet(MapName map,int tileID); + //Gets the rectangle of the tile collision at this tile. geom2d::rectGetTileCollision(MapName map,vf2d pos); + //Checks if the point resides inside of a collision tile. bool HasTileCollision(MapName map,vf2d pos); MapName GetCurrentLevel(); }; \ No newline at end of file diff --git a/Crawler/monSlimeA.cpp b/Crawler/monSlimeA.cpp deleted file mode 100644 index 693df678..00000000 --- a/Crawler/monSlimeA.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "MonsterType.h" - -monSlimeA::monSlimeA(vf2d pos,MonsterData data) - :Monster(pos,data){ - jumpAnimation=AnimationState::GREEN_SLIME_JUMP; - shootAnimation=AnimationState::GREEN_SLIME_SPIT; -}