Finished implementing Ground Slam effect, cooldown display, and range hit.

pull/28/head
sigonasr2 2 years ago
parent 7e543a3021
commit 3aebde6287
  1. 20
      Crawler/Crawler.cpp
  2. 2
      Crawler/Crawler.h
  3. 4
      Crawler/Effect.cpp
  4. 3
      Crawler/Effect.h
  5. 4
      Crawler/Monster.cpp
  6. 3
      Crawler/Monster.h
  7. 19
      Crawler/Player.cpp
  8. 4
      Crawler/Player.h

@ -61,6 +61,7 @@ bool Crawler::OnUserUpdate(float fElapsedTime){
}
UpdateCamera(fElapsedTime);
RenderWorld(fElapsedTime);
RenderHud();
return true;
}
@ -125,7 +126,7 @@ void Crawler::InitializeAnimations(){
void Crawler::HandleUserInput(float fElapsedTime){
bool setIdleAnimation=true;
if(GetKey(SPACE).bPressed&&player.GetState()==State::NORMAL){
if(GetKey(SPACE).bPressed&&player.GetState()==State::NORMAL&&player.GetGroundSlamCooldown()==0){
player.Spin(Player::GROUND_SLAM_SPIN_TIME,14*PI);
}
if(GetKey(RIGHT).bHeld){
@ -273,6 +274,13 @@ void Crawler::UpdateEffects(float fElapsedTime){
}
}
}
void Crawler::HurtEnemies(vf2d pos,float radius,int damage){
for(Monster&m:MONSTER_LIST){
if(geom2d::overlaps(geom2d::circle(pos,radius),geom2d::circle(m.GetPos(),12*m.GetSizeMult()))){
m.Hurt(damage);
}
}
}
void Crawler::RenderWorld(float fElapsedTime){
Clear({100,180,100});
@ -320,6 +328,16 @@ void Crawler::RenderWorld(float fElapsedTime){
}
}
void Crawler::RenderHud(){
if(player.GetGroundSlamCooldown()>0){
FillRectDecal({10,ScreenHeight()-22.f},{64,6},BLACK);
FillRectDecal({11,ScreenHeight()-21.f},{62,4},DARK_GREY);
GradientFillRectDecal({10,ScreenHeight()-22.f},{(player.GetGroundSlamCooldown()/Player::GROUND_SLAM_COOLDOWN)*64,6},VERY_DARK_RED,VERY_DARK_RED,DARK_RED,DARK_RED);
DrawRotatedStringPropDecal(vf2d{8,ScreenHeight()-20.f}+vf2d{1,1},"G R O U N D S L A M",-PI/64,{0,0},BLACK,{0.4,0.4});
DrawRotatedStringPropDecal({8,ScreenHeight()-20.f},"G R O U N D S L A M",-PI/64,{0,0},WHITE,{0.4,0.4});
}
}
void Crawler::AddEffect(Effect foreground,Effect background){
foregroundEffects.push_back(foreground);
backgroundEffects.push_back(background);

@ -29,5 +29,7 @@ public:
void UpdateCamera(float fElapsedTime);
void UpdateEffects(float fElapsedTime);
void RenderWorld(float fElapsedTime);
void RenderHud();
void AddEffect(Effect foreground,Effect background);
void HurtEnemies(vf2d pos,float radius,int damage);
};

@ -5,8 +5,8 @@
INCLUDE_ANIMATION_DATA
INCLUDE_game
Effect::Effect(vf2d pos,float lifetime,AnimationState animation,float fadeout)
:pos(pos),lifetime(lifetime),fadeout(fadeout),original_fadeoutTime(fadeout){
Effect::Effect(vf2d pos,float lifetime,AnimationState animation,float size,float fadeout)
:pos(pos),lifetime(lifetime),size(size),fadeout(fadeout),original_fadeoutTime(fadeout){
this->animation.AddState(animation,ANIMATION_DATA[animation]);
}

@ -7,7 +7,8 @@ struct Effect{
vf2d pos;
float lifetime;
float fadeout;
Effect(vf2d pos,float lifetime,AnimationState animation,float fadeout=0.0f);
float size;
Effect(vf2d pos,float lifetime,AnimationState animation,float size=1.0f,float fadeout=0.0f);
bool Update(float fElapsedTime);
Animate2D::Frame GetFrame();
void Draw();

@ -98,12 +98,14 @@ AnimationState Monster::GetDeathAnimationName(){
}
}
}
void Monster::Hurt(int damage){
bool Monster::Hurt(int damage){
if(hp<=0) return false;
hp=std::max(0,hp-damage);
DAMAGENUMBER_LIST.push_back(DamageNumber(pos,damage));
if(hp<=0){
animation.ChangeState(internal_animState,GetDeathAnimationName());
}
return true;
}
bool Monster::IsAlive(){

@ -64,7 +64,8 @@ struct Monster{
Animate2D::Frame GetFrame();
void UpdateAnimation(AnimationState state);
bool Update(float fElapsedTime);
void Hurt(int damage);
//Returns true when damage is actually dealt (there is a death check here.)
bool Hurt(int damage);
bool IsAlive();
};

@ -12,6 +12,7 @@ INCLUDE_DAMAGENUMBER_LIST
INCLUDE_game
const float Player::GROUND_SLAM_SPIN_TIME=0.6f;
const float Player::GROUND_SLAM_COOLDOWN=20;
Player::Player(){
}
@ -116,7 +117,8 @@ void Player::Update(float fElapsedTime){
state=NORMAL;
spin_angle=0;
z=0;
game->AddEffect(Effect{GetPos(),0.5,AnimationState::GROUND_SLAM_ATTACK_FRONT,0.6f},Effect{GetPos(),0.5,AnimationState::GROUND_SLAM_ATTACK_BACK,0.6f});
game->HurtEnemies(pos,3*12,atk*2.5);
game->AddEffect(Effect{GetPos(),0.5,AnimationState::GROUND_SLAM_ATTACK_FRONT,1.33f,0.6f},Effect{GetPos(),0.5,AnimationState::GROUND_SLAM_ATTACK_BACK,1.33f,0.6f});
}
if(lastAnimationFlip>0){
lastAnimationFlip=std::max(0.f,lastAnimationFlip-fElapsedTime);
@ -128,13 +130,15 @@ void Player::Update(float fElapsedTime){
[[fallthrough]];
}
animation.UpdateState(internal_animState,fElapsedTime);
groundSlamCooldown=std::max(0.f,groundSlamCooldown-fElapsedTime);
if(attack_cooldown_timer==0&&game->GetMouse(0).bHeld){
bool attack=false;
for(Monster&m:MONSTER_LIST){
if(m.IsAlive()&&geom2d::overlaps(geom2d::circle<float>(pos-vf2d{size*12,size*12},attack_range*size*12),geom2d::circle<float>(m.GetPos()-vf2d{m.GetSizeMult()*12,m.GetSizeMult()*12},m.GetSizeMult()*12))){
m.Hurt(atk);
attack=true;
break;
if(geom2d::overlaps(geom2d::circle<float>(pos-vf2d{size*12,size*12},attack_range*size*12),geom2d::circle<float>(m.GetPos()-vf2d{m.GetSizeMult()*12,m.GetSizeMult()*12},m.GetSizeMult()*12))){
if(m.Hurt(atk)){
attack=true;
break;
}
}
}
if(attack){
@ -184,9 +188,14 @@ void Player::Moved(){
}
}
float Player::GetGroundSlamCooldown(){
return groundSlamCooldown;
}
void Player::Spin(float duration,float spinSpd){
state=State::SPIN;
spin_attack_timer=duration;
spin_spd=spinSpd;
spin_angle=0;
groundSlamCooldown=GROUND_SLAM_COOLDOWN;
}

@ -19,6 +19,7 @@ private:
float spin_spd=0;
float spin_angle=0;
float lastAnimationFlip=0;
float groundSlamCooldown=0;
State state;
Animate2D::Animation<AnimationState>animation;
Animate2D::AnimationState internal_animState;
@ -28,6 +29,7 @@ public:
Player();
Player(vf2d pos);
const static float GROUND_SLAM_SPIN_TIME;
const static float GROUND_SLAM_COOLDOWN;
void SetX(float x);
void SetY(float y);
void SetZ(float z);
@ -57,6 +59,8 @@ public:
void SetLastReleasedMovementKey(Key k);
Key GetLastReleasedMovementKey();
float GetGroundSlamCooldown();
//Triggers when the player has moved.
void Moved();
};
Loading…
Cancel
Save