Player.hpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #pragma once
  2. #include <vector>
  3. #include <SFML/Graphics.hpp>
  4. #include <SFML/Audio.hpp>
  5. using namespace sf;
  6. class Map;
  7. class Bullet;
  8. class ActualPlayer;
  9. class AiPlayer;
  10. class PowerupManager;
  11. class Player: public ConvexShape
  12. {
  13. public:
  14. Player(Map* map);
  15. ~Player();
  16. void setColor(Color color);
  17. void logic(float delta);
  18. void spawnBullet(bool altFire);
  19. void drawBullets(RenderTarget& target) const;
  20. void hasten();
  21. void addNuke();
  22. int nukes() const;
  23. void growStronger();
  24. void rateOfFire();
  25. void kill(bool increaseScore);
  26. bool isDead() const;
  27. static ActualPlayer* actualPlayer;
  28. static std::vector<AiPlayer*>* aiPlayer;
  29. static unsigned totalScore;
  30. protected:
  31. Vector2f movementHelper(float delta, bool key1, bool key2, float& velocity, float angle, float speed, float damping);
  32. int _nukes;
  33. float _speed;
  34. int _strength;
  35. float _rateOfFire;
  36. Sound _laser;
  37. SoundBuffer _laserLaser;
  38. Sound _kill;
  39. SoundBuffer _killKill;
  40. Sound _powerup;
  41. SoundBuffer _powerupPowerup;
  42. private:
  43. Map* _map;
  44. Color _color;
  45. std::vector<Bullet*> _bullets;
  46. bool _dead;
  47. };
  48. class ActualPlayer: public Player
  49. {
  50. public:
  51. ActualPlayer(Map* map): Player(map) {_nukes = 1;};
  52. void input(float delta, Map* map, const Vector2f mouse);
  53. };
  54. class AiPlayer: public Player
  55. {
  56. public:
  57. AiPlayer(Map* map): Player(map), _velocity(0), _targetRotation(0), _targetRotationDeviation(0), _powerupManager(nullptr) {};
  58. void input(float delta, Map* map, ActualPlayer* player);
  59. void registerPowerups(PowerupManager* mgr);
  60. private:
  61. void updateAi(Map* map, ActualPlayer* player);
  62. Clock _clock;
  63. Clock _clock2;
  64. float _velocity;
  65. float _targetRotation;
  66. float _targetRotationDeviation;
  67. Vector2f _targetPos;
  68. PowerupManager* _powerupManager;
  69. };