// // Created by Иван Ильин on 14.03.2021. // #ifndef SHOOTER_PLAYER_H #define SHOOTER_PLAYER_H #include #include #include #include "Mesh.h" #include "Camera.h" #include "World.h" #include "weapon/Ak47.h" #include "weapon/Shotgun.h" #include "weapon/Gun.h" #include "weapon/Gold_Ak47.h" #include "weapon/Rifle.h" class Player : public Mesh{ private: double _healthMax = 100; double _health = _healthMax; double _abilityMax = 10; double _ability = _abilityMax; double jumpHeight = 3; double walkSpeed = 10; double _headAngle = 0; unsigned _kills = 0; unsigned _deaths = 0; double g = 35; double slowMoCoefficient = 5; bool isInSlowMo = false; std::shared_ptr _camera; std::shared_ptr _screen; std::shared_ptr _world; bool inRunning = false; // sounds sf::Sound killSound; sf::Sound deathSound; sf::Sound walkSound; sf::Sound changeWeaponSound; sf::Sound slowMoSound; sf::Sound unSlowMoSound; sf::Sound fullHealthSound; sf::Sound fullAbilitySound; std::string _name = "im"; std::vector> _weapons; uint8_t _selectedWeapon = 0; std::function damagePlayerCallBack; std::function addTraceCallBack; std::function takeBonusCallBack; public: Player() { loadObj("../obj/cube.obj", "", Point4D{0.5, 1.9, 0.5}); setAcceleration(Point4D{0, -g, 0}); setCollision(true); setVisible(false); setColor({240, 168, 168}); }; void update(); void attachCamera(std::shared_ptr camera, std::shared_ptr screen) { _camera = std::move(camera); _screen = std::move(screen); _camera->translateToPoint(position() + Point4D{0, 1.8, 0}); this->attach(_camera); } void attachWorld(std::shared_ptr world, const Point4D& pos = Point4D{0, 30, 0}) { _world = std::move(world); translate(pos); initWeapons(); changeWeaponSound.setBuffer(*ResourceManager::loadSoundBuffer("../sound/weapons/change_weapon.ogg")); slowMoSound.setBuffer(*ResourceManager::loadSoundBuffer("../sound/slow_mo.ogg")); unSlowMoSound.setBuffer(*ResourceManager::loadSoundBuffer("../sound/unslow_mo.ogg")); fullHealthSound.setBuffer(*ResourceManager::loadSoundBuffer("../sound/fullHealth.ogg")); fullAbilitySound.setBuffer(*ResourceManager::loadSoundBuffer("../sound/fullAbility.ogg")); setCollisionCallBack([this](const std::string& objName, std::shared_ptr obj) {collisionWithObject(objName, std::move(obj));}); } void setHealth(double h) { _health = h; } void setAbility(double a) { _ability = a; } void setFullHealth() { _health = _healthMax; fullHealthSound.play(); } void setFullAbility() { _ability = _abilityMax; fullAbilitySound.play(); } void setDamagePlayerCallBack(std::function hit) { damagePlayerCallBack = std::move(hit); } void setAddTraceCallBack(std::function add) { addTraceCallBack = std::move(add); } void setTakeBonusCallBack(std::function take) { takeBonusCallBack = std::move(take); } [[nodiscard]] double health() const { return _health; } [[nodiscard]] std::string name() const { return "Player_" + _name; } std::shared_ptr camera() { return _camera; } // This is for situation when you want to store the position of the head but you dont have attached camera void setHeadAngle(double a) { _headAngle = a; } [[nodiscard]] double headAngle() const { return _headAngle; }; void rotateWeaponsRelativePoint(const Point4D& point4D, const Point4D& v, double val); void drawStats(); void addKill() { _kills++; } void addDeath() { _deaths++; } void playDeath(); void playKill(); void collisionWithObject(const std::string& objName, std::shared_ptr obj); void addWeapon(std::shared_ptr weapon); void initWeapons(); }; #endif //MINECRAFT_3DZAVR_PLAYER_H