Advertisement
Berhoh

Iji

Oct 11th, 2017
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.30 KB | None | 0 0
  1. void Iji::Move()
  2. {
  3.     //is Iji moving?
  4.     m_IsMoving = (m_CanMove && ((GAME_ENGINE->IsKeyboardKeyDown(m_KeysArr[0]) && m_Direction == -1) ||
  5.         (GAME_ENGINE->IsKeyboardKeyDown(m_KeysArr[1]) && m_Direction == 1)));
  6.     if (m_IsMoving && m_IsOnGround && m_ActionState != ActionState::WALKING)
  7.     {
  8.         if (m_ActionState != ActionState::STANDING)
  9.             SoundManager::SoundPlay(String("Resources/Audio/Iji/snd_iji_land.wav"), SoundManager::SoundType::SFX);
  10.  
  11.         m_ActionState = ActionState::WALKING;
  12.     }
  13.  
  14.     //press left
  15.     if (GAME_ENGINE->IsKeyboardKeyPressed(m_KeysArr[0]) && m_CanMove)
  16.         m_Direction = -1;
  17.  
  18.     //press right
  19.     if (GAME_ENGINE->IsKeyboardKeyPressed(m_KeysArr[1]) && m_CanMove)
  20.         m_Direction = 1;
  21.  
  22.     //move/release left
  23.     if (m_Direction == -1)
  24.     {
  25.         if (GAME_ENGINE->IsKeyboardKeyDown(m_KeysArr[0]) &&
  26.             m_CanMove)
  27.             m_ActPtr->SetLinearVelocity(DOUBLE2(-m_HorSpeed, m_ActPtr->GetLinearVelocity().y));
  28.        
  29.         if (GAME_ENGINE->IsKeyboardKeyDown(m_KeysArr[0]) == false &&
  30.             m_IsOnGround &&
  31.             (m_ActionState == ActionState::WALKING ||
  32.             m_ActionState == ActionState::FALLING ||
  33.             m_ActionState == ActionState::JUMPING))
  34.         {
  35.             if (m_ActionState != ActionState::WALKING)
  36.                 SoundManager::SoundPlay(String("Resources/Audio/Iji/snd_iji_land.wav"), SoundManager::SoundType::SFX);
  37.  
  38.             m_ActPtr->SetLinearVelocity(DOUBLE2(0, m_ActPtr->GetLinearVelocity().y));
  39.             m_ActionState = ActionState::STANDING;
  40.         }
  41.     }
  42.  
  43.     //move/release right
  44.     if (m_Direction == 1)
  45.     {
  46.         if (GAME_ENGINE->IsKeyboardKeyDown(m_KeysArr[1]) &&
  47.             m_CanMove)
  48.             m_ActPtr->SetLinearVelocity(DOUBLE2(m_HorSpeed, m_ActPtr->GetLinearVelocity().y));
  49.        
  50.         if(GAME_ENGINE->IsKeyboardKeyDown(m_KeysArr[1]) == false &&
  51.             m_IsOnGround &&
  52.             (m_ActionState == ActionState::WALKING ||
  53.             m_ActionState == ActionState::FALLING ||
  54.             m_ActionState == ActionState::JUMPING))
  55.         {
  56.             if (m_ActionState != ActionState::WALKING)
  57.                 SoundManager::SoundPlay(String("Resources/Audio/Iji/snd_iji_land.wav"), SoundManager::SoundType::SFX);
  58.  
  59.             m_ActPtr->SetLinearVelocity(DOUBLE2(0, m_ActPtr->GetLinearVelocity().y));
  60.             m_ActionState = ActionState::STANDING;
  61.         }
  62.     }
  63.  
  64.     if (m_IsOnGround)
  65.     {
  66.         m_FallTime = 0;
  67.  
  68.         //jump
  69.         if (GAME_ENGINE->IsKeyboardKeyPressed(m_KeysArr[2]) && m_CanMove &&
  70.             (m_ElevatorPtr ==nullptr || m_ElevatorPtr->CanGoUp()==false))
  71.         {
  72.             m_ActPtr->SetLinearVelocity(DOUBLE2(m_ActPtr->GetLinearVelocity().x, -m_JumpSpeed));
  73.             m_JumpTime = 10;
  74.             m_ActionState = ActionState::JUMPING;
  75.  
  76.             if (rand()%6==0)
  77.             SoundManager::SoundPlay(String("Resources/Audio/Iji/snd_iji_jump.wav"), SoundManager::SoundType::SFX);
  78.         }
  79.     }
  80.  
  81.     if (m_ActionState != ActionState::JUMPING && m_ActionState!=ActionState::ELEVATOR && !m_IsOnGround)
  82.         ++m_FallTime;
  83.  
  84.     if (m_FallTime>10 && m_ActionState!=ActionState::FALLING && m_ActionState!=ActionState::FLYING)
  85.         m_ActionState = ActionState::FALLING;
  86.  
  87.     //thrown onto ground
  88.     if (m_ActionState == ActionState::FLYING && m_IsOnGround)
  89.         m_ActionState = ActionState::LYING;
  90.  
  91.     //get up from ground
  92.     if (m_ActionState == ActionState::LYING &&
  93.         m_Dead==false && (
  94.         GAME_ENGINE->IsKeyboardKeyPressed(m_KeysArr[0]) ||
  95.         GAME_ENGINE->IsKeyboardKeyPressed(m_KeysArr[1]) ||
  96.         GAME_ENGINE->IsKeyboardKeyPressed(m_KeysArr[2]) ||
  97.         GAME_ENGINE->IsKeyboardKeyPressed(m_KeysArr[3])))
  98.         m_ActionState = ActionState::GETUP;
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement