Implement Iframes for the player when performing a Ground Slam.
This commit is contained in:
parent
4b98518fcf
commit
75b763e87b
@ -223,6 +223,7 @@ void Crawler::HandleUserInput(float fElapsedTime){
|
|||||||
bool setIdleAnimation=true;
|
bool setIdleAnimation=true;
|
||||||
if(GetKey(SPACE).bPressed&&player.GetState()==State::NORMAL&&player.GetGroundSlamCooldown()==0){
|
if(GetKey(SPACE).bPressed&&player.GetState()==State::NORMAL&&player.GetGroundSlamCooldown()==0){
|
||||||
player.Spin(Player::GROUND_SLAM_SPIN_TIME,14*PI);
|
player.Spin(Player::GROUND_SLAM_SPIN_TIME,14*PI);
|
||||||
|
player.iframe_time=Player::GROUND_SLAM_SPIN_TIME;
|
||||||
}
|
}
|
||||||
if(player.GetVelocity()==vf2d{0,0}){
|
if(player.GetVelocity()==vf2d{0,0}){
|
||||||
if(RightHeld()){
|
if(RightHeld()){
|
||||||
@ -414,10 +415,11 @@ void Crawler::UpdateBullets(float fElapsedTime){
|
|||||||
Bullet&b=*it;
|
Bullet&b=*it;
|
||||||
b.pos+=b.vel*fElapsedTime;
|
b.pos+=b.vel*fElapsedTime;
|
||||||
if(geom2d::overlaps(geom2d::circle(player.GetPos(),12*player.GetSizeMult()/2),geom2d::circle(b.pos,b.radius))){
|
if(geom2d::overlaps(geom2d::circle(player.GetPos(),12*player.GetSizeMult()/2),geom2d::circle(b.pos,b.radius))){
|
||||||
player.Hurt(b.damage);
|
if(player.Hurt(b.damage)){
|
||||||
it=BULLET_LIST.erase(it);
|
it=BULLET_LIST.erase(it);
|
||||||
if(it==BULLET_LIST.end()){
|
if(it==BULLET_LIST.end()){
|
||||||
break;
|
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){
|
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());
|
geom2d::line line(pos,game->GetPlayer().GetPos());
|
||||||
float dist = line.length();
|
float dist = line.length();
|
||||||
SetPosition(line.rpoint(-0.1));
|
SetPosition(line.rpoint(-0.1));
|
||||||
|
@ -88,6 +88,7 @@ State Player::GetState(){
|
|||||||
|
|
||||||
void Player::Update(float fElapsedTime){
|
void Player::Update(float fElapsedTime){
|
||||||
attack_cooldown_timer=std::max(0.f,attack_cooldown_timer-fElapsedTime);
|
attack_cooldown_timer=std::max(0.f,attack_cooldown_timer-fElapsedTime);
|
||||||
|
iframe_time=std::max(0.f,iframe_time-fElapsedTime);
|
||||||
switch(state){
|
switch(state){
|
||||||
case SPIN:{
|
case SPIN:{
|
||||||
switch(facingDirection){
|
switch(facingDirection){
|
||||||
@ -132,7 +133,7 @@ void Player::Update(float fElapsedTime){
|
|||||||
animation.UpdateState(internal_animState,fElapsedTime);
|
animation.UpdateState(internal_animState,fElapsedTime);
|
||||||
groundSlamCooldown=std::max(0.f,groundSlamCooldown-fElapsedTime);
|
groundSlamCooldown=std::max(0.f,groundSlamCooldown-fElapsedTime);
|
||||||
for(Monster&m:MONSTER_LIST){
|
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()){
|
if(m.IsAlive()){
|
||||||
m.Collision(*this);
|
m.Collision(*this);
|
||||||
}
|
}
|
||||||
@ -212,8 +213,12 @@ vf2d Player::GetVelocity(){
|
|||||||
return vel;
|
return vel;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::Hurt(int damage){
|
bool Player::HasIframes(){
|
||||||
if(hp<=0) return;
|
return iframe_time>0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Player::Hurt(int damage){
|
||||||
|
if(hp<=0||iframe_time!=0) return false;
|
||||||
hp=std::max(0,hp-damage);
|
hp=std::max(0,hp-damage);
|
||||||
DAMAGENUMBER_LIST.push_back(DamageNumber(pos,damage));
|
DAMAGENUMBER_LIST.push_back(DamageNumber(pos,damage));
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@ private:
|
|||||||
float lastAnimationFlip=0;
|
float lastAnimationFlip=0;
|
||||||
float groundSlamCooldown=0;
|
float groundSlamCooldown=0;
|
||||||
float swordSwingTimer=0;
|
float swordSwingTimer=0;
|
||||||
|
float iframe_time=0;
|
||||||
State state=State::NORMAL;
|
State state=State::NORMAL;
|
||||||
Animate2D::Animation<AnimationState>animation;
|
Animate2D::Animation<AnimationState>animation;
|
||||||
Animate2D::AnimationState internal_animState;
|
Animate2D::AnimationState internal_animState;
|
||||||
@ -60,8 +61,9 @@ public:
|
|||||||
State GetState();
|
State GetState();
|
||||||
Key GetFacingDirection();
|
Key GetFacingDirection();
|
||||||
vf2d GetVelocity();
|
vf2d GetVelocity();
|
||||||
|
bool HasIframes();
|
||||||
|
|
||||||
void Hurt(int damage);
|
bool Hurt(int damage);
|
||||||
void UpdateAnimation(AnimationState animState);
|
void UpdateAnimation(AnimationState animState);
|
||||||
Animate2D::Frame GetFrame();
|
Animate2D::Frame GetFrame();
|
||||||
Key GetLastReleasedMovementKey();
|
Key GetLastReleasedMovementKey();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user