Bounce collisions occur between units.
This commit is contained in:
@@ -131,6 +131,37 @@ void Player::Update(float fElapsedTime){
|
||||
}
|
||||
animation.UpdateState(internal_animState,fElapsedTime);
|
||||
groundSlamCooldown=std::max(0.f,groundSlamCooldown-fElapsedTime);
|
||||
for(Monster&m:MONSTER_LIST){
|
||||
if(geom2d::overlaps(geom2d::circle(pos,12*size/2),geom2d::circle(m.GetPos(),12*m.GetSizeMult()/2))){
|
||||
if(m.IsAlive()){
|
||||
m.Collision(*this);
|
||||
}
|
||||
geom2d::line line(pos,m.GetPos());
|
||||
float dist = line.length();
|
||||
m.SetPosition(line.rpoint(dist*1.1));
|
||||
if(m.IsAlive()){
|
||||
vel=line.vector().norm()*-128;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(vel.x>0){
|
||||
vel.x=std::max(0.f,vel.x-friction*fElapsedTime);
|
||||
} else {
|
||||
vel.x=std::min(0.f,vel.x+friction*fElapsedTime);
|
||||
}
|
||||
if(vel.y>0){
|
||||
vel.y=std::max(0.f,vel.y-friction*fElapsedTime);
|
||||
} else {
|
||||
vel.y=std::min(0.f,vel.y+friction*fElapsedTime);
|
||||
}
|
||||
float newX=pos.x+vel.x*fElapsedTime;
|
||||
if(newX-12*size>0&&newX+12*size<game->WORLD_SIZE.x*24){
|
||||
pos.x=newX;
|
||||
}
|
||||
float newY=pos.y+vel.y*fElapsedTime;
|
||||
if(newY-12*size>0&&newY+12*size<game->WORLD_SIZE.y*24){
|
||||
pos.y=newY;
|
||||
}
|
||||
if(attack_cooldown_timer==0&&game->GetMouse(0).bHeld){
|
||||
bool attack=false;
|
||||
Monster*closest=nullptr;
|
||||
@@ -149,6 +180,10 @@ void Player::Update(float fElapsedTime){
|
||||
}
|
||||
}
|
||||
|
||||
vf2d Player::GetVelocity(){
|
||||
return vel;
|
||||
}
|
||||
|
||||
void Player::Hurt(int damage){
|
||||
if(hp<=0) return;
|
||||
hp=std::max(0,hp-damage);
|
||||
|
||||
Reference in New Issue
Block a user