Add in multi-key mapping for same key actions.

pull/28/head
sigonasr2 1 year ago
parent 7c542740cc
commit b5b7097418
  1. 73
      Crawler/Crawler.cpp
  2. 8
      Crawler/Crawler.h

@ -143,12 +143,37 @@ void Crawler::InitializeAnimations(){
ANIMATION_DATA[AnimationState::GROUND_SLAM_ATTACK_FRONT]=effect_groundslam_front;
}
bool Crawler::LeftHeld(){
return GetKey(LEFT).bHeld|GetKey(A).bHeld;
}
bool Crawler::RightHeld(){
return GetKey(RIGHT).bHeld|GetKey(D).bHeld;
}
bool Crawler::UpHeld(){
return GetKey(UP).bHeld|GetKey(W).bHeld;
}
bool Crawler::DownHeld(){
return GetKey(DOWN).bHeld|GetKey(S).bHeld;
}
bool Crawler::LeftReleased(){
return GetKey(LEFT).bReleased|GetKey(A).bReleased;
}
bool Crawler::RightReleased(){
return GetKey(RIGHT).bReleased|GetKey(D).bReleased;
}
bool Crawler::UpReleased(){
return GetKey(UP).bReleased|GetKey(W).bReleased;
}
bool Crawler::DownReleased(){
return GetKey(DOWN).bReleased|GetKey(S).bReleased;
}
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);
}
if(GetKey(RIGHT).bHeld){
if(RightHeld()){
if(player.GetPos().x+12+fElapsedTime*100*player.GetMoveSpdMult()<WORLD_SIZE.x*24){
player.SetX(player.GetX()+fElapsedTime*100*player.GetMoveSpdMult());
} else {
@ -158,7 +183,7 @@ void Crawler::HandleUserInput(float fElapsedTime){
player.UpdateAnimation(AnimationState::WALK_E);
setIdleAnimation=false;
}
if(GetKey(LEFT).bHeld){
if(LeftHeld()){
if(player.GetPos().x-12+fElapsedTime*100*player.GetMoveSpdMult()>0){
player.SetX(player.GetX()-fElapsedTime*100*player.GetMoveSpdMult());
} else {
@ -170,7 +195,7 @@ void Crawler::HandleUserInput(float fElapsedTime){
}
setIdleAnimation=false;
}
if(GetKey(UP).bHeld){
if(UpHeld()){
if(player.GetPos().y-12+fElapsedTime*100*player.GetMoveSpdMult()>0){
player.SetY(player.GetY()-fElapsedTime*100*player.GetMoveSpdMult());
} else {
@ -182,7 +207,7 @@ void Crawler::HandleUserInput(float fElapsedTime){
}
setIdleAnimation=false;
}
if(GetKey(DOWN).bHeld){
if(DownHeld()){
if(player.GetPos().y+12+fElapsedTime*100*player.GetMoveSpdMult()<WORLD_SIZE.y*24){
player.SetY(player.GetY()+fElapsedTime*100*player.GetMoveSpdMult());
} else {
@ -195,51 +220,51 @@ void Crawler::HandleUserInput(float fElapsedTime){
setIdleAnimation=false;
}
if(GetKey(UP).bReleased){
if(UpReleased()){
player.SetLastReleasedMovementKey(UP);
if(GetKey(RIGHT).bHeld){
if(RightHeld()){
player.UpdateAnimation(AnimationState::WALK_E);
} else
if(GetKey(DOWN).bHeld){
player.UpdateAnimation(AnimationState::WALK_S);
} else
if(GetKey(LEFT).bHeld){
player.UpdateAnimation(AnimationState::WALK_W);
}
if(DownHeld()){
player.UpdateAnimation(AnimationState::WALK_S);
} else
if(LeftHeld()){
player.UpdateAnimation(AnimationState::WALK_W);
}
}
if(GetKey(RIGHT).bReleased){
if(RightReleased()){
player.SetLastReleasedMovementKey(RIGHT);
if(GetKey(UP).bHeld){
if(UpHeld()){
player.UpdateAnimation(AnimationState::WALK_N);
} else
if(GetKey(DOWN).bHeld){
if(DownHeld()){
player.UpdateAnimation(AnimationState::WALK_S);
} else
if(GetKey(LEFT).bHeld){
if(LeftHeld()){
player.UpdateAnimation(AnimationState::WALK_W);
}
}
if(GetKey(LEFT).bReleased){
if(LeftReleased()){
player.SetLastReleasedMovementKey(LEFT);
if(GetKey(RIGHT).bHeld){
if(RightHeld()){
player.UpdateAnimation(AnimationState::WALK_E);
} else
if(GetKey(DOWN).bHeld){
if(DownHeld()){
player.UpdateAnimation(AnimationState::WALK_S);
} else
if(GetKey(UP).bHeld){
if(UpHeld()){
player.UpdateAnimation(AnimationState::WALK_N);
}
}
if(GetKey(DOWN).bReleased){
if(DownReleased()){
player.SetLastReleasedMovementKey(DOWN);
if(GetKey(RIGHT).bHeld){
if(RightHeld()){
player.UpdateAnimation(AnimationState::WALK_E);
} else
if(GetKey(UP).bHeld){
if(UpHeld()){
player.UpdateAnimation(AnimationState::WALK_N);
} else
if(GetKey(LEFT).bHeld){
if(LeftHeld()){
player.UpdateAnimation(AnimationState::WALK_W);
}
}

@ -33,4 +33,12 @@ public:
void AddEffect(Effect foreground,Effect background);
void HurtEnemies(vf2d pos,float radius,int damage);
vf2d GetWorldMousePos();
bool LeftHeld();
bool RightHeld();
bool UpHeld();
bool DownHeld();
bool LeftReleased();
bool RightReleased();
bool UpReleased();
bool DownReleased();
};
Loading…
Cancel
Save