almoos dere

This commit is contained in:
MarcEricMartel
2023-12-18 13:29:38 -05:00
parent 68d03c1eac
commit f1bb7447f9
14 changed files with 125 additions and 68 deletions

View File

@@ -4,12 +4,7 @@ Booster::Booster()
{
}
Booster::Booster(Vector3f tpos, BOOST_TYPE ttype)
{
pos = tpos;
type = ttype;
available = true;
}
Booster::Booster(Vector3f tpos, BOOST_TYPE ttype, uint64_t id): m_id(id), pos(tpos), type(ttype){}
Booster::~Booster()
{
@@ -26,6 +21,11 @@ BOOST_TYPE Booster::GetType()
return type;
}
uint64_t Booster::GetId() const
{
return m_id;
}
bool Booster::GetAvailability()
{
return available;
@@ -34,5 +34,6 @@ bool Booster::GetAvailability()
void Booster::SetAvailability(bool value)
{
available = value;
modified = true;
}

View File

@@ -6,15 +6,18 @@
class Booster {
public:
Booster();
Booster(Vector3f tpos, BOOST_TYPE ttype);
Booster(Vector3f tpos, BOOST_TYPE ttype, uint64_t id);
~Booster();
Vector3f GetPosition();
BOOST_TYPE GetType();
uint64_t GetId() const;
bool GetAvailability();
void SetAvailability(bool value);
bool modified = true;
private:
Vector3f pos;
BOOST_TYPE type;
bool available;
uint64_t m_id;
bool available = true;
};
#endif

View File

@@ -12,8 +12,12 @@ Bullet::~Bullet() {}
bool Bullet::Update(World* world, float elapsedtime, int perframe, std::unordered_map<uint64_t, Player*> mapPlayer, netprot::ChunkMod** chunkmod) {
int max = 100 / perframe;
Player* shooter = mapPlayer.at(m_shooter_id);
float damage = shooter->boostdamage? 0.123f: 0.098f;
Player* shooter = nullptr;
float damage = 0.098f;
if (mapPlayer.count(m_shooter_id)) {
shooter = mapPlayer.at(m_shooter_id);
damage = shooter->boostdamage ? 0.123f : 0.098f;
}
for (int x = 0; x < max; ++x) {
m_currentpos += m_velocity * elapsedtime;

View File

@@ -553,7 +553,7 @@ void netprot::Serialize(PickupMod* pmod, char* buf[], uint32_t* buflen) {
(uint8_t)((vec[2] >> 8) & 0xFF),
(uint8_t)(vec[2] & 0xFF) };
memcpy(*buf + sizeof(uint64_t) + 1, vec8, sizeof(uint32_t) * 3);
memcpy(*buf + sizeof(uint64_t) + 2, vec8, sizeof(uint32_t) * 3);
Boosts boost = pmod->boost;
uint8_t boost8 = // Reste 5 bits.

View File

@@ -133,7 +133,7 @@ namespace netprot {
Vector3f pos;
Boosts boost;
bool available = true;
PickupMod();
PickupMod() {}
PickupMod(PickupMod* pmod) : id(pmod->id), pos(pmod->pos), boost(pmod->boost), available(pmod->available) {}
};

View File

@@ -84,7 +84,7 @@ Vector3f Player::GetInput(bool front, bool back, bool left, bool right, bool jum
return delta;
}
Player::Sound Player::ApplyPhysics(Vector3f input, World* world, float elapsedTime, Booster booster_table[]) {
Player::Sound Player::ApplyPhysics(Vector3f input, World* world, float elapsedTime, std::unordered_map<uint64_t, Booster*> booster_table) {
Player::Sound snd = Player::Sound::NOSOUND;
static float timing = 0.f;
/* Gestion de collisions */
@@ -196,16 +196,16 @@ void Player::ApplyTransformation(Transformation& transformation, bool rel, bool
if (rel) transformation.ApplyTranslation(-GetPOV());
}
void Player::TakeBooster(Booster booster_table[], float elapsedtime)
void Player::TakeBooster(std::unordered_map<uint64_t, Booster*> booster_table, float elapsedtime)
{
Vector3f playerpos = GetPosition();
for (int i = 0; i < sizeof(booster_table); i++)
for (auto& [key, booster]: booster_table)
{
Vector3f pos = booster_table[i].GetPosition();
if (abs(playerpos.x - pos.x) <= 0.5f && abs(playerpos.y - pos.y) <= 1.0f && abs(playerpos.z - pos.z) <= 0.5f && booster_table[i].GetAvailability() == true)
Vector3f pos = booster->GetPosition();
if (booster->GetAvailability() && abs(playerpos.x - pos.x) <= 0.5f && abs(playerpos.y - pos.y) <= 1.0f && abs(playerpos.z - pos.z) <= 0.5f)
{
GetBooster(booster_table[i].GetType(), elapsedtime);
booster_table[i].SetAvailability(false);
GetBooster(booster->GetType(), elapsedtime);
booster->SetAvailability(false);
break;
}
}

View File

@@ -2,6 +2,7 @@
#define PLAYER_H__
#include <cmath>
#include <unordered_map>
#include "transformation.h"
#include "vector3.h"
#include "booster.h"
@@ -21,8 +22,8 @@ public:
void TurnLeftRight(float value, float sensitivity);
void TurnTopBottom(float value, float sensitivity);
Vector3f GetInput(bool front, bool back, bool left, bool right, bool jump, bool dash, float elapsedTime);
Sound ApplyPhysics(Vector3f input, World* world, float elapsedTime, Booster booster_table[]);
void TakeBooster(Booster booster_table[], float elapsedTime);
Sound ApplyPhysics(Vector3f input, World* world, float elapsedTime, std::unordered_map<uint64_t, Booster*> booster_table);
void TakeBooster(std::unordered_map<uint64_t, Booster*> booster_table, float elapsedTime);
void GetBooster(BOOST_TYPE boosttype, float elapsedTime);
void RemoveBooster(float elapsedtime);
void ApplyTransformation(Transformation& transformation, bool rel = true, bool rot = true) const;