Compare commits
13 Commits
2c346139d5
...
535d6f7745
Author | SHA1 | Date | |
---|---|---|---|
|
535d6f7745 | ||
|
40e90fe12d | ||
|
6076b55267 | ||
|
f799e689d2 | ||
|
6d07285f43 | ||
|
25b5c1e492 | ||
|
f1bb7447f9 | ||
|
68d03c1eac | ||
|
cf831e339f | ||
|
9a669acd9c | ||
|
f2c5f8b636 | ||
|
2364fb9c1f | ||
|
570bef266c |
@ -131,6 +131,7 @@
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="booster.h" />
|
||||
<ClInclude Include="array2d.h" />
|
||||
<ClInclude Include="array3d.h" />
|
||||
<ClInclude Include="blockinfo.h" />
|
||||
@ -147,6 +148,7 @@
|
||||
<ClInclude Include="world.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="booster.cpp" />
|
||||
<ClCompile Include="blockinfo.cpp" />
|
||||
<ClCompile Include="boostinfo.cpp" />
|
||||
<ClCompile Include="bullet.cpp" />
|
||||
|
@ -54,6 +54,9 @@
|
||||
<ClInclude Include="transformation.h">
|
||||
<Filter>Fichiers d%27en-tête</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="booster.h">
|
||||
<Filter>Fichiers d%27en-tête</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="boostinfo.h">
|
||||
<Filter>Fichiers d%27en-tête</Filter>
|
||||
</ClInclude>
|
||||
@ -83,6 +86,9 @@
|
||||
<ClCompile Include="transformation.cpp">
|
||||
<Filter>Fichiers sources</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="booster.cpp">
|
||||
<Filter>Fichiers sources</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="boostinfo.cpp">
|
||||
<Filter>Fichiers sources</Filter>
|
||||
</ClCompile>
|
||||
|
39
SQCSim-common/booster.cpp
Normal file
39
SQCSim-common/booster.cpp
Normal file
@ -0,0 +1,39 @@
|
||||
#include "booster.h"
|
||||
|
||||
Booster::Booster()
|
||||
{
|
||||
}
|
||||
|
||||
Booster::Booster(Vector3f tpos, BOOST_TYPE ttype, uint64_t id): m_id(id), pos(tpos), type(ttype){}
|
||||
|
||||
Booster::~Booster()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Vector3f Booster::GetPosition()
|
||||
{
|
||||
return pos;
|
||||
}
|
||||
|
||||
BOOST_TYPE Booster::GetType()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
uint64_t Booster::GetId() const
|
||||
{
|
||||
return m_id;
|
||||
}
|
||||
|
||||
bool Booster::GetAvailability()
|
||||
{
|
||||
return available;
|
||||
}
|
||||
|
||||
void Booster::SetAvailability(bool value)
|
||||
{
|
||||
available = value;
|
||||
modified = true;
|
||||
}
|
||||
|
23
SQCSim-common/booster.h
Normal file
23
SQCSim-common/booster.h
Normal file
@ -0,0 +1,23 @@
|
||||
#ifndef BOOSTER_H__
|
||||
#define BOOSTER_H__
|
||||
#include "define.h"
|
||||
#include "vector3.h"
|
||||
|
||||
class Booster {
|
||||
public:
|
||||
Booster();
|
||||
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;
|
||||
uint64_t m_id;
|
||||
bool available = true;
|
||||
};
|
||||
#endif
|
@ -12,7 +12,13 @@ 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 = 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;
|
||||
|
||||
@ -29,7 +35,7 @@ bool Bullet::Update(World* world, float elapsedtime, int perframe, std::unordere
|
||||
hit = true;
|
||||
}
|
||||
if (hit && !player->AmIDead()) {
|
||||
if (m_canhurt)
|
||||
if (m_canhurt && !player->boostinvincible)
|
||||
player->InflictDamage(damage);
|
||||
player->m_hit = true;
|
||||
|
||||
|
@ -31,10 +31,11 @@
|
||||
#define TEXTURE_SIZE 512
|
||||
#define MAX_BULLETS 512
|
||||
|
||||
#define NB_BOOST 2
|
||||
#define TIME_SPEED_BOOST 10 //secondes
|
||||
#define TIME_DAMAGE_BOOST 10 //secondes
|
||||
#define TIME_INVINCIBLE_BOOST 4 //secondes
|
||||
#define STRENGTH_SPEED_BOOST 10 //Pourcentage
|
||||
#define STRENGTH_SPEED_BOOST 1000 //Pourcentage
|
||||
#define BULLET_TIME .2 //secondes
|
||||
|
||||
#define SYNC_ACC 600 // ms
|
||||
|
@ -212,7 +212,14 @@ void netprot::Serialize(Sync* sync, char* buf[], uint32_t* buflen) {
|
||||
|
||||
memcpy(*buf + sizeof(uint64_t) * 2 + sizeof(uint32_t) * 4 + sizeof(uint16_t) + 1, hp8, sizeof(float));
|
||||
|
||||
*buflen = sizeof(uint64_t) * 2 + sizeof(uint32_t) * 4 + sizeof(uint16_t) + sizeof(float) + 1;
|
||||
Boosts boost = sync->boost;
|
||||
uint8_t boost8 = // Reste 6 bits.
|
||||
(boost.invincible ? 0b10000000 : 0) |
|
||||
(boost.damage ? 0b01000000 : 0);
|
||||
|
||||
memcpy(*buf + sizeof(uint64_t) * 2 + sizeof(uint32_t) * 5 + sizeof(uint16_t) + 1, &boost8, sizeof(uint8_t));
|
||||
|
||||
*buflen = sizeof(uint64_t) * 2 + sizeof(uint32_t) * 5 + sizeof(uint16_t) + sizeof(float) + 2;
|
||||
}
|
||||
|
||||
void netprot::Serialize(TeamInfo* tinfo, char* buf[], uint32_t* buflen) {
|
||||
@ -514,6 +521,53 @@ void netprot::Serialize(BulletAdd* bull, char* buf[], uint32_t* buflen) {
|
||||
*buflen = 1 + sizeof(uint64_t) * 2 + sizeof(uint32_t) * 6;
|
||||
}
|
||||
|
||||
void netprot::Serialize(PickupMod* pmod, char* buf[], uint32_t* buflen) {
|
||||
*buf[0] = (char)netprot::PACKET_TYPE::PICKUPMOD;
|
||||
|
||||
uint64_t id = pmod->id;
|
||||
uint8_t id8[sizeof(uint64_t)] = { (uint8_t)((id >> 56) & 0xFF),
|
||||
(uint8_t)((id >> 48) & 0xFF),
|
||||
(uint8_t)((id >> 40) & 0xFF),
|
||||
(uint8_t)((id >> 32) & 0xFF),
|
||||
(uint8_t)((id >> 24) & 0xFF),
|
||||
(uint8_t)((id >> 16) & 0xFF),
|
||||
(uint8_t)((id >> 8) & 0xFF),
|
||||
(uint8_t)(id & 0xFF) };
|
||||
|
||||
memcpy(*buf + 1, id8, sizeof(uint64_t));
|
||||
|
||||
uint32_t vec[3];
|
||||
memcpy(vec, &pmod->pos, sizeof(Vector3f)); // Pour d<>naturer les floats.
|
||||
|
||||
uint8_t vec8[3 * sizeof(uint32_t)] = {
|
||||
(uint8_t)((vec[0] >> 24) & 0xFF),
|
||||
(uint8_t)((vec[0] >> 16) & 0xFF),
|
||||
(uint8_t)((vec[0] >> 8) & 0xFF),
|
||||
(uint8_t)(vec[0] & 0xFF),
|
||||
(uint8_t)((vec[1] >> 24) & 0xFF),
|
||||
(uint8_t)((vec[1] >> 16) & 0xFF),
|
||||
(uint8_t)((vec[1] >> 8) & 0xFF),
|
||||
(uint8_t)(vec[1] & 0xFF),
|
||||
(uint8_t)((vec[2] >> 24) & 0xFF),
|
||||
(uint8_t)((vec[2] >> 16) & 0xFF),
|
||||
(uint8_t)((vec[2] >> 8) & 0xFF),
|
||||
(uint8_t)(vec[2] & 0xFF) };
|
||||
|
||||
memcpy(*buf + sizeof(uint64_t) + 2, vec8, sizeof(uint32_t) * 3);
|
||||
|
||||
Boosts boost = pmod->boost;
|
||||
uint8_t boost8 = // Reste 5 bits.
|
||||
(boost.invincible ? 0b10000000 : 0) |
|
||||
(boost.damage ? 0b01000000 : 0) |
|
||||
(boost.hp ? 0b00100000 : 0);
|
||||
|
||||
memcpy(*buf + sizeof(uint64_t) + sizeof(uint32_t) * 3 + 1, &boost8, sizeof(uint8_t));
|
||||
|
||||
memcpy(*buf + 2 + sizeof(uint64_t) + sizeof(uint32_t) * 3, &pmod->available, sizeof(bool));
|
||||
|
||||
*buflen = 2 + sizeof(uint64_t) + sizeof(uint32_t) * 3 + 3;
|
||||
}
|
||||
|
||||
void netprot::Serialize(ErrorLog* errlog, char* buf[], uint32_t* buflen) {
|
||||
*buf[0] = (char)netprot::PACKET_TYPE::ERRLOG;
|
||||
|
||||
@ -528,6 +582,7 @@ void netprot::Serialize(ErrorLog* errlog, char* buf[], uint32_t* buflen) {
|
||||
|
||||
|
||||
|
||||
|
||||
bool netprot::Deserialize(Input* in, char* buf, uint32_t* buflen) {
|
||||
if (*buflen <= sizeof(Input))
|
||||
return false;
|
||||
@ -736,7 +791,12 @@ bool netprot::Deserialize(Sync* sync, char* buf, uint32_t* buflen) {
|
||||
|
||||
memcpy(&sync->hp, &hp, sizeof(float));
|
||||
|
||||
*buflen = 1 + sizeof(uint64_t) * 2 + sizeof(uint32_t) * 4 + sizeof(uint16_t) + sizeof(float);
|
||||
uint8_t boost = 0;
|
||||
memcpy(&boost, &buf[2 + sizeof(uint64_t) * 2 + sizeof(uint32_t) * 5 + sizeof(uint16_t)], sizeof(uint8_t));
|
||||
sync->boost.invincible = boost & 0b10000000;
|
||||
sync->boost.damage = boost & 0b01000000;
|
||||
|
||||
*buflen = 2 + sizeof(uint64_t) * 2 + sizeof(uint32_t) * 5 + sizeof(uint16_t) + sizeof(float);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -1059,6 +1119,53 @@ bool netprot::Deserialize(ErrorLog* errlog, char* buf, uint32_t* buflen) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool netprot::Deserialize(PickupMod* pmod, char* buf, uint32_t* buflen) {
|
||||
if (*buflen <= sizeof(PickupMod))
|
||||
return false;
|
||||
|
||||
uint8_t diff[sizeof(uint64_t)] = { 0,0,0,0,0,0,0,0 };
|
||||
memcpy(diff, &buf[1], sizeof(uint64_t));
|
||||
pmod->id =
|
||||
(uint64_t)diff[0] << 56 |
|
||||
(uint64_t)diff[1] << 48 |
|
||||
(uint64_t)diff[2] << 40 |
|
||||
(uint64_t)diff[3] << 32 |
|
||||
(uint64_t)diff[4] << 24 |
|
||||
(uint64_t)diff[5] << 16 |
|
||||
(uint64_t)diff[6] << 8 |
|
||||
(uint64_t)diff[7];
|
||||
|
||||
uint8_t subvec[3 * sizeof(uint32_t)] = { 0,0,0,0,0,0,0,0,0,0,0,0 };
|
||||
memcpy(subvec, &buf[2 + sizeof(uint64_t)], sizeof(uint8_t) * 12);
|
||||
uint32_t vec[3] = {
|
||||
(uint32_t)subvec[0] << 24 |
|
||||
(uint32_t)subvec[1] << 16 |
|
||||
(uint32_t)subvec[2] << 8 |
|
||||
(uint32_t)subvec[3],
|
||||
(uint32_t)subvec[4] << 24 |
|
||||
(uint32_t)subvec[5] << 16 |
|
||||
(uint32_t)subvec[6] << 8 |
|
||||
(uint32_t)subvec[7],
|
||||
(uint32_t)subvec[8] << 24 |
|
||||
(uint32_t)subvec[9] << 16 |
|
||||
(uint32_t)subvec[10] << 8 |
|
||||
(uint32_t)subvec[11] };
|
||||
|
||||
memcpy(&pmod->pos, vec, sizeof(uint32_t) * 3);
|
||||
|
||||
uint8_t boosts = 0;
|
||||
memcpy(&boosts, &buf[1 + sizeof(uint64_t) + sizeof(uint32_t) * 3], sizeof(uint8_t));
|
||||
pmod->boost.invincible = boosts & 0b10000000;
|
||||
pmod->boost.damage = boosts & 0b01000000;
|
||||
pmod->boost.hp = boosts & 0b00100000;
|
||||
|
||||
memcpy(&pmod->available, &buf[2 + sizeof(uint64_t) + sizeof(uint32_t) * 3], sizeof(bool));
|
||||
|
||||
*buflen = 3 + sizeof(uint64_t) + sizeof(uint32_t) * 3;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
netprot::PACKET_TYPE netprot::getType(char* buf, const uint32_t buflen) {
|
||||
|
@ -58,6 +58,12 @@ namespace netprot {
|
||||
running = false;
|
||||
};
|
||||
|
||||
struct Boosts {
|
||||
bool invincible = false,
|
||||
damage = false,
|
||||
hp = false;
|
||||
};
|
||||
|
||||
/* Structures de paquets */
|
||||
|
||||
struct Input { // cli -> srv UDP ~frame
|
||||
@ -80,10 +86,11 @@ namespace netprot {
|
||||
uint64_t sid = 0;
|
||||
uint32_t timer = 0;
|
||||
uint16_t ammo = 0;
|
||||
Boosts boost;
|
||||
float hp = 0;
|
||||
Vector3f position;
|
||||
Sync() {}
|
||||
Sync(Sync* sync) : timestamp(sync->timestamp), sid(sync->sid), timer(sync->timer), ammo(sync->ammo), hp(sync->hp), position(sync->position) {}
|
||||
Sync(Sync* sync) : timestamp(sync->timestamp), sid(sync->sid), timer(sync->timer), ammo(sync->ammo), hp(sync->hp), position(sync->position), boost(sync->boost) {}
|
||||
};
|
||||
|
||||
struct TeamInfo { // cli <-> srv TCP once
|
||||
@ -121,6 +128,15 @@ namespace netprot {
|
||||
GameInfo(GameInfo* gam) : seed(gam->seed), countdown(gam->countdown), gameType(gam->gameType) {}
|
||||
};
|
||||
|
||||
struct PickupMod {
|
||||
uint64_t id;
|
||||
Vector3f pos;
|
||||
Boosts boost;
|
||||
bool available = true;
|
||||
PickupMod() {}
|
||||
PickupMod(PickupMod* pmod) : id(pmod->id), pos(pmod->pos), boost(pmod->boost), available(pmod->available) {}
|
||||
};
|
||||
|
||||
struct Chat { // cli <-> srv TCP event
|
||||
uint64_t src_id = 0,
|
||||
dest_id = 0,
|
||||
@ -161,6 +177,7 @@ namespace netprot {
|
||||
void Serialize(GameInfo* ginfo, char* buf[], uint32_t* buflen); // cli/srv
|
||||
void Serialize(Chat* chat, char* buf[], uint32_t* buflen); // cli/srv
|
||||
void Serialize(ChunkMod* chmod, char* buf[], uint32_t* buflen); // srv
|
||||
void Serialize(PickupMod* chmod, char* buf[], uint32_t* buflen); // srv
|
||||
void Serialize(BulletAdd* bull, char* buf[], uint32_t* buflen); // srv
|
||||
void Serialize(ErrorLog* errlog, char* buf[], uint32_t* buflen); // srv
|
||||
|
||||
@ -173,6 +190,7 @@ namespace netprot {
|
||||
bool Deserialize(GameInfo* ginfo, char* buf, uint32_t* buflen); // cli
|
||||
bool Deserialize(Chat* chat, char* buf, uint32_t* buflen); // srv/cli
|
||||
bool Deserialize(ChunkMod* chmod, char* buf, uint32_t* buflen); // cli
|
||||
bool Deserialize(PickupMod* chmod, char* buf, uint32_t* buflen); // cli
|
||||
bool Deserialize(BulletAdd* bull, char* buf, uint32_t* buflen); // cli
|
||||
bool Deserialize(ErrorLog* errlog, char* buf, uint32_t* buflen); // srv
|
||||
|
||||
|
@ -68,8 +68,8 @@ Vector3f Player::GetInput(bool front, bool back, bool left, bool right, bool jum
|
||||
delta.x *= .6f;
|
||||
delta.z *= .6f;
|
||||
|
||||
if ((jump || shoot ) && !m_airborne) {
|
||||
delta.y += jump? .32f: shoot? .1f : 0.f;
|
||||
if ((jump || shoot) && !m_airborne) {
|
||||
delta.y += jump ? .32f : shoot ? .1f : 0.f;
|
||||
m_airborne = true;
|
||||
}
|
||||
if (boostspeed)
|
||||
@ -124,7 +124,6 @@ Player::Sound Player::ApplyPhysics(Vector3f input, World* world, float elapsedTi
|
||||
bt2 = world->BlockAt(GetPosition().x + input.x, GetPosition().y - 0.9f, GetPosition().z);
|
||||
bt3 = world->BlockAt(GetPosition().x + input.x, GetPosition().y - 1.7f, GetPosition().z);
|
||||
if (bt1 != BTYPE_AIR || bt2 != BTYPE_AIR || bt3 != BTYPE_AIR) {
|
||||
//input.x = m_velocity.x = 0;
|
||||
m_velocity.y += .04f;
|
||||
m_velocity.z *= .5f;
|
||||
m_velocity.x *= .5f;
|
||||
@ -134,50 +133,17 @@ Player::Sound Player::ApplyPhysics(Vector3f input, World* world, float elapsedTi
|
||||
bt2 = world->BlockAt(GetPosition().x, GetPosition().y - 0.9f, GetPosition().z + input.z);
|
||||
bt3 = world->BlockAt(GetPosition().x, GetPosition().y - 1.7f, GetPosition().z + input.z);
|
||||
if (bt1 != BTYPE_AIR || bt2 != BTYPE_AIR || bt3 != BTYPE_AIR) {
|
||||
//input.z = m_velocity.z = 0;
|
||||
m_velocity.y += .04f;
|
||||
m_velocity.z *= .5f;
|
||||
m_velocity.x *= .5f;
|
||||
}
|
||||
|
||||
//bt1 = world->BlockAt(GetPosition().x + input.x, GetPosition().y, GetPosition().z);
|
||||
//bt2 = world->BlockAt(GetPosition().x + input.x, GetPosition().y - 0.9f, GetPosition().z);
|
||||
//bt3 = world->BlockAt(GetPosition().x + input.x, GetPosition().y - 1.7f, GetPosition().z);
|
||||
//if (bt1 == BTYPE_AIR && bt2 != BTYPE_AIR && bt3 != BTYPE_AIR) {
|
||||
// if (input.x > 0)
|
||||
// input.x = m_velocity.x = 0.5f;
|
||||
// else
|
||||
// input.x = m_velocity.x = -0.5f;
|
||||
// m_velocity.y = 0.3;
|
||||
// m_velocity.z *= .5f;
|
||||
//}
|
||||
//else if (bt1 != BTYPE_AIR || bt2 != BTYPE_AIR || bt3 != BTYPE_AIR) {
|
||||
// input.x = m_velocity.x = 0;
|
||||
// m_velocity.z *= .5f;
|
||||
//}
|
||||
|
||||
//bt1 = world->BlockAt(GetPosition().x, GetPosition().y, GetPosition().z + input.z);
|
||||
//bt2 = world->BlockAt(GetPosition().x, GetPosition().y - 0.9f, GetPosition().z + input.z);
|
||||
//bt3 = world->BlockAt(GetPosition().x, GetPosition().y - 1.7f, GetPosition().z + input.z);
|
||||
//if (bt1 == BTYPE_AIR && bt2 != BTYPE_AIR && bt3 != BTYPE_AIR) {
|
||||
// if (input.z > 0)
|
||||
// input.z = m_velocity.z = 0.5f;
|
||||
// else
|
||||
// input.z = m_velocity.z = -0.5f;
|
||||
// m_velocity.y = 0.3;
|
||||
// m_velocity.x *= .5f;
|
||||
//}
|
||||
//else if (bt1 != BTYPE_AIR || bt2 != BTYPE_AIR || bt3 != BTYPE_AIR) {
|
||||
// input.z = m_velocity.z = 0;
|
||||
// m_velocity.x *= .5f;
|
||||
//}
|
||||
|
||||
/* Fin gestion de collisions */
|
||||
/* Gestion de la friction */
|
||||
|
||||
if (!m_airborne) {
|
||||
m_velocity.x += input.x * 2.f * elapsedTime;
|
||||
m_velocity.z += input.z * 2.f * elapsedTime;
|
||||
m_velocity.x += input.x * (boostspeed ? 2.5f : 2.f) * elapsedTime;
|
||||
m_velocity.z += input.z * (boostspeed ? 2.5f : 2.f) * elapsedTime;
|
||||
|
||||
if (input.x == 0.f)
|
||||
m_velocity.x *= .8f;
|
||||
@ -195,7 +161,7 @@ Player::Sound Player::ApplyPhysics(Vector3f input, World* world, float elapsedTi
|
||||
/* Fin gestion de la friction */
|
||||
|
||||
float vy = m_velocity.y;
|
||||
m_velocity.y = 1.f; // Padding pour limiter le x et z lors du Normalize().
|
||||
m_velocity.y = boostspeed ? 0.f: 1.f; // Padding pour limiter le x et z lors du Normalize().
|
||||
if (m_velocity.Length() >= 1.f) m_velocity.Normalize(); // Limiteur de vitesse en x/z.
|
||||
m_velocity.y = 0;
|
||||
if (m_velocity.Length() < .005f) m_velocity.Zero(); // Threshold en x/z.
|
||||
@ -222,29 +188,51 @@ Player::Sound Player::ApplyPhysics(Vector3f input, World* world, float elapsedTi
|
||||
return snd;
|
||||
}
|
||||
|
||||
void Player::Put(Vector3f pos) {
|
||||
m_position = pos;
|
||||
}
|
||||
|
||||
void Player::ApplyTransformation(Transformation& transformation, bool rel, bool rot) const {
|
||||
|
||||
transformation.ApplyRotation(-m_rotX, 1, 0, 0);
|
||||
transformation.ApplyRotation(-m_rotY, 0, 1, 0);
|
||||
if (rel) transformation.ApplyTranslation(-GetPOV());
|
||||
}
|
||||
|
||||
void Player::GetBooster(Booster boosttype)
|
||||
uint64_t Player::TakeBooster(std::unordered_map<uint64_t, Booster*> booster_table, float elapsedtime)
|
||||
{
|
||||
if (boosttype == SPEED)
|
||||
uint64_t boostid = 0;
|
||||
Vector3f playerpos = GetPosition();
|
||||
for (auto& [key, booster]: booster_table) {
|
||||
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)
|
||||
{
|
||||
boostid = booster->GetId();
|
||||
GetBooster(booster->GetType(), elapsedtime);
|
||||
booster->SetAvailability(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return boostid;
|
||||
}
|
||||
|
||||
void Player::GetBooster(BOOST_TYPE boosttype, float elapsedtime)
|
||||
{
|
||||
if (boosttype == BTYPE_SPEED)
|
||||
{
|
||||
boostspeed = true;
|
||||
timeboostspeed = 0;
|
||||
}
|
||||
if (boosttype == HEAL)
|
||||
if (boosttype == BTYPE_HEAL)
|
||||
{
|
||||
m_hp = 100;
|
||||
m_hp = 1.0f;
|
||||
}
|
||||
if (boosttype == DAMAGE)
|
||||
if (boosttype == BTYPE_DAMAGE)
|
||||
{
|
||||
boostdamage = true;
|
||||
timeboostdamage = 0;
|
||||
}
|
||||
if (boosttype == INVINCIBLE)
|
||||
if (boosttype == BTYPE_INVINCIBLE)
|
||||
{
|
||||
boostinvincible = true;
|
||||
boostinvincible = 0;
|
||||
@ -255,19 +243,17 @@ void Player::RemoveBooster(float elapsedtime)
|
||||
if (boostspeed)
|
||||
{
|
||||
timeboostspeed += elapsedtime;
|
||||
if (timeboostspeed >= TIME_SPEED_BOOST)
|
||||
if (timeboostspeed >= TIME_SPEED_BOOST && boostspeed == true)
|
||||
boostspeed = false;
|
||||
}
|
||||
if (boostdamage)
|
||||
{
|
||||
timeboostdamage += elapsedtime;
|
||||
if (timeboostdamage >= TIME_DAMAGE_BOOST)
|
||||
if (timeboostdamage >= TIME_DAMAGE_BOOST && boostdamage == true)
|
||||
boostdamage = false;
|
||||
}
|
||||
if (boostinvincible)
|
||||
{
|
||||
timeboostinvincible += elapsedtime;
|
||||
if (timeboostinvincible >= TIME_INVINCIBLE_BOOST)
|
||||
if (timeboostinvincible >= TIME_INVINCIBLE_BOOST && boostinvincible == true)
|
||||
boostinvincible = false;
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,11 @@
|
||||
#define PLAYER_H__
|
||||
|
||||
#include <cmath>
|
||||
#include <unordered_map>
|
||||
#include "transformation.h"
|
||||
#include "vector3.h"
|
||||
#include "booster.h"
|
||||
#include "define.h"
|
||||
|
||||
|
||||
class World;
|
||||
@ -11,7 +14,7 @@ class World;
|
||||
class Player {
|
||||
public:
|
||||
enum Sound { NOSOUND, STEP, FALL };
|
||||
enum Booster { SPEED, HEAL, DAMAGE, INVINCIBLE };
|
||||
//enum BoosterType { SPEED, HEAL, DAMAGE, INVINCIBLE };
|
||||
|
||||
Player(const Vector3f& position, float rotX = 0, float rotY = 0);
|
||||
~Player();
|
||||
@ -20,7 +23,8 @@ public:
|
||||
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);
|
||||
void GetBooster(Booster boosttype);
|
||||
uint64_t 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;
|
||||
|
||||
@ -50,6 +54,12 @@ public:
|
||||
|
||||
bool Eulogy = false;
|
||||
|
||||
bool boostspeed = false;
|
||||
bool boostdamage = false;
|
||||
bool boostinvincible = false;
|
||||
|
||||
void Put(Vector3f pos);
|
||||
|
||||
private:
|
||||
uint64_t getId() const;
|
||||
|
||||
@ -72,9 +82,6 @@ protected:
|
||||
float m_hp;
|
||||
|
||||
bool m_airborne;
|
||||
bool boostspeed;
|
||||
bool boostdamage;
|
||||
bool boostinvincible;
|
||||
|
||||
Vector3f InterpolatePosition(const Vector3f& vec1, const Vector3f& vec2, const Timestamp& tim1, const Timestamp& tim2, const Timestamp& now);
|
||||
};
|
||||
|
@ -132,7 +132,7 @@ void Connection::sendPacks(SOCKET sock, std::unordered_map<uint64_t, Connection*
|
||||
}
|
||||
}
|
||||
|
||||
Timestamp Connection::Run(World* world) {
|
||||
Timestamp Connection::Run(World* world, std::unordered_map<uint64_t, Booster*> boosters) {
|
||||
Input in, last;
|
||||
Output out;
|
||||
Timestamp tstamp = 0;
|
||||
@ -169,7 +169,10 @@ Timestamp Connection::Run(World* world) {
|
||||
in.keys.backward,
|
||||
in.keys.left,
|
||||
in.keys.right,
|
||||
in.keys.jump, false, el), world, el);
|
||||
in.keys.jump, false, el),
|
||||
world, el);
|
||||
|
||||
player->TakeBooster(boosters, el);
|
||||
|
||||
if (player->GetPosition().y < -20.) {
|
||||
player->InflictDamage(9000.);
|
||||
|
@ -36,7 +36,7 @@ public:
|
||||
void getPacks(SOCKET sock);
|
||||
void sendPacks(SOCKET sock, std::unordered_map<uint64_t, Connection*> conns, const uint32_t timer);
|
||||
|
||||
Timestamp Run(World* world);
|
||||
Timestamp Run(World* world, std::unordered_map<uint64_t, Booster*> boosters);
|
||||
|
||||
void CleanInputManifest(Timestamp time);
|
||||
|
||||
|
@ -21,6 +21,7 @@ const std::vector<std::string> DEATHMESSAGES = { "@ has gone to meet their maker
|
||||
"So long, @, and thanks for all the lols!",
|
||||
"@ has a bad case of being dead.",
|
||||
"@ has finally seen the light!",
|
||||
"$ sees dead people; in this case they see a dead @.",
|
||||
"Thought @ was hot; guess what? He's not. He is dead, dead, dead.",
|
||||
"@ did not want to live forever.",
|
||||
"$ made @ die for their country.",
|
||||
|
@ -83,18 +83,18 @@ int Server::Ready() {
|
||||
m_game.countdown = 0;
|
||||
}
|
||||
} while (m_game.countdown < 1);
|
||||
m_game.seed = 9370707;
|
||||
/*do {
|
||||
// m_game.seed = 9370707;
|
||||
do {
|
||||
Log("Entrez le seed de la partie: ", false, false);
|
||||
std::cin.getline(m_buf.ptr, BUFFER_LENGTH);
|
||||
try {
|
||||
std::stoi(m_buf.ptr);
|
||||
m_game.seed = std::stoi(m_buf.ptr);
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
Log(e.what(), true, false);
|
||||
m_game.seed = 0;
|
||||
}
|
||||
} while (m_game.seed < 1);*/
|
||||
} while (m_game.seed < 1);
|
||||
do {
|
||||
Log("Entrez le nombre de joueurs: ", false, false);
|
||||
std::cin.getline(m_buf.ptr, BUFFER_LENGTH);
|
||||
@ -108,7 +108,17 @@ int Server::Ready() {
|
||||
if (nbrjoueurs <= 0 || nbrjoueurs > MAX_CONNECTIONS)
|
||||
Log("Nombre de joueurs invalide.", true, false);
|
||||
} while (nbrjoueurs <= 0 || nbrjoueurs > MAX_CONNECTIONS);
|
||||
|
||||
do {
|
||||
Log("Entrez le nombre de boosters: ", false, false);
|
||||
std::cin.getline(m_buf.ptr, BUFFER_LENGTH);
|
||||
try {
|
||||
m_boostcount = std::stoi(m_buf.ptr);
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
Log(e.what(), true, false);
|
||||
m_boostcount = -1;
|
||||
}
|
||||
} while (m_boostcount < 0);
|
||||
m_game.gameType = 1;
|
||||
|
||||
if (listen(m_sock_tcp, MAX_CONNECTIONS) < 0) {
|
||||
@ -202,8 +212,8 @@ void Server::Run() {
|
||||
m_conns.erase(key);
|
||||
continue;
|
||||
}
|
||||
int x = (rand() % (CHUNK_SIZE_X * WORLD_SIZE_X - 1) - (CHUNK_SIZE_X * WORLD_SIZE_X / 2)) / 16,
|
||||
y = (rand() % (CHUNK_SIZE_Y * WORLD_SIZE_Y - 1) - (CHUNK_SIZE_Y * WORLD_SIZE_Y / 2)) / 16;
|
||||
int x = (rand() % (CHUNK_SIZE_X * WORLD_SIZE_X - 1) - (CHUNK_SIZE_X * WORLD_SIZE_X / 2)) / 4,
|
||||
y = (rand() % (CHUNK_SIZE_Z * WORLD_SIZE_Y - 1) - (CHUNK_SIZE_Z * WORLD_SIZE_Y / 2)) / 4;
|
||||
conn->player = new Player(Vector3f(x + .5f, CHUNK_SIZE_Y + 1.8f, y + .5f));
|
||||
conn->player->m_username = conn->GetName();
|
||||
m_players[key] = conn->player;
|
||||
@ -225,8 +235,21 @@ void Server::Run() {
|
||||
std::vector<Bullet*> bullets;
|
||||
std::vector<std::vector<Bullet*>::iterator> bullit;
|
||||
std::vector<BulletAdd*> netbull;
|
||||
std::vector<PickupMod*> netboosters;
|
||||
std::vector<char*> lsPck;
|
||||
|
||||
int max = 0;
|
||||
for (int64_t x = 0; x < m_boostcount; ++x) {
|
||||
Vector3f pos = Vector3f(rand() % (WORLD_SIZE_X * CHUNK_SIZE_X) + .5f, rand() % CHUNK_SIZE_Y + .5f, rand() % (WORLD_SIZE_Y * CHUNK_SIZE_Z) + .5f);
|
||||
if (m_world->BlockAt(pos) == BTYPE_AIR && m_world->BlockAt(Vector3f(pos.x, pos.y - 2, pos.z)) != BTYPE_AIR) {
|
||||
Booster* boost = new Booster(pos, (BOOST_TYPE)(rand() % BTYPE_BOOST_LAST), getUniqueId());
|
||||
m_boosters[boost->GetId()] = boost;
|
||||
}
|
||||
else --x;
|
||||
if (++max > 100000)
|
||||
break;
|
||||
}
|
||||
|
||||
Chat* startchat = new Chat();
|
||||
startchat->src_id = 0;
|
||||
char startmess[] = "How would -YOU- like to die today, motherf-words?";
|
||||
@ -282,8 +305,7 @@ void Server::Run() {
|
||||
/* Process */
|
||||
|
||||
if (conn->m_nsync) {
|
||||
|
||||
Timestamp tstamp = conn->Run(m_world);
|
||||
Timestamp tstamp = conn->Run(m_world, m_boosters);
|
||||
|
||||
if (conn->player->AmIDead() && !conn->player->Eulogy) {
|
||||
Chat* chat = new Chat();
|
||||
@ -367,6 +389,37 @@ void Server::Run() {
|
||||
}
|
||||
}
|
||||
|
||||
int max = 0;
|
||||
for (auto& [key, booster] : m_boosters) {
|
||||
if (booster->modified) {
|
||||
PickupMod pmod;
|
||||
pmod.available = booster->GetAvailability();
|
||||
pmod.id = booster->GetId();
|
||||
pmod.pos = booster->GetPosition();
|
||||
|
||||
Boosts boost;
|
||||
switch (booster->GetType()) {
|
||||
case BTYPE_DAMAGE:
|
||||
boost.damage = true;
|
||||
break;
|
||||
case BTYPE_HEAL:
|
||||
boost.hp = true;
|
||||
break;
|
||||
case BTYPE_INVINCIBLE:
|
||||
boost.invincible = true;
|
||||
break;
|
||||
default: continue;
|
||||
}
|
||||
pmod.boost = boost;
|
||||
booster->modified = false;
|
||||
for (auto& [key, conn] : m_conns)
|
||||
sendPackTo<PickupMod>(m_sock_udp, &pmod, &m_buf, conn->getAddr());
|
||||
max++;
|
||||
if (max > 5)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& bull : netbull) {
|
||||
for (auto& [key, conn] : m_conns)
|
||||
if (bull->id != conn->GetHash(false)) // Pour pas repitcher au joueur sa propre balle.
|
||||
|
@ -43,12 +43,15 @@ private:
|
||||
std::unordered_map<uint64_t, Player*> m_players;
|
||||
std::unordered_map<uint64_t, Connection*> m_conns;
|
||||
std::unordered_map<Timestamp, Chat> m_chatlog;
|
||||
std::unordered_map<uint64_t, Booster*> m_boosters;
|
||||
std::vector<uint64_t> m_ids;
|
||||
GameInfo m_game;
|
||||
|
||||
World* m_world = nullptr;
|
||||
bool m_exit = true;
|
||||
|
||||
int64_t m_boostcount = -1;
|
||||
|
||||
std::string LogTimestamp();
|
||||
void Log(std::string str, bool is_error, bool is_fatal);
|
||||
void buildIdList(size_t size);
|
||||
|
@ -20,7 +20,6 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="audio.h" />
|
||||
<ClInclude Include="booster.h" />
|
||||
<ClInclude Include="connector.h" />
|
||||
<ClInclude Include="define.h" />
|
||||
<ClInclude Include="engine.h" />
|
||||
@ -38,7 +37,6 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="audio.cpp" />
|
||||
<ClCompile Include="booster.cpp" />
|
||||
<ClCompile Include="connector.cpp" />
|
||||
<ClCompile Include="engine.cpp" />
|
||||
<ClCompile Include="main.cpp" />
|
||||
|
@ -53,9 +53,6 @@
|
||||
<ClInclude Include="remoteplayer.h">
|
||||
<Filter>Fichiers d%27en-tête</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="booster.h">
|
||||
<Filter>Fichiers d%27en-tête</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="settings.h">
|
||||
<Filter>Fichiers d%27en-tête</Filter>
|
||||
</ClInclude>
|
||||
@ -103,9 +100,6 @@
|
||||
<ClCompile Include="remoteplayer.cpp">
|
||||
<Filter>Fichiers sources</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="booster.cpp">
|
||||
<Filter>Fichiers sources</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="settings.cpp">
|
||||
<Filter>Fichiers sources</Filter>
|
||||
</ClCompile>
|
||||
|
@ -1,46 +0,0 @@
|
||||
#include "booster.h"
|
||||
|
||||
void Booster::RenderBillboard(const Vector3f pos, TextureAtlas& textureAtlas, Shader& shader, Transformation tran)
|
||||
{
|
||||
//
|
||||
//Vector3f playerToQuad = m_player.GetPosition() - m_position;
|
||||
//playerToQuad.Normalize();
|
||||
//Vector3f targetPosition = m_player.GetPosition() + playerToQuad * 10.0f;
|
||||
//Matrix4f rotationMatrix;
|
||||
//rotationMatrix.SetLookAt(m_position, targetPosition, Vector3f(0, 1, 0));
|
||||
//glMultMatrixf(rotationMatrix.GetInternalValues());
|
||||
float x = pos.x;
|
||||
float y = pos.y;
|
||||
float z = pos.z;
|
||||
float width = 1.0f;
|
||||
float height = 1.0f;
|
||||
//Pt override les collisions.. a ce point la je sais pas quoi faire
|
||||
|
||||
//Matrix4 mat4 = tran.GetMatrix();
|
||||
//mat4 VP = pMatrix * vMatrix;
|
||||
//Vector3f CameraRight = Vector3f(mat4.Get11(), mat4.Get21(), mat4.Get31());
|
||||
//Vector3f CameraUp = Vector3f(mat4.Get12(), mat4.Get22(), mat4.Get32());
|
||||
|
||||
//Vector3f v1 = (m_position + CameraRight * 0.5 * width + CameraUp * -0.5 * width);
|
||||
//Vector3f v2 = (m_position + CameraRight * 0.5 * width + CameraUp * 0.5 * width);
|
||||
//Vector3f v4 = (m_position + CameraRight * -0.5 * width + CameraUp * -0.5 * width);
|
||||
//Vector3f v3 = (m_position + CameraRight * -0.5 * width + CameraUp * 0.5 * width);
|
||||
|
||||
//tran.ApplyTranslation(m_position);
|
||||
float u, v, w, h;
|
||||
//glDisable(GL_DEPTH_TEST);
|
||||
shader.Use();
|
||||
textureAtlas.Bind();
|
||||
textureAtlas.TextureIndexToCoord(8, u, v, w, h);
|
||||
//glLoadIdentity();
|
||||
glLoadMatrixf(tran.GetMatrix().GetInternalValues());
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(u, v); glVertex3f(x - width / 2., y - height, z); //glVertex3f(v4.x, v4.y, v4.z);//glVertex3f(0, 50, 0);
|
||||
glTexCoord2f(u + w, v); glVertex3f(x + width / 2., y - height, z); //glVertex3f(v3.x, v3.y, v3.z); //glVertex3f(50,50, 0);
|
||||
glTexCoord2f(u + w, v + h); glVertex3f(x + width / 2., y, z); //glVertex3f(v2.x, v2.y, v2.z); //glVertex3f(50, 0, 0);
|
||||
glTexCoord2f(u, v + h); glVertex3f(x - width / 2., y, z); //glVertex3f(v1.x, v1.y, v1.z);// glVertex3f(0, 0, 0);
|
||||
glEnd();
|
||||
shader.Disable();
|
||||
//tran.ApplyTranslation(-m_position);
|
||||
//glEnable(GL_DEPTH_TEST);
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
#ifndef BOOSTER_H__
|
||||
#define BOOSTER_H__
|
||||
#include "define.h"
|
||||
#include "textureatlas.h"
|
||||
#include "shader.h"
|
||||
#include "../SQCSim-common/vector3.h"
|
||||
#include "../SQCSim-common/transformation.h"
|
||||
|
||||
|
||||
class Booster {
|
||||
public:
|
||||
void RenderBillboard(const Vector3f pos, TextureAtlas& textureAtlas, Shader& shader, Transformation tran);
|
||||
};
|
||||
#endif
|
@ -78,7 +78,6 @@ void Engine::LoadResource() {
|
||||
std::cerr << " ERREUR GLEW : " << glewGetErrorString(glewErr) << std::endl;
|
||||
abort();
|
||||
}
|
||||
|
||||
LoadTexture(m_skybox.GetTexture(), TEXTURE_PATH "skybox.png", true);
|
||||
LoadTexture(m_textureCrosshair, TEXTURE_PATH "cross.bmp", true);
|
||||
LoadTexture(m_textureFont, TEXTURE_PATH "font.bmp", true);
|
||||
@ -124,15 +123,15 @@ void Engine::LoadResource() {
|
||||
LoadTexture(m_textureMenuQuit, TEXTURE_PATH "menus/buttons/main/mainQuit.png", false);
|
||||
LoadTexture(m_textureMenuSingle, TEXTURE_PATH "menus/buttons/main/mainSingle.png", false);
|
||||
|
||||
TextureAtlas::TextureIndex texDirtIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal2.png");
|
||||
TextureAtlas::TextureIndex texIceIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal3.png");
|
||||
TextureAtlas::TextureIndex texGrassIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "grass.png");
|
||||
TextureAtlas::TextureIndex texMetalIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "dirt.png");
|
||||
TextureAtlas::TextureIndex texGreenGrassIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "greengrass.png");
|
||||
TextureAtlas::TextureIndex texBoostHeal = m_textureAtlas.AddTexture(BOOSTER_TEXTURE_PATH "BoosterVert.png");
|
||||
TextureAtlas::TextureIndex texBoostDmg = m_textureAtlas.AddTexture(BOOSTER_TEXTURE_PATH "BoosterRouge.png");
|
||||
TextureAtlas::TextureIndex texBoostSpd = m_textureAtlas.AddTexture(BOOSTER_TEXTURE_PATH "BoosterBleu.png");
|
||||
TextureAtlas::TextureIndex texBoostInv = m_textureAtlas.AddTexture(BOOSTER_TEXTURE_PATH "BoosterJaune.png");
|
||||
TextureAtlas::TextureIndex texDirtIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal2.png"); //0
|
||||
TextureAtlas::TextureIndex texIceIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal3.png"); //1
|
||||
TextureAtlas::TextureIndex texGrassIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "grass.png"); //2
|
||||
TextureAtlas::TextureIndex texMetalIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "dirt.png"); //3
|
||||
TextureAtlas::TextureIndex texGreenGrassIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "greengrass.png"); //4
|
||||
TextureAtlas::TextureIndex texBoostHeal = m_textureAtlas.AddTexture(BOOSTER_TEXTURE_PATH "BoosterVert.png"); //5
|
||||
TextureAtlas::TextureIndex texBoostDmg = m_textureAtlas.AddTexture(BOOSTER_TEXTURE_PATH "BoosterRouge.png"); //6
|
||||
TextureAtlas::TextureIndex texBoostSpd = m_textureAtlas.AddTexture(BOOSTER_TEXTURE_PATH "BoosterBleu.png"); //7
|
||||
TextureAtlas::TextureIndex texBoostInv = m_textureAtlas.AddTexture(BOOSTER_TEXTURE_PATH "BoosterJaune.png"); //8
|
||||
|
||||
//AJOUTER LES TEXTURES DANS L'ORDRE DE L'ÉNUM
|
||||
|
||||
@ -620,8 +619,8 @@ bool Engine::StartMultiplayerGame() {
|
||||
for (auto& [key, player] : m_conn.m_players)
|
||||
m_players[key] = new RemotePlayer(&player);
|
||||
|
||||
//m_world.SetSeed(m_conn.getSeed());
|
||||
m_world.SetSeed(9370707);
|
||||
m_world.SetSeed(m_conn.getSeed());
|
||||
//m_world.SetSeed(9370707);
|
||||
m_networkgame = true;
|
||||
m_player.m_username = m_username;
|
||||
}
|
||||
@ -685,11 +684,6 @@ void Engine::DisplayInfo(float elapsedTime, BlockType bloc) {
|
||||
ss.str("");
|
||||
fPosY -= charSize;
|
||||
|
||||
//ss << " Block : ";
|
||||
//if (bloc == BTYPE_LAST)
|
||||
// ss << "Weapon";
|
||||
//else
|
||||
// ss << (int)bloc;
|
||||
PrintText(fPosX, fPosYJump, ss.str());
|
||||
}
|
||||
|
||||
@ -1367,6 +1361,9 @@ void Engine::Render(float elapsedTime) {
|
||||
// son vecteur de velocite (pour l'effet Doppler)
|
||||
pollTime = 0;
|
||||
}
|
||||
uint64_t boostid = m_player.TakeBooster(m_boosters, elapsedTime);
|
||||
|
||||
m_boost_manifest.insert(boostid);
|
||||
|
||||
m_player.ApplyTransformation(all);
|
||||
|
||||
@ -1412,25 +1409,16 @@ void Engine::Render(float elapsedTime) {
|
||||
m_chunkmod = nullptr;
|
||||
}
|
||||
m_bullets[x] = nullptr;
|
||||
/*if (m_whoosh[x]){
|
||||
m_whoosh[x]->drop();
|
||||
m_whoosh[x] = nullptr;
|
||||
}*/
|
||||
break;
|
||||
}
|
||||
/*else if (!m_whoosh[x]) {
|
||||
m_whoosh[x] = m_audio.Create3DAudioObj(m_whoosh[x], AUDIO_PATH "noise.wav", m_bullets[x]->getPos(), m_bullets[x]->getVel(), true, (m_bullets[x]->getPos() - m_player.GetPosition()).Length());
|
||||
}
|
||||
else {
|
||||
Vector3f pos = m_bullets[x]->getPos(), vel = m_bullets[x]->getVel();
|
||||
m_audio.Render3DAudioObj(m_whoosh[x], pos, vel, m_sfxvolume);
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_world.Update(m_bullets, m_player.GetPosition(), m_blockinfo);
|
||||
m_renderer.UpdateMesh(&m_world, m_player.GetPosition(), m_blockinfo);
|
||||
|
||||
if (m_isSkybox) m_renderer.RenderWorld(&m_world, m_renderCount, m_player.GetPosition(), m_player.GetDirection(), all, m_shader01, m_textureAtlas);
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
m_renderer.RenderWorld(&m_world, m_renderCount, m_player.GetPosition(), m_player.GetDirection(), all, m_shader01, m_textureAtlas);
|
||||
glEnable(GL_BLEND);
|
||||
@ -1450,10 +1438,6 @@ void Engine::Render(float elapsedTime) {
|
||||
m_player.m_username = user;
|
||||
m_player.InflictDamage(-m_player.GetHP());
|
||||
}
|
||||
/*if (m_player.GetPosition().y < -21.f || died) {
|
||||
died = false;
|
||||
|
||||
}*/
|
||||
|
||||
m_time += elapsedTime;
|
||||
|
||||
@ -1520,13 +1504,48 @@ void Engine::Render(float elapsedTime) {
|
||||
char* prevptr = nullptr;
|
||||
Chat chat;
|
||||
for (auto& pck : lsPck) { // We could make a few threads out of this.
|
||||
Sync sync; Output out; ChunkMod cmod; BulletAdd bull;
|
||||
Sync sync; Output out; ChunkMod cmod; BulletAdd bull; PickupMod pmod;
|
||||
if (!prevptr)
|
||||
prevptr = m_buf.ptr;
|
||||
uint32_t bsize = m_buf.len - (pck - prevptr);
|
||||
prevptr = pck;
|
||||
switch (getType(pck, 1)) {
|
||||
using enum PACKET_TYPE;
|
||||
case PICKUPMOD:
|
||||
if (Deserialize(&pmod, pck, &bsize)) {
|
||||
if (m_boosters.count(pmod.id)) {
|
||||
Booster* boost = m_boosters.at(pmod.id);
|
||||
if (m_boost_manifest.count(boost->GetId())) {
|
||||
std::string str = "Picked up ";
|
||||
if (pmod.boost.damage)
|
||||
str.append("Damage Booster");
|
||||
else if (pmod.boost.hp)
|
||||
str.append("Healing");
|
||||
else if (pmod.boost.invincible)
|
||||
str.append("Invincibility");
|
||||
else break;
|
||||
SystemNotification(str);
|
||||
}
|
||||
boost->SetAvailability(pmod.available);
|
||||
}
|
||||
else {
|
||||
BOOST_TYPE btype;
|
||||
if (pmod.boost.damage)
|
||||
btype = BOOST_TYPE::BTYPE_DAMAGE;
|
||||
else if (pmod.boost.hp)
|
||||
btype = BOOST_TYPE::BTYPE_HEAL;
|
||||
else if (pmod.boost.invincible)
|
||||
btype = BOOST_TYPE::BTYPE_INVINCIBLE;
|
||||
else break;
|
||||
|
||||
Booster* boost = new Booster(pmod.pos, btype, pmod.id);
|
||||
|
||||
boost->SetAvailability(pmod.available);
|
||||
|
||||
m_boosters[pmod.id] = boost;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SYNC:
|
||||
if (Deserialize(&sync, pck, &bsize)) {
|
||||
if (sync.sid != m_conn.getId()) {
|
||||
@ -1547,6 +1566,15 @@ void Engine::Render(float elapsedTime) {
|
||||
if (diff.y < 1.)
|
||||
diff.y = 0;
|
||||
|
||||
Boosts boost = sync.boost;
|
||||
|
||||
m_player.boostdamage = boost.damage;
|
||||
m_player.boostinvincible = boost.invincible;
|
||||
|
||||
if (diff.Length() > 10.) {
|
||||
m_player.Move(-diff);
|
||||
}
|
||||
|
||||
if (diff.Length() > 1.5) {
|
||||
diff.Normalize();
|
||||
m_player.Move(-diff);
|
||||
@ -1620,6 +1648,12 @@ void Engine::Render(float elapsedTime) {
|
||||
glClear(GL_STENCIL_BUFFER_BIT);
|
||||
rt->Render(m_animeAtlas, m_shader01, all, elapsedTime, m_player);
|
||||
}
|
||||
for (auto& [key, booster] : m_boosters) {
|
||||
if (booster->GetAvailability()) {
|
||||
glClear(GL_STENCIL_BUFFER_BIT);
|
||||
m_renderer.RenderBooster(m_textureAtlas, m_shader01, all, m_player, booster);
|
||||
}
|
||||
}
|
||||
glEnable(GL_CULL_FACE);
|
||||
}
|
||||
else {
|
||||
@ -1880,8 +1914,7 @@ void Engine::KeyReleaseEvent(unsigned char key) {
|
||||
m_keyS = false;
|
||||
break;
|
||||
case 19: // T -Reset countdown
|
||||
m_resetcountdown = true;
|
||||
std::cout << "RESET COUNTDOWN" << std::endl;
|
||||
m_player.Put(m_otherplayerpos);
|
||||
break;
|
||||
case 22: // W - Stop avancer
|
||||
m_keyW = false;
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "../SQCSim-common/world.h"
|
||||
#include "../SQCSim-common/transformation.h"
|
||||
#include "../SQCSim-common/player.h"
|
||||
#include "../SQCSim-common/booster.h"
|
||||
#include "define.h"
|
||||
#include "openglcontext.h"
|
||||
#include "texture.h"
|
||||
@ -24,13 +25,15 @@
|
||||
#include "connector.h"
|
||||
#include "renderer.h"
|
||||
#include "remoteplayer.h"
|
||||
#include "booster.h"
|
||||
#include "settings.h"
|
||||
|
||||
class Engine : public OpenglContext {
|
||||
public:
|
||||
Engine();
|
||||
virtual ~Engine();
|
||||
|
||||
|
||||
|
||||
virtual void Init();
|
||||
virtual void DeInit();
|
||||
virtual void LoadResource();
|
||||
@ -39,8 +42,8 @@ public:
|
||||
virtual void KeyPressEvent(unsigned char key);
|
||||
virtual void KeyReleaseEvent(unsigned char key);
|
||||
virtual void MouseMoveEvent(int x, int y);
|
||||
virtual void MousePressEvent(const MOUSE_BUTTON &button, int x, int y);
|
||||
virtual void MouseReleaseEvent(const MOUSE_BUTTON &button, int x, int y);
|
||||
virtual void MousePressEvent(const MOUSE_BUTTON& button, int x, int y);
|
||||
virtual void MouseReleaseEvent(const MOUSE_BUTTON& button, int x, int y);
|
||||
|
||||
private:
|
||||
int GetFps(float elapsedTime) const;
|
||||
@ -56,6 +59,7 @@ private:
|
||||
void KillNotification(Player killer, Player killed);
|
||||
|
||||
void DisplayNotification(std::string message);
|
||||
|
||||
void DisplayCrosshair();
|
||||
void DisplayPovGun();
|
||||
void DisplayCurrentItem();
|
||||
@ -103,10 +107,8 @@ private:
|
||||
|
||||
Renderer m_renderer = Renderer();
|
||||
|
||||
Booster m_booster = Booster();
|
||||
BlockInfo* m_blockinfo[BTYPE_LAST];
|
||||
BoostInfo* m_boostinfo[BTYPE_BOOST_LAST];
|
||||
|
||||
GameState m_gamestate = GameState::SPLASH;
|
||||
|
||||
Shader m_shader01;
|
||||
@ -169,9 +171,12 @@ private:
|
||||
float m_splashTime = 2.0f;
|
||||
float m_scale;
|
||||
float m_time = 0;
|
||||
|
||||
float m_titleX = 0;
|
||||
float m_titleY = 0;
|
||||
|
||||
|
||||
|
||||
int m_renderCount = 0;
|
||||
int m_countdown = COUNTDOWN;
|
||||
int m_nbReductionChunk = 4;
|
||||
@ -186,7 +191,7 @@ private:
|
||||
|
||||
bool m_selectedOptAudioMainBar = false;
|
||||
bool m_selectedOptAudioMusicBar = false;
|
||||
bool m_selectedOptAudioSfxBar = false;
|
||||
bool m_selectedOptAudioSfxBar = false;
|
||||
bool m_selectedGameplaySensitivityBar = false;
|
||||
|
||||
bool m_damage = false;
|
||||
@ -223,6 +228,7 @@ private:
|
||||
|
||||
bool m_key1 = false;
|
||||
bool m_key2 = false;
|
||||
|
||||
bool m_keyK = false;
|
||||
bool m_keyL = false;
|
||||
bool m_keyW = false;
|
||||
@ -252,6 +258,8 @@ private:
|
||||
std::set<uint64_t> m_deadplayers;
|
||||
netprot::Buffer m_buf, m_bufout;
|
||||
netprot::ChunkMod* m_chunkmod = nullptr;
|
||||
std::unordered_map<uint64_t, Booster*> m_boosters;
|
||||
std::set<uint64_t> m_boost_manifest;
|
||||
|
||||
std::unordered_map<uint64_t, netprot::Sync> m_syncs;
|
||||
std::string m_messageNotification = "";
|
||||
|
@ -120,7 +120,7 @@ void Renderer::RenderWorld(World* origin, int& rendercount, const Vector3f& play
|
||||
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
|
||||
|
||||
unsigned int sx, sy, cx, cy;
|
||||
origin->GetScope(sx,sy);
|
||||
origin->GetScope(sx, sy);
|
||||
|
||||
for (int index = 0; index < rendercount; ++index) {
|
||||
int chx = (renderManifest[index].x - sx) * CHUNK_SIZE_X, chy = (renderManifest[index].z - sy) * CHUNK_SIZE_Z;
|
||||
@ -129,9 +129,9 @@ void Renderer::RenderWorld(World* origin, int& rendercount, const Vector3f& play
|
||||
glLoadMatrixf(world.GetMatrix().GetInternalValues());
|
||||
float blcolor = renderManifest[index].y / (VIEW_DISTANCE / 50.f);
|
||||
glBlendColor(blcolor, blcolor, blcolor, 1.f);
|
||||
origin->ChunkAt(chx, 1, chy)->GetPosition(cx,cy);
|
||||
origin->ChunkAt(chx, 1, chy)->GetPosition(cx, cy);
|
||||
if (m_meshes.Get(cx - sx, cy - sy))
|
||||
m_meshes.Get(cx - sx, cy -sy)->Render();
|
||||
m_meshes.Get(cx - sx, cy - sy)->Render();
|
||||
world.ApplyTranslation(-chx, 0, -chy);
|
||||
}
|
||||
shader.Disable();
|
||||
@ -147,7 +147,7 @@ void Renderer::UpdateMesh(World* origin, const Vector3f& player, BlockInfo* bloc
|
||||
int threads = 0;
|
||||
std::future<Mesh*> updateThList[THREADS_UPDATE_CHUNKS];
|
||||
|
||||
unsigned int mx = 0 , my = 0, sx, sy;
|
||||
unsigned int mx = 0, my = 0, sx, sy;
|
||||
|
||||
origin->GetScope(sx, sy);
|
||||
|
||||
@ -244,31 +244,73 @@ void Renderer::UpdateMesh(World* origin, const Vector3f& player, BlockInfo* bloc
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer::RenderBillboard(const Vector3f pos, TextureAtlas textureAtlas, TextureAtlas::TextureIndex idx, Shader& shader, Transformation tran)
|
||||
{
|
||||
//float x = pos.x;
|
||||
//float y = pos.y;
|
||||
//float z = pos.z;
|
||||
//float width = 1.0f;
|
||||
//float height = 1.0f;
|
||||
void Renderer::RenderBooster(TextureAtlas& textureAtlas, Shader& shader, Transformation tran, Player player, Booster* booster) {
|
||||
float width = 1.f;
|
||||
float height = 1.f;
|
||||
|
||||
//float u, v, w, h;
|
||||
//shader.Use();
|
||||
//textureAtlas.Bind();
|
||||
//textureAtlas.TextureIndexToCoord(idx, u, v, w, h);
|
||||
Vector3f DiffCam = booster->GetPosition() - player.GetPosition();
|
||||
Vector3f UpCam = Vector3f(0.f, 1.f, 0.f);
|
||||
|
||||
//glLoadMatrixf(tran.GetMatrix().GetInternalValues());
|
||||
//glBegin(GL_QUADS);
|
||||
//glTexCoord2f(u, v); glVertex3f(x - width / 2., y - height, z); //glVertex3f(v4.x, v4.y, v4.z);//glVertex3f(0, 50, 0);
|
||||
//glTexCoord2f(u + w, v); glVertex3f(x + width / 2., y - height, z); //glVertex3f(v3.x, v3.y, v3.z); //glVertex3f(50,50, 0);
|
||||
//glTexCoord2f(u + w, v + h); glVertex3f(x + width / 2., y, z); //glVertex3f(v2.x, v2.y, v2.z); //glVertex3f(50, 0, 0);
|
||||
//glTexCoord2f(u, v + h); glVertex3f(x - width / 2., y, z); //glVertex3f(v1.x, v1.y, v1.z);// glVertex3f(0, 0, 0);
|
||||
//glEnd();
|
||||
//shader.Disable();
|
||||
Vector3f CrossA = DiffCam.Cross(UpCam);
|
||||
Vector3f CrossB = DiffCam.Cross(CrossA);
|
||||
|
||||
CrossA.Normalize();
|
||||
CrossB.Normalize();
|
||||
|
||||
Vector3f playerPosition = booster->GetPosition() + Vector3f(0.f, -.75f, 0.f);
|
||||
|
||||
Vector3f v2 = (playerPosition + CrossA * 0.5 * width + CrossB * 0.5 * height);
|
||||
Vector3f v1 = (playerPosition - CrossA * 0.5 * width + CrossB * 0.5 * height);
|
||||
Vector3f v3 = (playerPosition + CrossA * 0.5 * width - CrossB * 0.5 * height);
|
||||
Vector3f v4 = (playerPosition - CrossA * 0.5 * width - CrossB * 0.5 * height);
|
||||
|
||||
int index;
|
||||
BOOST_TYPE type = booster->GetType();
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case BTYPE_HEAL:
|
||||
index = 5;
|
||||
break;
|
||||
case BTYPE_DAMAGE:
|
||||
index = 6;
|
||||
break;
|
||||
case BTYPE_SPEED:
|
||||
index = 7;
|
||||
break;
|
||||
case BTYPE_INVINCIBLE:
|
||||
index = 8;
|
||||
break;
|
||||
default:
|
||||
index = 1;
|
||||
break;
|
||||
}
|
||||
float u, v, w, h;
|
||||
|
||||
shader.Use();
|
||||
textureAtlas.Bind();
|
||||
textureAtlas.TextureIndexToCoord(index, u, v, w, h);
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glBlendEquation(GL_FUNC_ADD);
|
||||
|
||||
glLoadMatrixf(tran.GetMatrix().GetInternalValues());
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(u, v); glVertex3f(v1.x, v1.y, v1.z);
|
||||
glTexCoord2f(u + w, v); glVertex3f(v2.x, v2.y, v2.z);
|
||||
glTexCoord2f(u + w, v + h); glVertex3f(v3.x, v3.y, v3.z);
|
||||
glTexCoord2f(u, v + h); glVertex3f(v4.x, v4.y, v4.z);
|
||||
|
||||
glEnd();
|
||||
|
||||
glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR);
|
||||
glBlendEquation(GL_FUNC_SUBTRACT);
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
shader.Disable();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Renderer::RenderPlayer(Player* player, Transformation tran) const {
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ public:
|
||||
|
||||
void UpdateMesh(World* origin, const Vector3f& player, BlockInfo* blockinfo[BTYPE_LAST]);
|
||||
|
||||
void RenderBillboard(const Vector3f pos, TextureAtlas textureAtlas, TextureAtlas::TextureIndex idx, Shader& shader, Transformation tran);
|
||||
void RenderBooster(TextureAtlas& textureAtlas, Shader& shader, Transformation tran, Player player, Booster* booster);
|
||||
|
||||
void RenderWorld(World* origin, int& rendercount, const Vector3f& player_pos, const Vector3f& player_dir, Transformation world, Shader& shader, TextureAtlas& atlas) const;
|
||||
void RenderPlayer(Player* player, Transformation tran) const;
|
||||
|
Loading…
Reference in New Issue
Block a user