2021-09-13 15:53:43 +03:00
|
|
|
//
|
|
|
|
// Created by Иван Ильин on 14.03.2021.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef SHOOTER_PLAYER_H
|
|
|
|
#define SHOOTER_PLAYER_H
|
|
|
|
|
|
|
|
#include <SFML/Audio/Sound.hpp>
|
|
|
|
#include <utility>
|
2021-10-09 13:41:12 +03:00
|
|
|
#include "engine/ResourceManager.h"
|
|
|
|
#include "engine/Camera.h"
|
|
|
|
#include "engine/World.h"
|
2021-09-14 13:47:53 +03:00
|
|
|
#include "weapon/Ak47.h"
|
|
|
|
#include "weapon/Shotgun.h"
|
|
|
|
#include "weapon/Gun.h"
|
|
|
|
#include "weapon/Gold_Ak47.h"
|
|
|
|
#include "weapon/Rifle.h"
|
2021-10-16 20:22:55 +03:00
|
|
|
#include "ShooterConsts.h"
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-10-31 11:39:08 +03:00
|
|
|
class Player final : public RigidBody {
|
2021-09-13 15:53:43 +03:00
|
|
|
private:
|
2021-10-16 20:22:55 +03:00
|
|
|
double _health = ShooterConsts::HEALTH_MAX;
|
|
|
|
double _ability = ShooterConsts::ABILITY_MAX;
|
2021-09-13 15:53:43 +03:00
|
|
|
|
|
|
|
double _headAngle = 0;
|
|
|
|
|
2021-10-02 20:36:07 +03:00
|
|
|
int _kills = 0;
|
|
|
|
int _deaths = 0;
|
2021-09-13 15:53:43 +03:00
|
|
|
|
|
|
|
std::vector<std::shared_ptr<Weapon>> _weapons;
|
2021-10-09 13:41:12 +03:00
|
|
|
size_t _selectedWeapon = 0;
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-10-28 16:58:02 +03:00
|
|
|
std::string _nickName = ShooterConsts::PLAYER_NAME;
|
2021-10-26 09:40:35 +03:00
|
|
|
|
2021-09-19 11:25:10 +03:00
|
|
|
std::function<void(sf::Uint16 targetId, double)> _damagePlayerCallBack;
|
2021-10-31 11:39:08 +03:00
|
|
|
std::function<void(const Vec3D &, const Vec3D &)> _addTraceCallBack;
|
|
|
|
std::function<void(const std::string &)> _takeBonusCallBack;
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-10-02 20:36:07 +03:00
|
|
|
std::function<void(std::shared_ptr<Weapon>)> _addWeaponCallBack;
|
|
|
|
std::function<void(std::shared_ptr<Weapon>)> _removeWeaponCallBack;
|
|
|
|
|
2021-10-31 11:39:08 +03:00
|
|
|
std::function<IntersectionInformation(const Vec3D &, const Vec3D &)> _rayCastFunction;
|
2021-10-31 19:01:06 +03:00
|
|
|
|
|
|
|
void collisionWithObject(const ObjectNameTag &tag, std::shared_ptr<RigidBody> obj);
|
2022-07-07 13:14:00 +03:00
|
|
|
void rotateWeapon();
|
2021-09-13 15:53:43 +03:00
|
|
|
public:
|
2021-11-06 22:11:06 +03:00
|
|
|
explicit Player(ObjectNameTag name, const std::string &filename = ShooterConsts::CUBE_OBJ, const Vec3D &scale = Vec3D{1, 1, 1});
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-10-17 19:38:16 +03:00
|
|
|
void setHealth(double h) { _health = h; }
|
2021-10-31 11:39:08 +03:00
|
|
|
|
2021-10-17 19:38:16 +03:00
|
|
|
void setAbility(double a) { _ability = a; }
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-10-02 20:36:07 +03:00
|
|
|
[[nodiscard]] double health() const { return _health; }
|
2021-10-31 11:39:08 +03:00
|
|
|
|
2021-09-19 15:44:31 +03:00
|
|
|
[[nodiscard]] double ability() const { return _ability; }
|
|
|
|
|
2021-10-02 20:36:07 +03:00
|
|
|
|
2021-10-16 20:22:55 +03:00
|
|
|
void setFullHealth();
|
2021-10-31 11:39:08 +03:00
|
|
|
|
2021-10-16 20:22:55 +03:00
|
|
|
void setFullAbility();
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-10-31 19:01:06 +03:00
|
|
|
void reInitWeapons();
|
2021-10-31 11:39:08 +03:00
|
|
|
|
2021-10-02 20:36:07 +03:00
|
|
|
void addWeapon(std::shared_ptr<Weapon> weapon);
|
2021-10-31 11:39:08 +03:00
|
|
|
|
2021-10-31 19:01:06 +03:00
|
|
|
void selectNextWeapon();
|
2021-10-31 11:39:08 +03:00
|
|
|
|
2021-10-31 19:01:06 +03:00
|
|
|
void selectPreviousWeapon();
|
2021-10-31 11:39:08 +03:00
|
|
|
|
2021-10-22 19:42:32 +03:00
|
|
|
bool fire();
|
2021-10-31 11:39:08 +03:00
|
|
|
|
2021-10-02 20:36:07 +03:00
|
|
|
void reload();
|
2021-10-31 11:39:08 +03:00
|
|
|
|
2021-10-31 19:01:06 +03:00
|
|
|
[[nodiscard]] std::shared_ptr<Weapon> weapon() const { return _weapons[_selectedWeapon]; }
|
2021-10-02 20:36:07 +03:00
|
|
|
|
2021-10-31 11:39:08 +03:00
|
|
|
void rotateWeaponsRelativePoint(const Vec3D &point, const Vec3D &v, double val);
|
2021-10-02 20:36:07 +03:00
|
|
|
|
2021-10-17 19:38:16 +03:00
|
|
|
[[nodiscard]] int kills() const { return _kills; }
|
2021-10-31 11:39:08 +03:00
|
|
|
|
2021-10-17 19:38:16 +03:00
|
|
|
[[nodiscard]] int deaths() const { return _deaths; }
|
2021-10-02 20:36:07 +03:00
|
|
|
|
|
|
|
void addKill() { _kills++; }
|
2021-10-31 11:39:08 +03:00
|
|
|
|
2021-10-02 20:36:07 +03:00
|
|
|
void addDeath() { _deaths++; }
|
|
|
|
|
2021-10-26 10:08:41 +03:00
|
|
|
void setKills(int kills) { _kills = kills; }
|
2021-10-31 11:39:08 +03:00
|
|
|
|
2021-10-26 10:08:41 +03:00
|
|
|
void setDeaths(int deaths) { _deaths = deaths; }
|
|
|
|
|
2021-09-13 15:53:43 +03:00
|
|
|
void setDamagePlayerCallBack(std::function<void(sf::Uint16 targetId, double)> hit) {
|
2021-09-19 11:25:10 +03:00
|
|
|
_damagePlayerCallBack = std::move(hit);
|
2021-09-13 15:53:43 +03:00
|
|
|
}
|
2021-10-31 11:39:08 +03:00
|
|
|
|
|
|
|
void setAddTraceCallBack(std::function<void(const Vec3D &, const Vec3D &)> add) {
|
2021-09-19 11:25:10 +03:00
|
|
|
_addTraceCallBack = std::move(add);
|
2021-09-13 15:53:43 +03:00
|
|
|
}
|
2021-10-31 11:39:08 +03:00
|
|
|
|
|
|
|
void setTakeBonusCallBack(std::function<void(const std::string &)> take) {
|
2021-09-19 11:25:10 +03:00
|
|
|
_takeBonusCallBack = std::move(take);
|
2021-09-13 15:53:43 +03:00
|
|
|
}
|
2021-10-31 11:39:08 +03:00
|
|
|
|
2021-10-02 20:36:07 +03:00
|
|
|
void setAddWeaponCallBack(std::function<void(std::shared_ptr<Weapon>)> addWeapon) {
|
2021-10-16 20:22:55 +03:00
|
|
|
_addWeaponCallBack = std::move(addWeapon);
|
2021-10-02 20:36:07 +03:00
|
|
|
}
|
2021-10-31 11:39:08 +03:00
|
|
|
|
2021-10-02 20:36:07 +03:00
|
|
|
void setRemoveWeaponCallBack(std::function<void(std::shared_ptr<Weapon>)> removeWeapon) {
|
|
|
|
_removeWeaponCallBack = std::move(removeWeapon);
|
|
|
|
}
|
2021-10-31 11:39:08 +03:00
|
|
|
|
|
|
|
void setRayCastFunction(std::function<IntersectionInformation(const Vec3D &, const Vec3D &)> rayCastFunction) {
|
2021-10-02 20:36:07 +03:00
|
|
|
_rayCastFunction = std::move(rayCastFunction);
|
|
|
|
}
|
2021-09-13 15:53:43 +03:00
|
|
|
|
|
|
|
// 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; }
|
2021-10-31 11:39:08 +03:00
|
|
|
|
2021-09-13 15:53:43 +03:00
|
|
|
[[nodiscard]] double headAngle() const { return _headAngle; };
|
|
|
|
|
2021-10-28 16:58:02 +03:00
|
|
|
[[nodiscard]] std::string playerNickName() const { return _nickName; }
|
2021-10-31 11:39:08 +03:00
|
|
|
|
|
|
|
void setPlayerNickName(const std::string &name) { _nickName = name; }
|
2021-09-13 15:53:43 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif //MINECRAFT_3DZAVR_PLAYER_H
|