oooooooooo

This commit is contained in:
MarcEricMartel 2023-12-18 14:24:43 -05:00
parent f1bb7447f9
commit 25b5c1e492
5 changed files with 23 additions and 18 deletions

View File

@ -199,11 +199,11 @@ void Player::ApplyTransformation(Transformation& transformation, bool rel, bool
void Player::TakeBooster(std::unordered_map<uint64_t, Booster*> booster_table, float elapsedtime)
{
Vector3f playerpos = GetPosition();
for (auto& [key, booster]: booster_table)
{
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)
{
std::cout << "booster got" << std::endl;
GetBooster(booster->GetType(), elapsedtime);
booster->SetAvailability(false);
break;

View File

@ -241,12 +241,12 @@ void Server::Run() {
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) {
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 > 1000)
if (++max > 100000)
break;
}
@ -390,6 +390,7 @@ void Server::Run() {
}
}
int max = 0;
for (auto& [key, booster] : m_boosters) {
if (booster->modified) {
PickupMod pmod;
@ -414,6 +415,9 @@ void Server::Run() {
booster->modified = false;
for (auto& [key, conn] : m_conns)
sendPackTo<PickupMod>(m_sock_udp, &pmod, &m_buf, conn->getAddr());
max++;
if (max > 5)
break;
}
}

View File

@ -1511,7 +1511,7 @@ void Engine::Render(float elapsedTime) {
if (Deserialize(&pmod, pck, &bsize)) {
if (m_boosters.count(pmod.id)) {
Booster* boost = m_boosters.at(pmod.id);
std::cout << "Ramassé booster selon serveur " << (pmod.boost.damage ? "damage" : "") << (pmod.boost.hp ? "heal" : "") << (pmod.boost.invincible ? "invincible" : "");
boost->SetAvailability(pmod.available);
}
else {
@ -1522,6 +1522,7 @@ void Engine::Render(float elapsedTime) {
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);
@ -1556,6 +1557,10 @@ void Engine::Render(float elapsedTime) {
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);
@ -1630,8 +1635,10 @@ void Engine::Render(float elapsedTime) {
rt->Render(m_animeAtlas, m_shader01, all, elapsedTime, m_player);
}
for (auto& [key, booster] : m_boosters) {
if (booster->GetAvailability())
m_renderer.RenderBooster(m_textureAtlas, m_shader01, all, m_player, *booster);
if (booster->GetAvailability()) {
glClear(GL_STENCIL_BUFFER_BIT);
m_renderer.RenderBooster(m_textureAtlas, m_shader01, all, m_player, booster);
}
}
glEnable(GL_CULL_FACE);
}

View File

@ -244,14 +244,11 @@ void Renderer::UpdateMesh(World* origin, const Vector3f& player, BlockInfo* bloc
}
}
void Renderer::RenderBooster(TextureAtlas& textureAtlas, Shader& shader, Transformation tran, Player player, Booster booster)
{
if (booster.GetAvailability() == true)
{
void Renderer::RenderBooster(TextureAtlas& textureAtlas, Shader& shader, Transformation tran, Player player, Booster* booster) {
float width = 1.f;
float height = 1.f;
Vector3f DiffCam = booster.GetPosition() - player.GetPosition();
Vector3f DiffCam = booster->GetPosition() - player.GetPosition();
Vector3f UpCam = Vector3f(0.f, 1.f, 0.f);
Vector3f CrossA = DiffCam.Cross(UpCam);
@ -260,7 +257,7 @@ void Renderer::RenderBooster(TextureAtlas& textureAtlas, Shader& shader, Transfo
CrossA.Normalize();
CrossB.Normalize();
Vector3f playerPosition = booster.GetPosition() + Vector3f(0.f, -.75f, 0.f);
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);
@ -268,7 +265,7 @@ void Renderer::RenderBooster(TextureAtlas& textureAtlas, Shader& shader, Transfo
Vector3f v4 = (playerPosition - CrossA * 0.5 * width - CrossB * 0.5 * height);
int index;
BOOST_TYPE type = booster.GetType();
BOOST_TYPE type = booster->GetType();
switch (type)
{
@ -312,11 +309,8 @@ void Renderer::RenderBooster(TextureAtlas& textureAtlas, Shader& shader, Transfo
glDisable(GL_BLEND);
shader.Disable();
}
}
void Renderer::RenderPlayer(Player* player, Transformation tran) const {
}

View File

@ -29,7 +29,7 @@ public:
void UpdateMesh(World* origin, const Vector3f& player, BlockInfo* blockinfo[BTYPE_LAST]);
void RenderBooster(TextureAtlas& textureAtlas, Shader& shader, Transformation tran, Player player, Booster booster);
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;