Huge refactoring v3

master
Vectozavr 2021-10-29 22:19:30 +07:00
parent 875f9f85ec
commit 0913c45743
12 changed files with 12 additions and 14 deletions

View File

@ -115,7 +115,7 @@ void PlayerController::update() {
bool shot = _player->fire(); bool shot = _player->fire();
if(shot) { if(shot) {
if(!_player->inCollision() && (_player->weaponName() == ObjectNameTag("weapon_shotgun"))) { if(!_player->inCollision() && (_player->weaponName() == ObjectNameTag("shotgun"))) {
_player->addVelocity(-camera->lookAt() * 30 * coeff); _player->addVelocity(-camera->lookAt() * 30 * coeff);
} }
} }

View File

@ -306,10 +306,9 @@ void Shooter::changeEnemyWeapon(const std::string& weaponName, sf::Uint16 enemyI
auto head = world->body(ObjectNameTag("Enemy_" + std::to_string(enemyId) + "_head")); auto head = world->body(ObjectNameTag("Enemy_" + std::to_string(enemyId) + "_head"));
auto enemy = world->body(ObjectNameTag("Enemy_" + std::to_string(enemyId))); auto enemy = world->body(ObjectNameTag("Enemy_" + std::to_string(enemyId)));
// remove old weapon: // remove old weapon:
world->removeBody(weaponTag); world->removeBody(weaponTag);
enemy->unattach(ObjectNameTag("Weapon")); enemy->unattach(weaponTag);
world->loadBody(weaponTag, "obj/" + weaponName + ".obj"); world->loadBody(weaponTag, "obj/" + weaponName + ".obj");
world->body(weaponTag)->setCollider(false); world->body(weaponTag)->setCollider(false);

View File

@ -27,8 +27,7 @@ void UDPSocket::unbind() {
sf::Packet packet; sf::Packet packet;
packet << MsgType::Disconnect << _ownId; packet << MsgType::Disconnect << _ownId;
for (auto it = _connections.begin(); it != _connections.end();) for (auto it = _connections.begin(); it != _connections.end();) {
{
send(packet, it->first); send(packet, it->first);
_connections.erase(it++); _connections.erase(it++);
} }

View File

@ -8,5 +8,5 @@
using namespace std; using namespace std;
Ak47::Ak47(const std::string& weaponName) : Weapon(100, 30, 3.0, 0.1, 300, 2.0, ShooterConsts::AK47_FIRE_SOUND, ShooterConsts::AK47_RELOAD_SOUND, weaponName, ShooterConsts::AK47_OBJ, Vec3D{3, 3, 3}, Vec3D{-2.2, 1.0, 1.3}, Vec3D{0, Consts::PI, 0}) { 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}) {
} }

View File

@ -9,7 +9,7 @@
class Ak47 final : public Weapon { class Ak47 final : public Weapon {
public: public:
explicit Ak47(const std::string& weaponName = "ak47"); explicit Ak47();
}; };

View File

@ -10,7 +10,7 @@
class Gold_Ak47 final : public Weapon { class Gold_Ak47 final : public Weapon {
public: public:
explicit Gold_Ak47(const std::string& weaponName = "gold_ak47") : Weapon(200, 60, 1.5, 0.05, 600, 1.0, ShooterConsts::GOLD_AK47_FIRE_SOUND, ShooterConsts::GOLD_AK47_RELOAD_SOUND, weaponName, ShooterConsts::GOLD_AK47_OBJ, Vec3D{3, 3, 3}, Vec3D{-2.2, 1.0, 1.3}, Vec3D{0, Consts::PI, 0}) { explicit Gold_Ak47() : Weapon(200, 60, 1.5, 0.05, 600, 1.0, ShooterConsts::GOLD_AK47_FIRE_SOUND, ShooterConsts::GOLD_AK47_RELOAD_SOUND, ObjectNameTag("gold_ak47"), ShooterConsts::GOLD_AK47_OBJ, Vec3D{3, 3, 3}, Vec3D{-2.2, 1.0, 1.3}, Vec3D{0, Consts::PI, 0}) {
} }
}; };

View File

@ -8,5 +8,5 @@
using namespace std; using namespace std;
Gun::Gun() : Weapon(30, 6, 2.0, 0.3, 800, 3.0, ShooterConsts::GUN_FIRE_SOUND, ShooterConsts::GUN_RELOAD_SOUND, "gun", ShooterConsts::GUN_OBJ, Vec3D{3, 3, 3}, Vec3D{-1.8, 1.3, 1.8}, Vec3D{0, Consts::PI, 0}) { 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}) {
} }

View File

@ -6,5 +6,5 @@
#include "Rifle.h" #include "Rifle.h"
#include "../ShooterConsts.h" #include "../ShooterConsts.h"
Rifle::Rifle() : Weapon(5, 1, 1.0, 1.0, 30000, 0.5, ShooterConsts::RIFLE_FIRE_SOUND, ShooterConsts::RIFLE_RELOAD_SOUND, "rifle", ShooterConsts::RIFLE_OBJ, Vec3D{3, 3, 3}, Vec3D{-2.3, 1, 1.3}, Vec3D{0, Consts::PI, 0}) { 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}) {
} }

View File

@ -9,7 +9,7 @@
using namespace std; using namespace std;
Shotgun::Shotgun(const std::string& weaponName) : Weapon(15, 1, 1.0, 1.0, 400, 5.0, ShooterConsts::SHOTGUN_FIRE_SOUND, ShooterConsts::SHOTGUN_RELOAD_SOUND, weaponName, ShooterConsts::SHOTGUN_OBJ, Vec3D{3, 3, 3}, Vec3D{-1.95, 0.8, 1.5}, Vec3D{0, Consts::PI, 0}) { 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> std::map<ObjectNameTag, double>

View File

@ -9,7 +9,7 @@
class Shotgun final : public Weapon { class Shotgun final : public Weapon {
public: public:
explicit Shotgun(const std::string& weaponName = "shotgun"); explicit Shotgun();
std::map<ObjectNameTag, double> processFire(std::function<IntersectionInformation(const Vec3D&, const Vec3D&)> rayCastFunction, const Vec3D& position, const Vec3D& direction) override; std::map<ObjectNameTag, double> processFire(std::function<IntersectionInformation(const Vec3D&, const Vec3D&)> rayCastFunction, const Vec3D& position, const Vec3D& direction) override;
}; };

View File

@ -11,7 +11,7 @@
using namespace std; using namespace std;
Weapon::Weapon(int initialPack, int clipCapacity, double reloadTime, double fireDelay, double damage, double spreading, std::string fireSound, std::string reloadSound, const std::string& weaponName, const std::string& objFileName, const Vec3D& s, const Vec3D& t, const Vec3D& r) : RigidBody(ObjectNameTag("weapon_" + weaponName), weaponName), _initialPack(initialPack), _clipCapacity(clipCapacity), _reloadTime(reloadTime), _fireDelay(fireDelay), _damage(damage), _spreading(spreading), _fireSound(std::move(fireSound)), _reloadSound(std::move(reloadSound)) { Weapon::Weapon(int initialPack, int clipCapacity, double reloadTime, double fireDelay, double damage, double spreading, std::string fireSound, std::string reloadSound, ObjectNameTag weaponName, const std::string& objFileName, const Vec3D& s, const Vec3D& t, const Vec3D& r) : RigidBody(std::move(weaponName), objFileName), _initialPack(initialPack), _clipCapacity(clipCapacity), _reloadTime(reloadTime), _fireDelay(fireDelay), _damage(damage), _spreading(spreading), _fireSound(std::move(fireSound)), _reloadSound(std::move(reloadSound)) {
_stockAmmo = _initialPack - _clipCapacity; _stockAmmo = _initialPack - _clipCapacity;
_clipAmmo = _clipCapacity; _clipAmmo = _clipCapacity;

View File

@ -44,7 +44,7 @@ protected:
virtual std::map<ObjectNameTag, double> processFire(std::function<IntersectionInformation(const Vec3D&, const Vec3D&)> rayCastFunction, const Vec3D& position, const Vec3D& direction); virtual std::map<ObjectNameTag, double> processFire(std::function<IntersectionInformation(const Vec3D&, const Vec3D&)> rayCastFunction, const Vec3D& position, const Vec3D& direction);
public: public:
Weapon(int initialPack, int clipCapacity, double reloadTime, double fireDelay, double damage, double spreading, std::string fireSound, std::string reloadSound, const std::string& weaponName, const std::string& objFileName, const Vec3D& s, const Vec3D& t, const Vec3D& r); Weapon(int initialPack, int clipCapacity, double reloadTime, double fireDelay, double damage, double spreading, std::string fireSound, std::string reloadSound, ObjectNameTag weaponName, const std::string& objFileName, const Vec3D& s, const Vec3D& t, const Vec3D& r);
FireInformation fire(std::function<IntersectionInformation(const Vec3D&, const Vec3D&)> rayCastFunction, const Vec3D& position, const Vec3D& direction); FireInformation fire(std::function<IntersectionInformation(const Vec3D&, const Vec3D&)> rayCastFunction, const Vec3D& position, const Vec3D& direction);
void reload(); void reload();