Implemented blocking. Made player abilities dynamic instead of fixed for class expansion preparation.

This commit is contained in:
2023-06-17 21:19:08 -05:00
parent 75b763e87b
commit e090bc775d
11 changed files with 183 additions and 26 deletions
+30 -12
View File
@@ -12,14 +12,13 @@ INCLUDE_DAMAGENUMBER_LIST
INCLUDE_game
const float Player::GROUND_SLAM_SPIN_TIME=0.6f;
const float Player::GROUND_SLAM_COOLDOWN=20;
Player::Player():
state(State::NORMAL),lastReleasedMovementKey(DOWN),facingDirection(DOWN){
}
Player::Player(vf2d pos):
pos(pos),state(State::NORMAL),lastReleasedMovementKey(DOWN),facingDirection(DOWN){
state(State::NORMAL),lastReleasedMovementKey(DOWN),facingDirection(DOWN),
rightClickAbility("Block",15,VERY_DARK_BLUE,DARK_BLUE),
ability1("Battlecry",12),
ability2("Ground Slam",15),
ability3("Sonic Slash",40){
}
void Player::SetX(float x){
@@ -125,13 +124,23 @@ void Player::Update(float fElapsedTime){
if(lastAnimationFlip>0){
lastAnimationFlip=std::max(0.f,lastAnimationFlip-fElapsedTime);
}
animation.UpdateState(internal_animState,fElapsedTime);
}break;
case BLOCK:{
if(rightClickAbility.COOLDOWN_TIME-rightClickAbility.cooldown>3){
state=NORMAL;
}
}break;
default:{
//Update animations normally.
//Update animations normally.
moveSpd=1.0;
animation.UpdateState(internal_animState,fElapsedTime);
}
}
animation.UpdateState(internal_animState,fElapsedTime);
groundSlamCooldown=std::max(0.f,groundSlamCooldown-fElapsedTime);
rightClickAbility.cooldown=std::max(0.f,rightClickAbility.cooldown-fElapsedTime);
ability1.cooldown=std::max(0.f,ability1.cooldown-fElapsedTime);
ability2.cooldown=std::max(0.f,ability2.cooldown-fElapsedTime);
ability3.cooldown=std::max(0.f,ability3.cooldown-fElapsedTime);
for(Monster&m:MONSTER_LIST){
if(iframe_time==0&&geom2d::overlaps(geom2d::circle(pos,12*size/2),geom2d::circle(m.GetPos(),12*m.GetSizeMult()/2))){
if(m.IsAlive()){
@@ -195,6 +204,11 @@ void Player::Update(float fElapsedTime){
}
}
}
if(rightClickAbility.cooldown==0&&GetState()==State::NORMAL&&game->GetMouse(1).bHeld){
rightClickAbility.cooldown=rightClickAbility.COOLDOWN_TIME;
SetState(State::BLOCK);
moveSpd=0.7;
}
}
float Player::GetSwordSwingTimer(){
@@ -219,6 +233,7 @@ bool Player::HasIframes(){
bool Player::Hurt(int damage){
if(hp<=0||iframe_time!=0) return false;
if(state==State::BLOCK)damage=0;
hp=std::max(0,hp-damage);
DAMAGENUMBER_LIST.push_back(DamageNumber(pos,damage));
}
@@ -259,8 +274,11 @@ void Player::Moved(){
}
}
float Player::GetGroundSlamCooldown(){
return groundSlamCooldown;
float Player::GetAbility2Cooldown(){
return ability2.cooldown;
}
float Player::GetRightClickCooldown(){
return rightClickAbility.cooldown;
}
void Player::Spin(float duration,float spinSpd){
@@ -268,5 +286,5 @@ void Player::Spin(float duration,float spinSpd){
spin_attack_timer=duration;
spin_spd=spinSpd;
spin_angle=0;
groundSlamCooldown=GROUND_SLAM_COOLDOWN;
ability2.cooldown=ability2.COOLDOWN_TIME;
}