Player.hpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /**
  2. * Triangles
  3. * Copyright (C) 2016 POSITIVE MENTAL ATTITUDE
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, version 3 of the License.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #pragma once
  18. #include <SFML/Audio.hpp>
  19. #include "Triangle.hpp"
  20. #include "InputTarget.hpp"
  21. #include "Utility.hpp"
  22. #include "Bullet.hpp"
  23. #include "Collidable.hpp"
  24. #include "Context.hpp"
  25. #include "Particle.hpp"
  26. /**
  27. * @class Player
  28. * @author POSITIVE MENTAL ATTITUDE
  29. * @date 06/09/16
  30. * @file Player.hpp
  31. * @brief TODO Player class is in fact a class for everything related to a moving triangles.
  32. * This has to be moved to an Entity class or something
  33. * and leave the camera and input stuff to the Player class.
  34. */
  35. class Player: public Triangle, public InputTarget<int>, public Collidable
  36. {
  37. public:
  38. Player();
  39. void update(sf::Time delta);
  40. void setTexture(sf::Texture& texture) override;
  41. /**
  42. * @brief
  43. * @param foreground
  44. * @return Returns true if the target died.
  45. */
  46. bool checkCollision(Foreground& foreground);
  47. bool isDead();
  48. Rect getBounds();
  49. sf::Image _image;
  50. sf::Texture _innerTexture;
  51. void setContext(Context* context);
  52. private:
  53. void keyboardControls(sf::Time delta);
  54. void padControls(sf::Time delta);
  55. Context* _context;
  56. std::vector<Bullet> _bullets;
  57. sf::Clock _bulletTimer;
  58. InputMap<int> _inputMap;
  59. float _movement, _movementSpeed, _movementMomentum, _movementAcceleration, _movementSuppresion;
  60. float _rotation, _rotationSpeed, _rotationMomentum, _rotationAcceleration, _rotationSuppresion;
  61. bool _canStrafe;
  62. float _strafe;
  63. bool _hit;
  64. bool _dead;
  65. virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const final override;
  66. sf::Sound _glass;
  67. sf::Sound _deathSound;
  68. ParticleSystem _particleSystem;
  69. };