Player.hpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /**
  2. * one room arena
  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 <vector>
  19. #include <SFML/Graphics.hpp>
  20. #include <SFML/Audio.hpp>
  21. using namespace sf;
  22. class Map;
  23. class Bullet;
  24. class ActualPlayer;
  25. class AiPlayer;
  26. class PowerupManager;
  27. class Player: public ConvexShape
  28. {
  29. public:
  30. Player(Map* map);
  31. ~Player();
  32. void setColor(Color color);
  33. void logic(float delta);
  34. void spawnBullet(bool altFire);
  35. void drawBullets(RenderTarget& target) const;
  36. void hasten();
  37. void addNuke();
  38. int nukes() const;
  39. void growStronger();
  40. void rateOfFire();
  41. void kill(bool increaseScore);
  42. bool isDead() const;
  43. static ActualPlayer* actualPlayer;
  44. static std::vector<AiPlayer*>* aiPlayer;
  45. static unsigned totalScore;
  46. protected:
  47. Vector2f movementHelper(float delta, bool key1, bool key2, float& velocity, float angle, float speed, float damping);
  48. int _nukes;
  49. float _speed;
  50. int _strength;
  51. float _rateOfFire;
  52. Sound _laser;
  53. SoundBuffer _laserLaser;
  54. Sound _kill;
  55. SoundBuffer _killKill;
  56. Sound _powerup;
  57. SoundBuffer _powerupPowerup;
  58. private:
  59. Map* _map;
  60. Color _color;
  61. std::vector<Bullet*> _bullets;
  62. bool _dead;
  63. };
  64. class ActualPlayer: public Player
  65. {
  66. public:
  67. ActualPlayer(Map* map): Player(map) {_nukes = 1;};
  68. void input(float delta, Map* map, const Vector2f mouse);
  69. };
  70. class AiPlayer: public Player
  71. {
  72. public:
  73. AiPlayer(Map* map): Player(map), _velocity(0), _targetRotation(0), _targetRotationDeviation(0), _powerupManager(nullptr) {};
  74. void input(float delta, Map* map, ActualPlayer* player);
  75. void registerPowerups(PowerupManager* mgr);
  76. private:
  77. void updateAi(Map* map, ActualPlayer* player);
  78. Clock _clock;
  79. Clock _clock2;
  80. float _velocity;
  81. float _targetRotation;
  82. float _targetRotationDeviation;
  83. Vector2f _targetPos;
  84. PowerupManager* _powerupManager;
  85. };