Teleport code added in Wizard. Needs more debugging.
This commit is contained in:
parent
ba6bc74f1f
commit
888d2a91a6
@ -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<float>{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,
|
||||
|
@ -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<std::pair<MonsterName,vf2d>>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::rect<int>collisionRect=GetTileCollision(map,pos);
|
||||
return collisionRect.pos==NO_COLLISION.pos&&collisionRect.size==NO_COLLISION.size;
|
||||
}
|
||||
|
||||
geom2d::rect<int>Crawler::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;
|
||||
|
@ -42,6 +42,7 @@ public:
|
||||
Crawler();
|
||||
|
||||
public:
|
||||
geom2d::rect<int>NO_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::rect<int>GetTileCollision(MapName map,vf2d pos);
|
||||
bool HasTileCollision(MapName map,vf2d pos);
|
||||
MapName GetCurrentLevel();
|
||||
};
|
@ -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(){
|
||||
|
@ -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::vector<Buff>buffList;
|
||||
protected:
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user