Posted By

philm on 01/14/14


Tagged

space c++ Alien Shooter


Versions (?)

Alien Space Shooter - Handle Input function


 / Published in: C++
 

This is the handleInput function from the Game.cpp of Alien Space Shooter, an iPhone game.

  1. void Game::handleInput(TouchType touchType, float locationX, float locationY)
  2. {
  3. if(touchType == TOUCH_BEGAN)
  4. {
  5. for(int i = 0; i < NUMBER_OF_ENEMIES; i++)
  6. {
  7. if(m_Enemies[i] != NULL)
  8. if(locationX >= m_Enemies[i]->getX() && locationX <= m_Enemies[i]->getX() + m_Enemies[i]->getWidth() &&
  9. locationY >= m_Enemies[i]->getY() && locationY <= m_Enemies[i]->getY() + m_Enemies[i]->getHeight())
  10. {
  11. m_Enemies[i]->setHealth(m_Enemies[i]->getHealth() - 1);
  12. int randomSound = (rand() % 4) + 1;
  13. if(randomSound == 1) // Plays a random Shoot sound.
  14. AudioWrapper::playSoundEffect(m_Shoot1_SFX);
  15. else if (randomSound == 2)
  16. AudioWrapper::playSoundEffect(m_Shoot2_SFX);
  17. else if (randomSound == 3)
  18. AudioWrapper::playSoundEffect(m_Shoot3_SFX);
  19. else if (randomSound == 4)
  20. AudioWrapper::playSoundEffect(m_Shoot4_SFX);
  21. if(m_Enemies[i]->getHealth() <= 0)
  22. {
  23. if(m_Enemies[i]->getColor() == 'p')
  24. {
  25. AudioWrapper::playSoundEffect(m_AlienDeathPurple_SFX);
  26. m_CurrentScore += m_Enemies[i]->getScoreModifier();
  27. setEnemiesKilled(getEnemiesKilled() + 1);
  28. }
  29. else if(m_Enemies[i]->getColor() == 'z')
  30. {
  31. AudioWrapper::playSoundEffect(m_BossDeath_SFX);
  32. m_CurrentScore += m_Enemies[i]->getScoreModifier();
  33. setEnemiesKilled(getEnemiesKilled() + 1);
  34. }
  35. else if(m_Enemies[i]->getColor() == 'a' || m_Enemies[i]->getColor() == 'y' || m_Enemies[i]->getColor() == 'b')
  36. {
  37. m_CurrentScore += (m_Enemies[i]->getScoreModifier() * m_Enemies[i]->getVelocityX()) * -1;
  38. setEnemiesKilled(getEnemiesKilled() + 1);
  39. }
  40.  
  41. CollisionManager::getInstance()->removeCollider(CollisionManager::getInstance()->getColliderForEntity(m_Enemies[i]));
  42. delete m_Enemies[i];
  43. m_Enemies[i] = NULL;
  44.  
  45. m_MaxSpeed += 5;
  46. m_MinSpeed += 5;
  47. }
  48. }
  49.  
  50. if(isGameOver == true)
  51. {
  52.  
  53. if(locationX <= 220 && locationY >= 240)
  54. {
  55. reset();
  56. }
  57. else if (locationX >= 260 && locationY >= 240)
  58. {
  59. GameWrapper::gameOver();
  60. reset();
  61. }
  62. }
  63.  
  64. }
  65. }
  66. }

Report this snippet  

You need to login to post a comment.