diff --git a/Crawler/Crawler.cpp b/Crawler/Crawler.cpp index c686bde6..ef1832b9 100644 --- a/Crawler/Crawler.cpp +++ b/Crawler/Crawler.cpp @@ -223,6 +223,7 @@ void Crawler::HandleUserInput(float fElapsedTime){ bool setIdleAnimation=true; if(GetKey(SPACE).bPressed&&player.GetState()==State::NORMAL&&player.GetGroundSlamCooldown()==0){ player.Spin(Player::GROUND_SLAM_SPIN_TIME,14*PI); + player.iframe_time=Player::GROUND_SLAM_SPIN_TIME; } if(player.GetVelocity()==vf2d{0,0}){ if(RightHeld()){ @@ -414,10 +415,11 @@ void Crawler::UpdateBullets(float fElapsedTime){ Bullet&b=*it; b.pos+=b.vel*fElapsedTime; if(geom2d::overlaps(geom2d::circle(player.GetPos(),12*player.GetSizeMult()/2),geom2d::circle(b.pos,b.radius))){ - player.Hurt(b.damage); - it=BULLET_LIST.erase(it); - if(it==BULLET_LIST.end()){ - break; + if(player.Hurt(b.damage)){ + it=BULLET_LIST.erase(it); + if(it==BULLET_LIST.end()){ + break; + } } } if(b.pos.xview.GetWorldBR().x||b.pos.yview.GetWorldBR().y){ diff --git a/Crawler/Monster.cpp b/Crawler/Monster.cpp index 4544c5ca..140b5974 100644 --- a/Crawler/Monster.cpp +++ b/Crawler/Monster.cpp @@ -125,7 +125,7 @@ bool Monster::Update(float fElapsedTime){ } } } - if(geom2d::overlaps(geom2d::circle(pos,12*size/2),geom2d::circle(game->GetPlayer().GetPos(),12*game->GetPlayer().GetSizeMult()/2))){ + if(!game->GetPlayer().HasIframes()&&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)); diff --git a/Crawler/Player.cpp b/Crawler/Player.cpp index 3c127680..eb79b3cc 100644 --- a/Crawler/Player.cpp +++ b/Crawler/Player.cpp @@ -88,6 +88,7 @@ State Player::GetState(){ void Player::Update(float fElapsedTime){ attack_cooldown_timer=std::max(0.f,attack_cooldown_timer-fElapsedTime); + iframe_time=std::max(0.f,iframe_time-fElapsedTime); switch(state){ case SPIN:{ switch(facingDirection){ @@ -132,7 +133,7 @@ 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(iframe_time==0&&geom2d::overlaps(geom2d::circle(pos,12*size/2),geom2d::circle(m.GetPos(),12*m.GetSizeMult()/2))){ if(m.IsAlive()){ m.Collision(*this); } @@ -212,8 +213,12 @@ vf2d Player::GetVelocity(){ return vel; } -void Player::Hurt(int damage){ - if(hp<=0) return; +bool Player::HasIframes(){ + return iframe_time>0; +} + +bool Player::Hurt(int damage){ + if(hp<=0||iframe_time!=0) return false; hp=std::max(0,hp-damage); DAMAGENUMBER_LIST.push_back(DamageNumber(pos,damage)); } diff --git a/Crawler/Player.h b/Crawler/Player.h index 8b63385e..f57d094b 100644 --- a/Crawler/Player.h +++ b/Crawler/Player.h @@ -24,6 +24,7 @@ private: float lastAnimationFlip=0; float groundSlamCooldown=0; float swordSwingTimer=0; + float iframe_time=0; State state=State::NORMAL; Animate2D::Animationanimation; Animate2D::AnimationState internal_animState; @@ -60,8 +61,9 @@ public: State GetState(); Key GetFacingDirection(); vf2d GetVelocity(); + bool HasIframes(); - void Hurt(int damage); + bool Hurt(int damage); void UpdateAnimation(AnimationState animState); Animate2D::Frame GetFrame(); Key GetLastReleasedMovementKey();