Fix teleport ability, reverse logic in has tile collision. Also use precise collision checking for tiles. Teleporting distance clamping is now proper (650 range)

pull/28/head
parent 888d2a91a6
commit d658bb9973
  1. 2
      Crawler/Class.cpp
  2. 6
      Crawler/Crawler.cpp
  3. 4
      Crawler/Crawler.h
  4. 7
      Crawler/monSlimeA.cpp

@ -303,7 +303,7 @@ bool Wizard::RightClickAbility(){
ACCESS_PLAYER ACCESS_PLAYER
float pointMouseDirection=atan2(game->GetWorldMousePos().y-p.GetPos().y,game->GetWorldMousePos().x-p.GetPos().x); float pointMouseDirection=atan2(game->GetWorldMousePos().y-p.GetPos().y,game->GetWorldMousePos().x-p.GetPos().x);
vf2d pointTowardsMouse={cos(pointMouseDirection),sin(pointMouseDirection)}; vf2d pointTowardsMouse={cos(pointMouseDirection),sin(pointMouseDirection)};
float dist=std::clamp(geom2d::line<float>{p.GetPos(),game->GetWorldMousePos()}.length(),0.f,650.f); float dist=std::clamp(geom2d::line<float>{p.GetPos(),game->GetWorldMousePos()}.length(),0.f,6.5f*24);
vf2d teleportPoint=p.GetPos()+pointTowardsMouse*dist; vf2d teleportPoint=p.GetPos()+pointTowardsMouse*dist;
while(dist>0&&game->HasTileCollision(game->GetCurrentLevel(),teleportPoint)){ while(dist>0&&game->HasTileCollision(game->GetCurrentLevel(),teleportPoint)){
dist--; dist--;

@ -950,7 +950,9 @@ TilesheetData Crawler::GetTileSheet(MapName map,int tileID){
bool Crawler::HasTileCollision(MapName map,vf2d pos){ bool Crawler::HasTileCollision(MapName map,vf2d pos){
geom2d::rect<int>collisionRect=GetTileCollision(map,pos); geom2d::rect<int>collisionRect=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::rect<int>Crawler::GetTileCollision(MapName map,vf2d pos){ geom2d::rect<int>Crawler::GetTileCollision(MapName map,vf2d pos){
@ -960,7 +962,7 @@ geom2d::rect<int>Crawler::GetTileCollision(MapName map,vf2d pos){
return GetTileSheet(map,tileID).tileset.collision[tileID].collision; return GetTileSheet(map,tileID).tileset.collision[tileID].collision;
} }
} }
return {}; return NO_COLLISION;
} }
MapName Crawler::GetCurrentLevel(){ MapName Crawler::GetCurrentLevel(){

@ -42,7 +42,7 @@ public:
Crawler(); Crawler();
public: public:
geom2d::rect<int>NO_COLLISION={{0,0},{1,1}}; geom2d::rect<int>NO_COLLISION={};
vi2d WORLD_SIZE={120,8}; vi2d WORLD_SIZE={120,8};
TileTransformedView view; TileTransformedView view;
bool OnUserCreate() override; bool OnUserCreate() override;
@ -76,7 +76,9 @@ public:
bool IsForegroundTile(TilesheetData sheet,int tileID); bool IsForegroundTile(TilesheetData sheet,int tileID);
//tileID is the tile number from the tilesets. //tileID is the tile number from the tilesets.
TilesheetData GetTileSheet(MapName map,int tileID); TilesheetData GetTileSheet(MapName map,int tileID);
//Gets the rectangle of the tile collision at this tile.
geom2d::rect<int>GetTileCollision(MapName map,vf2d pos); geom2d::rect<int>GetTileCollision(MapName map,vf2d pos);
//Checks if the point resides inside of a collision tile.
bool HasTileCollision(MapName map,vf2d pos); bool HasTileCollision(MapName map,vf2d pos);
MapName GetCurrentLevel(); MapName GetCurrentLevel();
}; };

@ -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;
}
Loading…
Cancel
Save