|
|
@ -57,10 +57,18 @@ int Monster::GetHealth(){ |
|
|
|
return hp; |
|
|
|
return hp; |
|
|
|
} |
|
|
|
} |
|
|
|
int Monster::GetAttack(){ |
|
|
|
int Monster::GetAttack(){ |
|
|
|
return atk; |
|
|
|
float mod_atk=atk; |
|
|
|
|
|
|
|
for(Buff&b:GetBuffs(ATTACK_UP)){ |
|
|
|
|
|
|
|
mod_atk+=atk*b.intensity; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return int(mod_atk); |
|
|
|
} |
|
|
|
} |
|
|
|
float Monster::GetMoveSpdMult(){ |
|
|
|
float Monster::GetMoveSpdMult(){ |
|
|
|
return moveSpd; |
|
|
|
float mod_moveSpd=moveSpd; |
|
|
|
|
|
|
|
for(Buff&b:GetBuffs(SLOWDOWN)){ |
|
|
|
|
|
|
|
mod_moveSpd-=moveSpd*b.intensity; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return mod_moveSpd; |
|
|
|
} |
|
|
|
} |
|
|
|
float Monster::GetSizeMult(){ |
|
|
|
float Monster::GetSizeMult(){ |
|
|
|
return size; |
|
|
|
return size; |
|
|
@ -113,6 +121,14 @@ void Monster::SetY(float y){ |
|
|
|
} |
|
|
|
} |
|
|
|
bool Monster::Update(float fElapsedTime){ |
|
|
|
bool Monster::Update(float fElapsedTime){ |
|
|
|
if(IsAlive()){ |
|
|
|
if(IsAlive()){ |
|
|
|
|
|
|
|
for(std::vector<Buff>::iterator it=buffList.begin();it!=buffList.end();++it){ |
|
|
|
|
|
|
|
Buff&b=*it; |
|
|
|
|
|
|
|
b.duration-=fElapsedTime; |
|
|
|
|
|
|
|
if(b.duration<=0){ |
|
|
|
|
|
|
|
it=buffList.erase(it); |
|
|
|
|
|
|
|
if(it==buffList.end())break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
for(Monster&m:MONSTER_LIST){ |
|
|
|
for(Monster&m:MONSTER_LIST){ |
|
|
|
if(&m==this)continue; |
|
|
|
if(&m==this)continue; |
|
|
|
if(geom2d::overlaps(geom2d::circle(pos,12*size/2),geom2d::circle(m.GetPos(),12*m.GetSizeMult()/2))){ |
|
|
|
if(geom2d::overlaps(geom2d::circle(pos,12*size/2),geom2d::circle(m.GetPos(),12*m.GetSizeMult()/2))){ |
|
|
@ -146,8 +162,8 @@ bool Monster::Update(float fElapsedTime){ |
|
|
|
target=geom2d::line(pos,game->GetPlayer().GetPos()).upoint(1.2); |
|
|
|
target=geom2d::line(pos,game->GetPlayer().GetPos()).upoint(1.2); |
|
|
|
state=MOVE_TOWARDS; |
|
|
|
state=MOVE_TOWARDS; |
|
|
|
} |
|
|
|
} |
|
|
|
if(state==MOVE_TOWARDS&&geom2d::line(pos,target).length()>100*fElapsedTime*moveSpd){ |
|
|
|
if(state==MOVE_TOWARDS&&geom2d::line(pos,target).length()>100*fElapsedTime*GetMoveSpdMult()){ |
|
|
|
SetPosition(pos+geom2d::line(pos,target).vector().norm()*100*fElapsedTime*moveSpd); |
|
|
|
SetPosition(pos+geom2d::line(pos,target).vector().norm()*100*fElapsedTime*GetMoveSpdMult()); |
|
|
|
PerformJumpAnimation(); |
|
|
|
PerformJumpAnimation(); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if(state==MOVE_TOWARDS){ |
|
|
|
if(state==MOVE_TOWARDS){ |
|
|
@ -163,7 +179,7 @@ bool Monster::Update(float fElapsedTime){ |
|
|
|
queueShotTimer-=fElapsedTime; |
|
|
|
queueShotTimer-=fElapsedTime; |
|
|
|
if(queueShotTimer<0){ |
|
|
|
if(queueShotTimer<0){ |
|
|
|
queueShotTimer=0; |
|
|
|
queueShotTimer=0; |
|
|
|
BULLET_LIST.push_back(Bullet(pos+vf2d{0,-4},geom2d::line(pos+vf2d{0,-4},game->GetPlayer().GetPos()).vector().norm()*24*3.f,2,atk,{75/2,162/2,225/2})); |
|
|
|
BULLET_LIST.push_back(Bullet(pos+vf2d{0,-4},geom2d::line(pos+vf2d{0,-4},game->GetPlayer().GetPos()).vector().norm()*24*3.f,2,GetAttack(),{75/2,162/2,225/2})); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
geom2d::line line(pos,game->GetPlayer().GetPos()); |
|
|
|
geom2d::line line(pos,game->GetPlayer().GetPos()); |
|
|
@ -203,7 +219,7 @@ bool Monster::Update(float fElapsedTime){ |
|
|
|
switch(state){ |
|
|
|
switch(state){ |
|
|
|
case MOVE_TOWARDS:{ |
|
|
|
case MOVE_TOWARDS:{ |
|
|
|
if(moveTowardsLine.length()>1){ |
|
|
|
if(moveTowardsLine.length()>1){ |
|
|
|
SetPosition(pos+moveTowardsLine.vector().norm()*100*fElapsedTime*moveSpd); |
|
|
|
SetPosition(pos+moveTowardsLine.vector().norm()*100*fElapsedTime*GetMoveSpdMult()); |
|
|
|
} |
|
|
|
} |
|
|
|
if(line.length()<=24*7){ |
|
|
|
if(line.length()<=24*7){ |
|
|
|
state=NORMAL; |
|
|
|
state=NORMAL; |
|
|
@ -217,7 +233,7 @@ bool Monster::Update(float fElapsedTime){ |
|
|
|
}break; |
|
|
|
}break; |
|
|
|
case MOVE_AWAY:{ |
|
|
|
case MOVE_AWAY:{ |
|
|
|
if(moveTowardsLine.length()>1){ |
|
|
|
if(moveTowardsLine.length()>1){ |
|
|
|
SetPosition(pos+moveTowardsLine.vector().norm()*100*fElapsedTime*moveSpd); |
|
|
|
SetPosition(pos+moveTowardsLine.vector().norm()*100*fElapsedTime*GetMoveSpdMult()); |
|
|
|
} |
|
|
|
} |
|
|
|
if(line.length()>=24*6){ |
|
|
|
if(line.length()>=24*6){ |
|
|
|
state=NORMAL; |
|
|
|
state=NORMAL; |
|
|
@ -267,9 +283,9 @@ Key Monster::GetFacingDirection(){ |
|
|
|
} |
|
|
|
} |
|
|
|
void Monster::Draw(){ |
|
|
|
void Monster::Draw(){ |
|
|
|
if(GetFacingDirection()==RIGHT){ |
|
|
|
if(GetFacingDirection()==RIGHT){ |
|
|
|
game->view.DrawPartialDecal((GetPos()+vf2d{float(GetFrame().GetSourceRect().size.x),0}*GetSizeMult())-vf2d{12,12}*GetSizeMult(),GetFrame().GetSourceImage()->Decal(),GetFrame().GetSourceRect().pos,GetFrame().GetSourceRect().size,vf2d(GetSizeMult()*-1,GetSizeMult())); |
|
|
|
game->view.DrawPartialDecal((GetPos()+vf2d{float(GetFrame().GetSourceRect().size.x),0}*GetSizeMult())-vf2d{12,12}*GetSizeMult(),GetFrame().GetSourceImage()->Decal(),GetFrame().GetSourceRect().pos,GetFrame().GetSourceRect().size,vf2d(GetSizeMult()*-1,GetSizeMult()),GetBuffs(BuffType::SLOWDOWN).size()>0?Pixel{uint8_t(255*abs(sin(1.4*GetBuffs(BuffType::SLOWDOWN)[0].duration))),uint8_t(255*abs(sin(1.4*GetBuffs(BuffType::SLOWDOWN)[0].duration))),uint8_t(128+127*abs(sin(1.4*GetBuffs(BuffType::SLOWDOWN)[0].duration)))}:WHITE); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
game->view.DrawPartialDecal(GetPos()-vf2d{12,12}*GetSizeMult(),GetFrame().GetSourceImage()->Decal(),GetFrame().GetSourceRect().pos,GetFrame().GetSourceRect().size,vf2d(GetSizeMult(),GetSizeMult())); |
|
|
|
game->view.DrawPartialDecal(GetPos()-vf2d{12,12}*GetSizeMult(),GetFrame().GetSourceImage()->Decal(),GetFrame().GetSourceRect().pos,GetFrame().GetSourceRect().size,vf2d(GetSizeMult(),GetSizeMult()),GetBuffs(BuffType::SLOWDOWN).size()>0?Pixel{uint8_t(255*abs(sin(1.4*GetBuffs(BuffType::SLOWDOWN)[0].duration))),uint8_t(255*abs(sin(1.4*GetBuffs(BuffType::SLOWDOWN)[0].duration))),uint8_t(128+127*abs(sin(1.4*GetBuffs(BuffType::SLOWDOWN)[0].duration)))}:WHITE); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
void Monster::Collision(Player&p){ |
|
|
|
void Monster::Collision(Player&p){ |
|
|
@ -311,8 +327,12 @@ AnimationState Monster::GetDeathAnimationName(){ |
|
|
|
}
|
|
|
|
}
|
|
|
|
bool Monster::Hurt(int damage){ |
|
|
|
bool Monster::Hurt(int damage){ |
|
|
|
if(hp<=0) return false; |
|
|
|
if(hp<=0) return false; |
|
|
|
hp=std::max(0,hp-damage); |
|
|
|
float mod_dmg=damage; |
|
|
|
DAMAGENUMBER_LIST.push_back(DamageNumber(pos,damage)); |
|
|
|
for(Buff&b:GetBuffs(BuffType::DAMAGE_REDUCTION)){ |
|
|
|
|
|
|
|
mod_dmg-=damage*b.intensity; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
hp=std::max(0,hp-int(mod_dmg)); |
|
|
|
|
|
|
|
DAMAGENUMBER_LIST.push_back(DamageNumber(pos,int(mod_dmg))); |
|
|
|
if(hp<=0){ |
|
|
|
if(hp<=0){ |
|
|
|
animation.ChangeState(internal_animState,GetDeathAnimationName()); |
|
|
|
animation.ChangeState(internal_animState,GetDeathAnimationName()); |
|
|
|
} |
|
|
|
} |
|
|
@ -347,3 +367,13 @@ void MonsterSpawner::SetTriggered(bool trigger,bool spawnMonsters){ |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Monster::AddBuff(BuffType type,float duration,float intensity){ |
|
|
|
|
|
|
|
buffList.push_back(Buff{type,duration,intensity}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<Buff>Monster::GetBuffs(BuffType buff){ |
|
|
|
|
|
|
|
std::vector<Buff>filteredBuffs; |
|
|
|
|
|
|
|
std::copy_if(buffList.begin(),buffList.end(),std::back_inserter(filteredBuffs),[buff](Buff&b){return b.type==buff;}); |
|
|
|
|
|
|
|
return filteredBuffs; |
|
|
|
|
|
|
|
} |