Implement Iframes for the player when performing a Ground Slam.

pull/28/head
sigonasr2 1 year ago
parent 4b98518fcf
commit 75b763e87b
  1. 10
      Crawler/Crawler.cpp
  2. 2
      Crawler/Monster.cpp
  3. 11
      Crawler/Player.cpp
  4. 4
      Crawler/Player.h

@ -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.x<view.GetWorldTL().x||b.pos.x>view.GetWorldBR().x||b.pos.y<view.GetWorldTL().y||b.pos.y>view.GetWorldBR().y){

@ -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));

@ -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));
}

@ -24,6 +24,7 @@ private:
float lastAnimationFlip=0;
float groundSlamCooldown=0;
float swordSwingTimer=0;
float iframe_time=0;
State state=State::NORMAL;
Animate2D::Animation<AnimationState>animation;
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();

Loading…
Cancel
Save