|
|
|
@ -129,11 +129,11 @@ bool Monster::Update(float fElapsedTime){ |
|
|
|
|
if(!HasIframes()){ |
|
|
|
|
for(Monster&m:MONSTER_LIST){ |
|
|
|
|
if(&m==this)continue; |
|
|
|
|
if(!m.HasIframes()&&OnUpperLevel()==m.OnUpperLevel()&&geom2d::overlaps(geom2d::circle(pos,12*size/2),geom2d::circle(m.GetPos(),12*m.GetSizeMult()/2))){ |
|
|
|
|
if(!m.HasIframes()&&OnUpperLevel()==m.OnUpperLevel()&&abs(m.GetZ()-GetZ())<=1&&geom2d::overlaps(geom2d::circle(pos,12*size/2),geom2d::circle(m.GetPos(),12*m.GetSizeMult()/2))){ |
|
|
|
|
m.Collision(*this); |
|
|
|
|
geom2d::line line(pos,m.GetPos()); |
|
|
|
|
float dist = line.length(); |
|
|
|
|
m.SetPosition(line.rpoint(dist*1.1)); |
|
|
|
|
m.SetPos(line.rpoint(dist*1.1)); |
|
|
|
|
if(m.IsAlive()){ |
|
|
|
|
vel=line.vector().norm()*-128; |
|
|
|
|
} |
|
|
|
@ -142,7 +142,7 @@ bool Monster::Update(float fElapsedTime){ |
|
|
|
|
if(!game->GetPlayer()->HasIframes()&&game->GetPlayer()->OnUpperLevel()==OnUpperLevel()&&geom2d::overlaps(geom2d::circle(pos,12*size/2),geom2d::circle(game->GetPlayer()->GetPos(),12*game->GetPlayer()->GetSizeMult()/2))){ |
|
|
|
|
geom2d::line line(pos,game->GetPlayer()->GetPos()); |
|
|
|
|
float dist = line.length(); |
|
|
|
|
SetPosition(line.rpoint(-0.1)); |
|
|
|
|
SetPos(line.rpoint(-0.1)); |
|
|
|
|
vel=line.vector().norm()*-128; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -183,6 +183,7 @@ Key Monster::GetFacingDirection(){ |
|
|
|
|
return facingDirection; |
|
|
|
|
} |
|
|
|
|
void Monster::Draw(){ |
|
|
|
|
strategyDraw(game); |
|
|
|
|
if(GetZ()>0){ |
|
|
|
|
vf2d shadowScale=vf2d{8*GetSizeMult()/3.f,1}/std::max(1.f,GetZ()/24); |
|
|
|
|
game->view.DrawDecal(GetPos()-vf2d{3,3}*shadowScale/2+vf2d{0,6*GetSizeMult()},game->GFX_Circle.Decal(),shadowScale,BLACK); |
|
|
|
@ -204,14 +205,14 @@ void Monster::Collision(Monster&m){ |
|
|
|
|
Collision(); |
|
|
|
|
} |
|
|
|
|
void Monster::Collision(){ |
|
|
|
|
if(strategy==0&&GetState()==MOVE_TOWARDS){//The run towards strategy causes state to return to normal upon a collision.
|
|
|
|
|
SetState(NORMAL); |
|
|
|
|
if(strategy==0&&GetState()==State::MOVE_TOWARDS){//The run towards strategy causes state to return to normal upon a collision.
|
|
|
|
|
SetState(State::NORMAL); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
void Monster::SetVelocity(vf2d vel){ |
|
|
|
|
this->vel=vel; |
|
|
|
|
} |
|
|
|
|
bool Monster::SetPosition(vf2d pos){ |
|
|
|
|
bool Monster::SetPos(vf2d pos){ |
|
|
|
|
bool resultX=SetX(pos.x); |
|
|
|
|
bool resultY=SetY(pos.y); |
|
|
|
|
if(resultY&&!resultX){ |
|
|
|
@ -301,7 +302,7 @@ void Monster::AddBuff(BuffType type,float duration,float intensity){ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Monster::StartPathfinding(float pathingTime){ |
|
|
|
|
SetState(PATH_AROUND); |
|
|
|
|
SetState(State::PATH_AROUND); |
|
|
|
|
path=game->pathfinder.Solve_AStar(pos,target,12,OnUpperLevel()); |
|
|
|
|
if(path.size()>0){ |
|
|
|
|
pathIndex=0; |
|
|
|
@ -315,7 +316,7 @@ void Monster::PathAroundBehavior(float fElapsedTime){ |
|
|
|
|
//Move towards the new path.
|
|
|
|
|
geom2d::line moveTowardsLine=geom2d::line(pos,path[pathIndex]*24); |
|
|
|
|
if(moveTowardsLine.length()>2){ |
|
|
|
|
SetPosition(pos+moveTowardsLine.vector().norm()*100*fElapsedTime*GetMoveSpdMult()); |
|
|
|
|
SetPos(pos+moveTowardsLine.vector().norm()*100*fElapsedTime*GetMoveSpdMult()); |
|
|
|
|
if(moveTowardsLine.vector().x>0){ |
|
|
|
|
facingDirection=RIGHT; |
|
|
|
|
} else { |
|
|
|
@ -341,11 +342,11 @@ std::vector<Buff>Monster::GetBuffs(BuffType buff){ |
|
|
|
|
return filteredBuffs; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
State Monster::GetState(){ |
|
|
|
|
State::State Monster::GetState(){ |
|
|
|
|
return state; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Monster::SetState(State newState){ |
|
|
|
|
void Monster::SetState(State::State newState){ |
|
|
|
|
state=newState; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -407,4 +408,19 @@ bool&Monster::GetBool(Attribute a){ |
|
|
|
|
attributes[a]=false; |
|
|
|
|
} |
|
|
|
|
return std::get<bool>(attributes[a]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
vf2d&Monster::GetVf2d(Attribute a){ |
|
|
|
|
if(attributes.count(a)==0){ |
|
|
|
|
attributes[a]=vf2d{}; |
|
|
|
|
} |
|
|
|
|
return std::get<vf2d>(attributes[a]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Monster::SetZ(float z){ |
|
|
|
|
this->z=z; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Monster::SetStrategyDrawFunction(std::function<void(Crawler*)>func){ |
|
|
|
|
strategyDraw=func; |
|
|
|
|
} |