void monster::monstermove(player * player1) {
if(abs(player1->m_x - m_x) < 10 && abs(player1->m_y - m_y) < 10)
return;
if(!CanMove())
return;
float tangent;
m_yvel = 4;
m_xvel=4;
if(abs(player1->m_y - this->m_y) < 10) m_yvel=0;
if(abs(player1->m_x - this->m_x) < 10) m_xvel=0;
tangent = (player1->m_y - this->m_y) / (player1->m_x - this->m_x) ;
this->m_yvel *= (abs(sinf(atan(tangent))));
this->m_xvel *= (abs(cosf(atan(tangent))));
if(player1->m_x - this->m_x > 0 && player1->m_y - this->m_y < 0) {
m_yvel*=-1;
}else if(player1->m_x - this->m_x < 0 && player1->m_y - this->m_y> 0) {
m_xvel*=-1;
}else if(player1->m_x - this->m_x < 0 && player1->m_y - this->m_y< 0) {
m_yvel*=-1;
m_xvel*=-1;
}
this->m_y += m_yvel;
this->m_x += m_xvel; //* (player1->m_x - this->m_x>0 && m_xvel >0 ?1:-1);
}
Hiç yorum yok:
Yorum Gönder