Visual Studio refactoring
parent
9b9aac7fa4
commit
fe71ab92b0
|
@ -16,14 +16,10 @@ add_executable(shooter
|
||||||
ShooterServer.h
|
ShooterServer.h
|
||||||
weapon/Weapon.cpp
|
weapon/Weapon.cpp
|
||||||
weapon/Weapon.h
|
weapon/Weapon.h
|
||||||
weapon/Ak47.cpp
|
|
||||||
weapon/Ak47.h
|
weapon/Ak47.h
|
||||||
weapon/Shotgun.cpp
|
|
||||||
weapon/Shotgun.h
|
weapon/Shotgun.h
|
||||||
weapon/Gun.cpp
|
|
||||||
weapon/Gun.h
|
weapon/Gun.h
|
||||||
weapon/Gold_Ak47.h
|
weapon/Gold_Ak47.h
|
||||||
weapon/Rifle.cpp
|
|
||||||
weapon/Rifle.h
|
weapon/Rifle.h
|
||||||
PlayerController.cpp
|
PlayerController.cpp
|
||||||
PlayerController.h
|
PlayerController.h
|
||||||
|
|
26
Player.cpp
26
Player.cpp
|
@ -56,8 +56,10 @@ void Player::collisionWithObject(const ObjectNameTag &tag, std::shared_ptr<Rigid
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tag.str().find("Bonus") != std::string::npos) {
|
if (tag.str().find("Bonus") != std::string::npos) {
|
||||||
|
if (_takeBonusCallBack != nullptr) {
|
||||||
_takeBonusCallBack(tag.str());
|
_takeBonusCallBack(tag.str());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::addWeapon(std::shared_ptr<Weapon> weapon) {
|
void Player::addWeapon(std::shared_ptr<Weapon> weapon) {
|
||||||
|
@ -77,46 +79,62 @@ void Player::addWeapon(std::shared_ptr<Weapon> weapon) {
|
||||||
_weapons.back()->rotateRelativePoint(position() + Vec3D{0, 1.8, 0}, Vec3D{0, 1, 0}, angle().y());
|
_weapons.back()->rotateRelativePoint(position() + Vec3D{0, 1.8, 0}, Vec3D{0, 1, 0}, angle().y());
|
||||||
_weapons.back()->rotateRelativePoint(position() + Vec3D{0, 1.8, 0}, left(), headAngle());
|
_weapons.back()->rotateRelativePoint(position() + Vec3D{0, 1.8, 0}, left(), headAngle());
|
||||||
|
|
||||||
|
if (_addTraceCallBack != nullptr) {
|
||||||
_weapons.back()->setAddTraceCallBack(_addTraceCallBack);
|
_weapons.back()->setAddTraceCallBack(_addTraceCallBack);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::initWeapons() {
|
void Player::reInitWeapons() {
|
||||||
|
|
||||||
if (!_weapons.empty()) {
|
if (!_weapons.empty()) {
|
||||||
for (auto weapon : _weapons) {
|
for (auto weapon : _weapons) {
|
||||||
unattach(ObjectNameTag(weapon->name()));
|
unattach(ObjectNameTag(weapon->name()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_removeWeaponCallBack != nullptr) {
|
||||||
_removeWeaponCallBack(_weapons[_selectedWeapon]);
|
_removeWeaponCallBack(_weapons[_selectedWeapon]);
|
||||||
|
}
|
||||||
_weapons.clear();
|
_weapons.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
_selectedWeapon = 0;
|
_selectedWeapon = 0;
|
||||||
addWeapon(std::make_shared<Gun>());
|
addWeapon(std::make_shared<Gun>());
|
||||||
|
if (_addWeaponCallBack != nullptr) {
|
||||||
_addWeaponCallBack(_weapons[_selectedWeapon]);
|
_addWeaponCallBack(_weapons[_selectedWeapon]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::nextWeapon() {
|
void Player::selectNextWeapon() {
|
||||||
if (_weapons.size() > 1) {
|
if (_weapons.size() > 1) {
|
||||||
// change '_selectedWeapon'
|
// change '_selectedWeapon'
|
||||||
|
if (_removeWeaponCallBack != nullptr) {
|
||||||
_removeWeaponCallBack(_weapons[_selectedWeapon]);
|
_removeWeaponCallBack(_weapons[_selectedWeapon]);
|
||||||
|
}
|
||||||
|
|
||||||
_selectedWeapon = (_selectedWeapon + 1) % _weapons.size();
|
_selectedWeapon = (_selectedWeapon + 1) % _weapons.size();
|
||||||
|
|
||||||
|
if (_addWeaponCallBack != nullptr) {
|
||||||
_addWeaponCallBack(_weapons[_selectedWeapon]);
|
_addWeaponCallBack(_weapons[_selectedWeapon]);
|
||||||
|
}
|
||||||
Log::log("selectedWeapon " + std::to_string(_selectedWeapon));
|
Log::log("selectedWeapon " + std::to_string(_selectedWeapon));
|
||||||
SoundController::playSound(SoundTag("changeWeapon"), ShooterConsts::CHANGE_WEAPON_SOUND);
|
SoundController::playSound(SoundTag("changeWeapon"), ShooterConsts::CHANGE_WEAPON_SOUND);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::previousWeapon() {
|
void Player::selectPreviousWeapon() {
|
||||||
if (_weapons.size() > 1) {
|
if (_weapons.size() > 1) {
|
||||||
// change '_selectedWeapon'
|
// change '_selectedWeapon'
|
||||||
|
if (_removeWeaponCallBack != nullptr) {
|
||||||
_removeWeaponCallBack(_weapons[_selectedWeapon]);
|
_removeWeaponCallBack(_weapons[_selectedWeapon]);
|
||||||
|
}
|
||||||
if (_selectedWeapon > 0) {
|
if (_selectedWeapon > 0) {
|
||||||
_selectedWeapon = (_selectedWeapon - 1) % _weapons.size();
|
_selectedWeapon = (_selectedWeapon - 1) % _weapons.size();
|
||||||
} else {
|
} else {
|
||||||
_selectedWeapon = _weapons.size() - 1;
|
_selectedWeapon = _weapons.size() - 1;
|
||||||
}
|
}
|
||||||
|
if (_addWeaponCallBack != nullptr) {
|
||||||
_addWeaponCallBack(_weapons[_selectedWeapon]);
|
_addWeaponCallBack(_weapons[_selectedWeapon]);
|
||||||
|
}
|
||||||
Log::log("selectedWeapon " + std::to_string(_selectedWeapon));
|
Log::log("selectedWeapon " + std::to_string(_selectedWeapon));
|
||||||
SoundController::playSound(SoundTag("changeWeapon"), ShooterConsts::CHANGE_WEAPON_SOUND);
|
SoundController::playSound(SoundTag("changeWeapon"), ShooterConsts::CHANGE_WEAPON_SOUND);
|
||||||
}
|
}
|
||||||
|
@ -128,8 +146,10 @@ bool Player::fire() {
|
||||||
auto fireInfo = _weapons[_selectedWeapon]->fire(_rayCastFunction, camera->position(), camera->lookAt());
|
auto fireInfo = _weapons[_selectedWeapon]->fire(_rayCastFunction, camera->position(), camera->lookAt());
|
||||||
for (auto&[damagedPlayerName, damage] : fireInfo.damagedPlayers) {
|
for (auto&[damagedPlayerName, damage] : fireInfo.damagedPlayers) {
|
||||||
sf::Uint16 targetId = std::stoi(damagedPlayerName.str().substr(6));
|
sf::Uint16 targetId = std::stoi(damagedPlayerName.str().substr(6));
|
||||||
|
if (_damagePlayerCallBack != nullptr) {
|
||||||
_damagePlayerCallBack(targetId, damage);
|
_damagePlayerCallBack(targetId, damage);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return fireInfo.shot;
|
return fireInfo.shot;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
16
Player.h
16
Player.h
|
@ -40,6 +40,8 @@ private:
|
||||||
std::function<void(std::shared_ptr<Weapon>)> _removeWeaponCallBack;
|
std::function<void(std::shared_ptr<Weapon>)> _removeWeaponCallBack;
|
||||||
|
|
||||||
std::function<IntersectionInformation(const Vec3D &, const Vec3D &)> _rayCastFunction;
|
std::function<IntersectionInformation(const Vec3D &, const Vec3D &)> _rayCastFunction;
|
||||||
|
|
||||||
|
void collisionWithObject(const ObjectNameTag &tag, std::shared_ptr<RigidBody> obj);
|
||||||
public:
|
public:
|
||||||
explicit Player(ObjectNameTag name);
|
explicit Player(ObjectNameTag name);
|
||||||
|
|
||||||
|
@ -56,23 +58,19 @@ public:
|
||||||
|
|
||||||
void setFullAbility();
|
void setFullAbility();
|
||||||
|
|
||||||
void initWeapons();
|
void reInitWeapons();
|
||||||
|
|
||||||
void addWeapon(std::shared_ptr<Weapon> weapon);
|
void addWeapon(std::shared_ptr<Weapon> weapon);
|
||||||
|
|
||||||
[[nodiscard]] std::pair<double, double> balance() const { return _weapons[_selectedWeapon]->balance(); }
|
void selectNextWeapon();
|
||||||
|
|
||||||
void nextWeapon();
|
void selectPreviousWeapon();
|
||||||
|
|
||||||
void previousWeapon();
|
|
||||||
|
|
||||||
bool fire();
|
bool fire();
|
||||||
|
|
||||||
void reload();
|
void reload();
|
||||||
|
|
||||||
[[nodiscard]] ObjectNameTag weaponName() const { return _weapons[_selectedWeapon]->name(); }
|
[[nodiscard]] std::shared_ptr<Weapon> weapon() const { return _weapons[_selectedWeapon]; }
|
||||||
|
|
||||||
std::shared_ptr<Weapon> weapon() { return _weapons[_selectedWeapon]; }
|
|
||||||
|
|
||||||
void rotateWeaponsRelativePoint(const Vec3D &point, const Vec3D &v, double val);
|
void rotateWeaponsRelativePoint(const Vec3D &point, const Vec3D &v, double val);
|
||||||
|
|
||||||
|
@ -117,8 +115,6 @@ public:
|
||||||
|
|
||||||
[[nodiscard]] double headAngle() const { return _headAngle; };
|
[[nodiscard]] double headAngle() const { return _headAngle; };
|
||||||
|
|
||||||
void collisionWithObject(const ObjectNameTag &tag, std::shared_ptr<RigidBody> obj);
|
|
||||||
|
|
||||||
[[nodiscard]] std::string playerNickName() const { return _nickName; }
|
[[nodiscard]] std::string playerNickName() const { return _nickName; }
|
||||||
|
|
||||||
void setPlayerNickName(const std::string &name) { _nickName = name; }
|
void setPlayerNickName(const std::string &name) { _nickName = name; }
|
||||||
|
|
|
@ -137,7 +137,7 @@ void PlayerController::update() {
|
||||||
bool shot = _player->fire();
|
bool shot = _player->fire();
|
||||||
|
|
||||||
if (shot) {
|
if (shot) {
|
||||||
if (_player->weaponName() == ObjectNameTag("shotgun")) {
|
if (_player->weapon()->name() == ObjectNameTag("shotgun")) {
|
||||||
_player->addVelocity(-camera->lookAt() * 30 * coeff);
|
_player->addVelocity(-camera->lookAt() * 30 * coeff);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -186,11 +186,11 @@ void PlayerController::update() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_keyboard->isKeyTapped(sf::Keyboard::Right) || _keyboard->isKeyTapped(sf::Keyboard::E)) {
|
if (_keyboard->isKeyTapped(sf::Keyboard::Right) || _keyboard->isKeyTapped(sf::Keyboard::E)) {
|
||||||
_player->nextWeapon();
|
_player->selectNextWeapon();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_keyboard->isKeyTapped(sf::Keyboard::Left) || _keyboard->isKeyTapped(sf::Keyboard::Q)) {
|
if (_keyboard->isKeyTapped(sf::Keyboard::Left) || _keyboard->isKeyTapped(sf::Keyboard::Q)) {
|
||||||
_player->previousWeapon();
|
_player->selectPreviousWeapon();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Keyboard::isKeyPressed(sf::Keyboard::R)) {
|
if (Keyboard::isKeyPressed(sf::Keyboard::R)) {
|
||||||
|
|
|
@ -92,7 +92,7 @@ void Shooter::start() {
|
||||||
player->setAddWeaponCallBack([this](std::shared_ptr<Weapon> weapon) { addWeapon(std::move(weapon)); });
|
player->setAddWeaponCallBack([this](std::shared_ptr<Weapon> weapon) { addWeapon(std::move(weapon)); });
|
||||||
player->setRemoveWeaponCallBack([this](std::shared_ptr<Weapon> weapon) { removeWeapon(std::move(weapon)); });
|
player->setRemoveWeaponCallBack([this](std::shared_ptr<Weapon> weapon) { removeWeapon(std::move(weapon)); });
|
||||||
|
|
||||||
player->initWeapons();
|
player->reInitWeapons();
|
||||||
|
|
||||||
player->translate(Vec3D{0, 0, 0});
|
player->translate(Vec3D{0, 0, 0});
|
||||||
camera->translateToPoint(player->position() + Vec3D{0, 1.8, 0});
|
camera->translateToPoint(player->position() + Vec3D{0, 1.8, 0});
|
||||||
|
@ -156,7 +156,6 @@ void Shooter::update() {
|
||||||
if (inGame) {
|
if (inGame) {
|
||||||
screen->setTitle(ShooterConsts::PROJECT_NAME);
|
screen->setTitle(ShooterConsts::PROJECT_NAME);
|
||||||
playerController->update();
|
playerController->update();
|
||||||
mouse->setMouseInCenter();
|
|
||||||
} else {
|
} else {
|
||||||
mainMenu.update();
|
mainMenu.update();
|
||||||
}
|
}
|
||||||
|
@ -229,7 +228,7 @@ void Shooter::drawPlayerStats() {
|
||||||
Vec2D{xPos, yPos - 15 + height},
|
Vec2D{xPos, yPos - 15 + height},
|
||||||
{255, 168, 168, 100});
|
{255, 168, 168, 100});
|
||||||
|
|
||||||
auto balance = player->balance();
|
auto balance = player->weapon()->balance();
|
||||||
|
|
||||||
screen->drawText(std::to_string((int) balance.first), Vec2D{150, static_cast<double>(screen->height() - 150)}, 100,
|
screen->drawText(std::to_string((int) balance.first), Vec2D{150, static_cast<double>(screen->height() - 150)}, 100,
|
||||||
sf::Color(0, 0, 0, 100));
|
sf::Color(0, 0, 0, 100));
|
||||||
|
|
|
@ -113,7 +113,7 @@ void ShooterClient::processCustomPacket(sf::Packet &packet) {
|
||||||
_player->translateToPoint(
|
_player->translateToPoint(
|
||||||
Vec3D{50.0 * (-1 + 2.0 * (double) rand() / RAND_MAX), 30.0 * (double) rand() / RAND_MAX,
|
Vec3D{50.0 * (-1 + 2.0 * (double) rand() / RAND_MAX), 30.0 * (double) rand() / RAND_MAX,
|
||||||
50.0 * (-1 + 2.0 * (double) rand() / RAND_MAX)});
|
50.0 * (-1 + 2.0 * (double) rand() / RAND_MAX)});
|
||||||
_player->initWeapons();
|
_player->reInitWeapons();
|
||||||
_player->setFullAbility();
|
_player->setFullAbility();
|
||||||
SoundController::playSound(SoundTag("death"), ShooterConsts::DEATH_SOUND);
|
SoundController::playSound(SoundTag("death"), ShooterConsts::DEATH_SOUND);
|
||||||
_lastEvent += _player->playerNickName();
|
_lastEvent += _player->playerNickName();
|
||||||
|
|
|
@ -28,7 +28,6 @@ void Engine::create(int screenWidth, int screenHeight, const std::string &name,
|
||||||
|
|
||||||
start();
|
start();
|
||||||
camera->init(screenWidth, screenHeight);
|
camera->init(screenWidth, screenHeight);
|
||||||
mouse->setMouseInCenter();
|
|
||||||
|
|
||||||
while (screen->isOpen()) {
|
while (screen->isOpen()) {
|
||||||
screen->clear();
|
screen->clear();
|
||||||
|
|
|
@ -36,8 +36,6 @@ public:
|
||||||
|
|
||||||
[[nodiscard]] std::vector<Triangle> const &triangles() const { return _tris; }
|
[[nodiscard]] std::vector<Triangle> const &triangles() const { return _tris; }
|
||||||
|
|
||||||
[[nodiscard]] std::vector<Triangle> &triangles() { return _tris; }
|
|
||||||
|
|
||||||
void setTriangles(const std::vector<Triangle> &t);
|
void setTriangles(const std::vector<Triangle> &t);
|
||||||
|
|
||||||
[[nodiscard]] size_t size() const { return _tris.size() * 3; }
|
[[nodiscard]] size_t size() const { return _tris.size() * 3; }
|
||||||
|
|
|
@ -12,11 +12,11 @@ Vec2D Mouse::getMousePosition() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
Vec2D Mouse::getMouseDisplacement() const {
|
Vec2D Mouse::getMouseDisplacement() const {
|
||||||
// TODO: getMouseDisplacement() should return displacement from the previous position but not from the center
|
|
||||||
sf::Vector2<int> mousePos = sf::Mouse::getPosition(*_screen->renderWindow());
|
sf::Vector2<int> mousePos = sf::Mouse::getPosition(*_screen->renderWindow());
|
||||||
sf::Vector2<int> center = sf::Vector2<int>(_screen->width() / 2, _screen->height() / 2);
|
sf::Vector2<int> center = sf::Vector2<int>(_screen->width() / 2, _screen->height() / 2);
|
||||||
|
|
||||||
sf::Vector2<int> displacement = mousePos - center;
|
sf::Vector2<int> displacement = mousePos - center;
|
||||||
|
setMouseInCenter();
|
||||||
return Vec2D(displacement.x, displacement.y);
|
return Vec2D(displacement.x, displacement.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ private:
|
||||||
const std::shared_ptr<Screen> _screen;
|
const std::shared_ptr<Screen> _screen;
|
||||||
|
|
||||||
std::map<sf::Mouse::Button, double> _tappedButtons;
|
std::map<sf::Mouse::Button, double> _tappedButtons;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit Mouse(std::shared_ptr<Screen> screen) : _screen(std::move(screen)) {};
|
explicit Mouse(std::shared_ptr<Screen> screen) : _screen(std::move(screen)) {};
|
||||||
|
|
||||||
|
|
|
@ -15,15 +15,13 @@
|
||||||
void Screen::open(int screenWidth, int screenHeight, const std::string &name, bool verticalSync, sf::Color background,
|
void Screen::open(int screenWidth, int screenHeight, const std::string &name, bool verticalSync, sf::Color background,
|
||||||
sf::Uint32 style) {
|
sf::Uint32 style) {
|
||||||
_title = name;
|
_title = name;
|
||||||
_w = screenWidth;
|
|
||||||
_h = screenHeight;
|
|
||||||
_background = background;
|
_background = background;
|
||||||
|
|
||||||
sf::ContextSettings settings;
|
sf::ContextSettings settings;
|
||||||
settings.depthBits = 24;
|
settings.depthBits = 24;
|
||||||
settings.antialiasingLevel = 8;
|
settings.antialiasingLevel = 8;
|
||||||
|
|
||||||
_window->create(sf::VideoMode(_w, _h), name, style, settings);
|
_window->create(sf::VideoMode(screenWidth, screenHeight), name, style, settings);
|
||||||
_window->setVerticalSyncEnabled(verticalSync);
|
_window->setVerticalSyncEnabled(verticalSync);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,7 +177,7 @@ void Screen::glDrawMesh(GLfloat *geometry, GLfloat *view, GLfloat *model, size_t
|
||||||
}
|
}
|
||||||
|
|
||||||
GLfloat *Screen::glMeshToGLfloatArray(std::shared_ptr<Mesh> mesh, const Vec3D &cameraPosition) {
|
GLfloat *Screen::glMeshToGLfloatArray(std::shared_ptr<Mesh> mesh, const Vec3D &cameraPosition) {
|
||||||
std::vector<Triangle> &triangles = mesh->triangles();
|
std::vector<Triangle> const &triangles = mesh->triangles();
|
||||||
|
|
||||||
auto *geometry = (GLfloat *) malloc(7 * 3 * triangles.size() * sizeof(GLfloat));
|
auto *geometry = (GLfloat *) malloc(7 * 3 * triangles.size() * sizeof(GLfloat));
|
||||||
|
|
||||||
|
|
|
@ -19,9 +19,6 @@
|
||||||
|
|
||||||
class Screen final {
|
class Screen final {
|
||||||
private:
|
private:
|
||||||
int _w{};
|
|
||||||
int _h{};
|
|
||||||
|
|
||||||
std::string _title;
|
std::string _title;
|
||||||
|
|
||||||
sf::Color _background;
|
sf::Color _background;
|
||||||
|
|
|
@ -23,6 +23,7 @@ void Window::update() {
|
||||||
|
|
||||||
Vec2D mousePos = _mouse->getMousePosition();
|
Vec2D mousePos = _mouse->getMousePosition();
|
||||||
Vec2D dMousePos = mousePos - _prevMousePosition;
|
Vec2D dMousePos = mousePos - _prevMousePosition;
|
||||||
|
_prevMousePosition = mousePos;
|
||||||
_back.setPosition(_back.getPosition() - sf::Vector2f(static_cast<float>(dMousePos.x()) / 30.0f,
|
_back.setPosition(_back.getPosition() - sf::Vector2f(static_cast<float>(dMousePos.x()) / 30.0f,
|
||||||
static_cast<float>(dMousePos.y()) / 30.0f));
|
static_cast<float>(dMousePos.y()) / 30.0f));
|
||||||
bool isPressed = _mouse->isButtonTapped(sf::Mouse::Left);
|
bool isPressed = _mouse->isButtonTapped(sf::Mouse::Left);
|
||||||
|
@ -44,8 +45,6 @@ void Window::update() {
|
||||||
_screen->drawText(button.text());
|
_screen->drawText(button.text());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_prevMousePosition = mousePos;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::setBackgroundTexture(const std::string &texture, double sx, double sy, int w, int h) {
|
void Window::setBackgroundTexture(const std::string &texture, double sx, double sy, int w, int h) {
|
||||||
|
|
|
@ -32,6 +32,15 @@ struct NextSimplex final {
|
||||||
|
|
||||||
class RigidBody : public Mesh {
|
class RigidBody : public Mesh {
|
||||||
private:
|
private:
|
||||||
|
Vec3D _velocity{0, 0, 0};
|
||||||
|
Vec3D _acceleration{0, 0, 0};
|
||||||
|
|
||||||
|
bool _collision = false;
|
||||||
|
bool _isCollider = true;
|
||||||
|
|
||||||
|
bool _inCollision = false;
|
||||||
|
Vec3D _collisionNormal{0, 0, 0};
|
||||||
|
|
||||||
Vec3D _findFurthestPoint(const Vec3D &direction);
|
Vec3D _findFurthestPoint(const Vec3D &direction);
|
||||||
|
|
||||||
Vec3D _support(std::shared_ptr<RigidBody> obj, const Vec3D &direction);
|
Vec3D _support(std::shared_ptr<RigidBody> obj, const Vec3D &direction);
|
||||||
|
@ -52,17 +61,6 @@ private:
|
||||||
static std::vector<std::pair<size_t, size_t>>
|
static std::vector<std::pair<size_t, size_t>>
|
||||||
_addIfUniqueEdge(const std::vector<std::pair<size_t, size_t>> &edges, const std::vector<size_t> &faces, size_t a,
|
_addIfUniqueEdge(const std::vector<std::pair<size_t, size_t>> &edges, const std::vector<size_t> &faces, size_t a,
|
||||||
size_t b);
|
size_t b);
|
||||||
|
|
||||||
protected:
|
|
||||||
Vec3D _velocity{0, 0, 0};
|
|
||||||
Vec3D _acceleration{0, 0, 0};
|
|
||||||
|
|
||||||
bool _collision = false;
|
|
||||||
bool _isCollider = true;
|
|
||||||
|
|
||||||
bool _inCollision = false;
|
|
||||||
Vec3D _collisionNormal{0, 0, 0};
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit RigidBody(ObjectNameTag nameTag) : Mesh(std::move(nameTag)) {};
|
explicit RigidBody(ObjectNameTag nameTag) : Mesh(std::move(nameTag)) {};
|
||||||
|
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
//
|
|
||||||
// Created by Иван Ильин on 02.06.2021.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "../engine/ResourceManager.h"
|
|
||||||
#include "Ak47.h"
|
|
||||||
#include "../ShooterConsts.h"
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
Ak47::Ak47() : Weapon(100, 30, 3.0, 0.1, 300, 2.0,
|
|
||||||
ShooterConsts::AK47_FIRE_SOUND, ShooterConsts::AK47_RELOAD_SOUND,
|
|
||||||
ObjectNameTag("ak47"), ShooterConsts::AK47_OBJ,
|
|
||||||
Vec3D{3, 3, 3}, Vec3D{-2.2, 1.0, 1.3},Vec3D{0, Consts::PI, 0}) {
|
|
||||||
}
|
|
|
@ -6,10 +6,15 @@
|
||||||
#define SHOOTER_AK47_H
|
#define SHOOTER_AK47_H
|
||||||
|
|
||||||
#include "Weapon.h"
|
#include "Weapon.h"
|
||||||
|
#include "../engine/ResourceManager.h"
|
||||||
|
#include "../ShooterConsts.h"
|
||||||
|
|
||||||
class Ak47 final : public Weapon {
|
class Ak47 final : public Weapon {
|
||||||
public:
|
public:
|
||||||
explicit Ak47();
|
explicit Ak47() : Weapon(100, 30, 3.0, 0.1, 300, 2.0,
|
||||||
|
ShooterConsts::AK47_FIRE_SOUND, ShooterConsts::AK47_RELOAD_SOUND,
|
||||||
|
ObjectNameTag("ak47"), ShooterConsts::AK47_OBJ,
|
||||||
|
Vec3D{3, 3, 3}, Vec3D{-2.2, 1.0, 1.3},Vec3D{0, Consts::PI, 0}) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
//
|
|
||||||
// Created by Иван Ильин on 03.06.2021.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "../engine/ResourceManager.h"
|
|
||||||
#include "Gun.h"
|
|
||||||
#include "../ShooterConsts.h"
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
Gun::Gun() : Weapon(30, 6, 2.0, 0.3, 800, 3.0,
|
|
||||||
ShooterConsts::GUN_FIRE_SOUND, ShooterConsts::GUN_RELOAD_SOUND, ObjectNameTag("gun"),
|
|
||||||
ShooterConsts::GUN_OBJ, Vec3D{3, 3, 3},
|
|
||||||
Vec3D{-1.8, 1.3, 1.8}, Vec3D{0, Consts::PI, 0}) {
|
|
||||||
}
|
|
|
@ -6,10 +6,15 @@
|
||||||
#define SHOOTER_GUN_H
|
#define SHOOTER_GUN_H
|
||||||
|
|
||||||
#include "Weapon.h"
|
#include "Weapon.h"
|
||||||
|
#include "../engine/ResourceManager.h"
|
||||||
|
#include "../ShooterConsts.h"
|
||||||
|
|
||||||
class Gun final : public Weapon {
|
class Gun final : public Weapon {
|
||||||
public:
|
public:
|
||||||
explicit Gun();
|
explicit Gun() : Weapon(30, 6, 2.0, 0.3, 800, 3.0,
|
||||||
|
ShooterConsts::GUN_FIRE_SOUND, ShooterConsts::GUN_RELOAD_SOUND, ObjectNameTag("gun"),
|
||||||
|
ShooterConsts::GUN_OBJ, Vec3D{3, 3, 3},
|
||||||
|
Vec3D{-1.8, 1.3, 1.8}, Vec3D{0, Consts::PI, 0}) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
//
|
|
||||||
// Created by Иван Ильин on 06.06.2021.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "../engine/ResourceManager.h"
|
|
||||||
#include "Rifle.h"
|
|
||||||
#include "../ShooterConsts.h"
|
|
||||||
|
|
||||||
Rifle::Rifle() : Weapon(5, 1, 1.0, 1.0, 30000, 0.5,
|
|
||||||
ShooterConsts::RIFLE_FIRE_SOUND, ShooterConsts::RIFLE_RELOAD_SOUND,
|
|
||||||
ObjectNameTag("rifle"), ShooterConsts::RIFLE_OBJ, Vec3D{3, 3, 3},
|
|
||||||
Vec3D{-2.3, 1, 1.3},Vec3D{0, Consts::PI, 0}) {
|
|
||||||
}
|
|
|
@ -6,10 +6,15 @@
|
||||||
#define SHOOTER_RIFLE_H
|
#define SHOOTER_RIFLE_H
|
||||||
|
|
||||||
#include "Weapon.h"
|
#include "Weapon.h"
|
||||||
|
#include "../engine/ResourceManager.h"
|
||||||
|
#include "../ShooterConsts.h"
|
||||||
|
|
||||||
class Rifle final : public Weapon {
|
class Rifle final : public Weapon {
|
||||||
public:
|
public:
|
||||||
explicit Rifle();
|
explicit Rifle() : Weapon(5, 1, 1.0, 1.0, 30000, 0.5,
|
||||||
|
ShooterConsts::RIFLE_FIRE_SOUND, ShooterConsts::RIFLE_RELOAD_SOUND,
|
||||||
|
ObjectNameTag("rifle"), ShooterConsts::RIFLE_OBJ, Vec3D{3, 3, 3},
|
||||||
|
Vec3D{-2.3, 1, 1.3},Vec3D{0, Consts::PI, 0}) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
//
|
|
||||||
// Created by Иван Ильин on 02.06.2021.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "../engine/ResourceManager.h"
|
|
||||||
#include "Shotgun.h"
|
|
||||||
#include "../ShooterConsts.h"
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
Shotgun::Shotgun() : Weapon(15, 1, 1.0, 1.0, 400, 5.0, ShooterConsts::SHOTGUN_FIRE_SOUND,
|
|
||||||
ShooterConsts::SHOTGUN_RELOAD_SOUND, ObjectNameTag("shotgun"), ShooterConsts::SHOTGUN_OBJ,
|
|
||||||
Vec3D{3, 3, 3}, Vec3D{-1.95, 0.8, 1.5}, Vec3D{0, Consts::PI, 0}) {
|
|
||||||
}
|
|
||||||
|
|
||||||
std::map<ObjectNameTag, double>
|
|
||||||
Shotgun::processFire(std::function<IntersectionInformation(const Vec3D &, const Vec3D &)> rayCastFunction,
|
|
||||||
const Vec3D &position, const Vec3D &direction) {
|
|
||||||
std::map<ObjectNameTag, double> damagedPlayers;
|
|
||||||
|
|
||||||
for (int i = 0; i < 15; i++) {
|
|
||||||
std::map<ObjectNameTag, double> damaged = addTrace(rayCastFunction, position, direction);
|
|
||||||
for (auto &player : damaged) {
|
|
||||||
damagedPlayers[player.first] += player.second;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return damagedPlayers;
|
|
||||||
}
|
|
|
@ -6,14 +6,30 @@
|
||||||
#define SHOOTER_SHOTGUN_H
|
#define SHOOTER_SHOTGUN_H
|
||||||
|
|
||||||
#include "Weapon.h"
|
#include "Weapon.h"
|
||||||
|
#include "../engine/ResourceManager.h"
|
||||||
|
#include "../ShooterConsts.h"
|
||||||
|
|
||||||
class Shotgun final : public Weapon {
|
class Shotgun final : public Weapon {
|
||||||
public:
|
public:
|
||||||
explicit Shotgun();
|
explicit Shotgun(): Weapon(15, 1, 1.0, 1.0, 400, 5.0, ShooterConsts::SHOTGUN_FIRE_SOUND,
|
||||||
|
ShooterConsts::SHOTGUN_RELOAD_SOUND, ObjectNameTag("shotgun"), ShooterConsts::SHOTGUN_OBJ,
|
||||||
|
Vec3D{3, 3, 3}, Vec3D{-1.95, 0.8, 1.5}, Vec3D{0, Consts::PI, 0}) {}
|
||||||
|
|
||||||
std::map<ObjectNameTag, double>
|
std::map<ObjectNameTag, double>
|
||||||
processFire(std::function<IntersectionInformation(const Vec3D &, const Vec3D &)> rayCastFunction,
|
processFire(std::function<IntersectionInformation(const Vec3D &, const Vec3D &)> rayCastFunction,
|
||||||
const Vec3D &position, const Vec3D &direction) override;
|
const Vec3D &position, const Vec3D &direction) override {
|
||||||
|
|
||||||
|
std::map<ObjectNameTag, double> damagedPlayers;
|
||||||
|
|
||||||
|
for (int i = 0; i < 15; i++) {
|
||||||
|
std::map<ObjectNameTag, double> damaged = addTrace(rayCastFunction, position, direction);
|
||||||
|
for (auto &player : damaged) {
|
||||||
|
damagedPlayers[player.first] += player.second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return damagedPlayers;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue