Compare commits
24 Commits
main
...
6ab9126cd7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6ab9126cd7 | ||
| 0f0d2cb5e0 | |||
| d5c52e8626 | |||
|
|
e16cea7214 | ||
| 42a37abe45 | |||
| fdc0d69605 | |||
| c115602419 | |||
| 4590672b36 | |||
| f79c65a563 | |||
| da76ae3d33 | |||
| ad389aa576 | |||
|
|
bd517c6cfe | ||
|
|
63c33e4bc5 | ||
| bea98cbe45 | |||
| bc84906b56 | |||
|
|
292fac185d | ||
|
|
b2ecc690c2 | ||
|
|
80dbd73bfb | ||
| 4399787209 | |||
| 25fe2eb6d5 | |||
|
|
9c5e788ee0 | ||
|
|
f28eb338d7 | ||
|
|
fdd0b185ac | ||
| 49ca6043bf |
@@ -25,10 +25,10 @@ class Player {
|
||||
float m_Pitch;
|
||||
float m_HP;
|
||||
bool m_IsBot;
|
||||
PlayerStats m_Stats{};
|
||||
|
||||
public:
|
||||
Player(PlayerID id) : m_ID(id), m_Yaw(0), m_Pitch(0), m_IsBot(false) {}
|
||||
Player(PlayerID id) : m_ID(id), m_Yaw(0), m_Pitch(0), m_HP(100), m_IsBot(false) {}
|
||||
PlayerStats m_Stats{};
|
||||
|
||||
PlayerID GetID() const {
|
||||
return m_ID;
|
||||
@@ -105,6 +105,10 @@ class Player {
|
||||
PlayerStats& GetStats() {
|
||||
return m_Stats;
|
||||
}
|
||||
|
||||
void SetStats(const PlayerStats& stats) {
|
||||
m_Stats = stats;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ class PacketHandler {
|
||||
virtual void HandlePacket(const PlayerLoginPacket* packet) {}
|
||||
virtual void HandlePacket(const PlayerPositionAndRotationPacket* packet) {}
|
||||
virtual void HandlePacket(const PlayerShootPacket* packet) {}
|
||||
virtual void HandlePacket(const PlayerStatsPacket* packet) {}
|
||||
virtual void HandlePacket(const ServerTpsPacket* packet) {}
|
||||
virtual void HandlePacket(const UpdateHealthPacket* packet) {}
|
||||
};
|
||||
|
||||
@@ -8,5 +8,6 @@
|
||||
#include "packets/PlayerLoginPacket.h"
|
||||
#include "packets/PlayerPositionAndRotationPacket.h"
|
||||
#include "packets/PlayerShootPacket.h"
|
||||
#include "packets/PlayerStatsPacket.h"
|
||||
#include "packets/ServerTpsPacket.h"
|
||||
#include "packets/UpdateHealthPacket.h"
|
||||
#include "packets/UpdateHealthPacket.h"
|
||||
|
||||
@@ -13,6 +13,7 @@ class PlayerListPacket;
|
||||
class PlayerLoginPacket;
|
||||
class PlayerPositionAndRotationPacket;
|
||||
class PlayerShootPacket;
|
||||
class PlayerStatsPacket;
|
||||
class ServerTpsPacket;
|
||||
class UpdateHealthPacket;
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ enum class PacketType : std::uint8_t {
|
||||
PlayerJoin, /**< Corresponds to PlayerJoinPacket */
|
||||
PlayerLeave, /**< Corresponds to PlayerLeavePacket */
|
||||
PlayerList, /**< Corresponds to PlayerListPacket */
|
||||
PlayerStats, /**< Corresponds to PlayerStatsPacket */
|
||||
ServerTps, /**< Corresponds to ServerTpsPacket */
|
||||
|
||||
// client <--> server
|
||||
|
||||
46
include/blitz/protocol/packets/PlayerStatsPacket.h
Normal file
46
include/blitz/protocol/packets/PlayerStatsPacket.h
Normal file
@@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
|
||||
#include "blitz/common/Defines.h"
|
||||
#include "blitz/game/Player.h"
|
||||
#include "blitz/protocol/Protocol.h"
|
||||
|
||||
namespace blitz {
|
||||
namespace protocol {
|
||||
|
||||
class PlayerStatsPacket : public Packet {
|
||||
private:
|
||||
game::PlayerID m_PlayerID;
|
||||
game::PlayerStats m_PlayerStats;
|
||||
|
||||
public:
|
||||
PlayerStatsPacket() {}
|
||||
PlayerStatsPacket(game::PlayerID playerID, const game::PlayerStats& stats) : m_PlayerID(playerID), m_PlayerStats(stats) {}
|
||||
virtual ~PlayerStatsPacket() {}
|
||||
|
||||
virtual DataBuffer Serialize(bool packetID = true) const;
|
||||
virtual void Deserialize(DataBuffer& data);
|
||||
virtual void Dispatch(PacketHandler* handler) const;
|
||||
|
||||
/**
|
||||
* \brief Getter of the player id
|
||||
* \return The ID of the player
|
||||
*/
|
||||
game::PlayerID GetPlayerID() const {
|
||||
return m_PlayerID;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Getter of the player stats
|
||||
* \return The stats of the player
|
||||
*/
|
||||
const game::PlayerStats& GetPlayerStats() const {
|
||||
return m_PlayerStats;
|
||||
}
|
||||
|
||||
virtual PacketType GetType() const {
|
||||
return PacketType::PlayerStats;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace protocol
|
||||
} // namespace blitz
|
||||
@@ -22,6 +22,7 @@ class BlitzConfig {
|
||||
bool m_DisplayFps;
|
||||
KeyAction m_CurrentAction;
|
||||
Keybinds m_Keybinds{};
|
||||
float m_MouseSpeed;
|
||||
|
||||
|
||||
public:
|
||||
@@ -52,6 +53,14 @@ class BlitzConfig {
|
||||
return m_Keybinds;
|
||||
}
|
||||
|
||||
float GetMouseSpeed() {
|
||||
return m_MouseSpeed;
|
||||
}
|
||||
|
||||
void SetMouseSpeed(float MouseSpeed) {
|
||||
m_MouseSpeed = MouseSpeed;
|
||||
}
|
||||
|
||||
private:
|
||||
void LoadConfig();
|
||||
void LoadDefaultConfig();
|
||||
|
||||
@@ -25,6 +25,7 @@ class ClientGame : public game::Game, public protocol::PacketHandler {
|
||||
virtual void HandlePacket(const protocol::PlayerPositionAndRotationPacket* packet) override;
|
||||
virtual void HandlePacket(const protocol::PlayerShootPacket* packet) override;
|
||||
virtual void HandlePacket(const protocol::UpdateHealthPacket* packet) override;
|
||||
virtual void HandlePacket(const protocol::PlayerStatsPacket* packet) override;
|
||||
|
||||
private:
|
||||
void RegisterHandlers();
|
||||
|
||||
21
include/client/gui/LeaderBoard.h
Normal file
21
include/client/gui/LeaderBoard.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include "GuiWidget.h"
|
||||
#include "client/Client.h"
|
||||
|
||||
namespace blitz {
|
||||
|
||||
namespace gui {
|
||||
class LeaderBoard : public GuiWidget {
|
||||
private:
|
||||
void Draw(const char* title, bool* p_open);
|
||||
|
||||
public:
|
||||
LeaderBoard(GuiWidget* parent, Client* client);
|
||||
~LeaderBoard();
|
||||
|
||||
virtual void Render() override;
|
||||
};
|
||||
|
||||
} // namespace gui
|
||||
} // namespace blitz
|
||||
@@ -28,6 +28,7 @@ class ServerGame : public game::Game {
|
||||
void SendPlayerPositions();
|
||||
void DamagePlayer(game::Player& player, game::Player& shooter);
|
||||
void UpdateHP(game::Player& player, float newHP);
|
||||
void UpdatePlayerStats();
|
||||
};
|
||||
|
||||
} // namespace server
|
||||
|
||||
@@ -19,6 +19,7 @@ static std::array<PacketPtr, static_cast<std::size_t>(PacketType::PACKET_COUNT)>
|
||||
std::make_unique<PlayerJoinPacket>(),
|
||||
std::make_unique<PlayerLeavePacket>(),
|
||||
std::make_unique<PlayerListPacket>(),
|
||||
std::make_unique<PlayerStatsPacket>(),
|
||||
std::make_unique<ServerTpsPacket>(),
|
||||
std::make_unique<KeepAlivePacket>(),
|
||||
std::make_unique<DisconnectPacket>(),
|
||||
|
||||
@@ -26,6 +26,7 @@ REGISTER_DISPATCH_CLASS(ChatPacket)
|
||||
REGISTER_DISPATCH_CLASS(PlayerPositionAndRotationPacket)
|
||||
REGISTER_DISPATCH_CLASS(PlayerShootPacket);
|
||||
REGISTER_DISPATCH_CLASS(UpdateHealthPacket);
|
||||
REGISTER_DISPATCH_CLASS(PlayerStatsPacket);
|
||||
|
||||
} // namespace protocol
|
||||
} // namespace blitz
|
||||
|
||||
19
src/blitz/protocol/packets/PlayerStatsPacket.cpp
Normal file
19
src/blitz/protocol/packets/PlayerStatsPacket.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#include "blitz/protocol/packets/PlayerStatsPacket.h"
|
||||
|
||||
namespace blitz {
|
||||
namespace protocol {
|
||||
|
||||
DataBuffer PlayerStatsPacket::Serialize(bool packetID) const {
|
||||
DataBuffer data;
|
||||
|
||||
WritePacketID(data, packetID);
|
||||
data << m_PlayerID << m_PlayerStats;
|
||||
return data;
|
||||
}
|
||||
|
||||
void PlayerStatsPacket::Deserialize(DataBuffer& data) {
|
||||
data >> m_PlayerID >> m_PlayerStats;
|
||||
}
|
||||
|
||||
} // namespace protocol
|
||||
} // namespace blitz
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "client/config/BlitzConfig.h"
|
||||
|
||||
#include "blitz/misc/Log.h"
|
||||
#include "client/display/PlayerController.h"
|
||||
#include "imgui.h"
|
||||
#include <fstream>
|
||||
#include <nlohmann/json.hpp>
|
||||
@@ -37,6 +38,7 @@ void BlitzConfig::LoadConfig() {
|
||||
std::memcpy(m_Pseudo.data(), pseudo.data(), pseudo.size() + 1);
|
||||
jsonInput.at("vsync").get_to<bool>(m_VSync);
|
||||
jsonInput.at("fps").get_to<bool>(m_DisplayFps);
|
||||
jsonInput.at("sensitivity").get_to<float>(m_MouseSpeed);
|
||||
jsonInput.at("keys").get_to<Keybinds>(m_Keybinds);
|
||||
|
||||
utils::LOG("[BlitzConfig] Restored config !");
|
||||
@@ -50,6 +52,7 @@ void BlitzConfig::LoadDefaultConfig() {
|
||||
m_VSync = true;
|
||||
const char defaultPseudo[] = "Pseudo";
|
||||
std::memcpy(m_Pseudo.data(), defaultPseudo, sizeof(defaultPseudo));
|
||||
m_MouseSpeed = 0.0025f;
|
||||
m_Keybinds = {ImGuiKey_Z, ImGuiKey_S, ImGuiKey_D, ImGuiKey_Q};
|
||||
}
|
||||
|
||||
@@ -64,6 +67,7 @@ void BlitzConfig::SaveConfig() {
|
||||
{"pseudo", GetPseudo().data()},
|
||||
{"vsync", IsVSyncEnabled()},
|
||||
{"fps", IsFPSDisplayEnabled()},
|
||||
{"sensitivity", GetMouseSpeed()},
|
||||
{"keys", GetKeys()},
|
||||
};
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "blitz/maths/Maths.h"
|
||||
#include "blitz/misc/Log.h"
|
||||
#include "client/Client.h"
|
||||
#include "client/config/BlitzConfig.h"
|
||||
#include "client/display/InputManager.h"
|
||||
#include "imgui.h"
|
||||
#include <algorithm>
|
||||
@@ -42,7 +43,7 @@ void PlayerController::MouseMotionEvent(int deltaX, int deltaY) {
|
||||
if (!m_Player || !InputManager::MouseGrabbed())
|
||||
return;
|
||||
|
||||
static const float MouseSpeed = 0.0025f;
|
||||
float MouseSpeed = m_Client->GetConfig()->GetMouseSpeed();
|
||||
|
||||
m_Player->AddYaw(deltaX * MouseSpeed);
|
||||
m_Player->AddPitch(deltaY * -MouseSpeed);
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "blitz/protocol/packets/PlayerListPacket.h"
|
||||
#include "blitz/protocol/packets/PlayerPositionAndRotationPacket.h"
|
||||
#include "blitz/protocol/packets/PlayerShootPacket.h"
|
||||
#include "blitz/protocol/packets/PlayerStatsPacket.h"
|
||||
#include "blitz/protocol/packets/UpdateHealthPacket.h"
|
||||
#include "client/Client.h"
|
||||
|
||||
@@ -29,6 +30,7 @@ void ClientGame::RegisterHandlers() {
|
||||
GetDispatcher()->RegisterHandler(protocol::PacketType::PlayerList, this);
|
||||
GetDispatcher()->RegisterHandler(protocol::PacketType::PlayerPositionAndRotation, this);
|
||||
GetDispatcher()->RegisterHandler(protocol::PacketType::PlayerShoot, this);
|
||||
GetDispatcher()->RegisterHandler(protocol::PacketType::PlayerStats, this);
|
||||
GetDispatcher()->RegisterHandler(protocol::PacketType::UpdateHealth, this);
|
||||
}
|
||||
|
||||
@@ -51,6 +53,12 @@ void ClientGame::HandlePacket(const protocol::PlayerListPacket* packet) {
|
||||
}
|
||||
}
|
||||
|
||||
void ClientGame::HandlePacket(const protocol::PlayerStatsPacket* packet) {
|
||||
game::Player* player = m_Client->GetGame()->GetPlayerById(packet->GetPlayerID());
|
||||
assert(player);
|
||||
player->SetStats(packet->GetPlayerStats());
|
||||
}
|
||||
|
||||
void ClientGame::HandlePacket(const protocol::UpdateHealthPacket* packet) {
|
||||
game::Player* player = m_Client->GetGame()->GetPlayerById(m_Client->GetPlayerID());
|
||||
player->SetHP(packet->GetNewHealth());
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "client/gui/GameChatGui.h"
|
||||
#include "client/gui/Hud.h"
|
||||
#include "client/gui/MainMenu.h"
|
||||
#include "client/gui/LeaderBoard.h"
|
||||
#include "client/gui/ServerGui.h"
|
||||
#include <imgui.h>
|
||||
|
||||
@@ -15,8 +16,9 @@ BlitzGui::BlitzGui(Client* client) : GuiWidget(nullptr, client) {
|
||||
AddWidget(std::make_unique<GameChatGui>(this, client));
|
||||
AddWidget(std::make_unique<MainMenu>(client));
|
||||
AddWidget(std::make_unique<CrossHair>(client));
|
||||
AddWidget(std::make_unique<ServerGui>(this, client));
|
||||
AddWidget(std::make_unique<Hud>(this, client));
|
||||
AddWidget(std::make_unique<LeaderBoard>(this, client));
|
||||
AddWidget(std::make_unique<ServerGui>(this, client));
|
||||
SetCustomTheme();
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,8 @@ void Hud::Draw(const char* title, bool* p_open) {
|
||||
ImGui::Begin(title, nullptr, GetWindowFullScreenFlags() | ImGuiWindowFlags_NoInputs);
|
||||
|
||||
auto displaySize = ImGui::GetIO().DisplaySize;
|
||||
ImVec2 center = ImGui::GetMainViewport()->GetCenter();
|
||||
|
||||
const static ImVec2 buttonSize = {300, 60};
|
||||
const static ImVec2 fingergunSize = {256, 134.5};
|
||||
const static ImVec2 jpSize = {256 / 2, 256 / 2};
|
||||
@@ -32,6 +34,13 @@ void Hud::Draw(const char* title, bool* p_open) {
|
||||
displaySize.x - fingergunSize.x - paddingHeight, displaySize.y - fingergunSize.y + 1.0f / 2.5f * paddingHeight};
|
||||
ImVec2 spacing = ImGui::GetStyle().ItemInnerSpacing;
|
||||
|
||||
const float timetextWidth = ImGui::CalcTextSize("03 : 00").x;
|
||||
const float timetextHeight = ImGui::CalcTextSize("03 : 00").y;
|
||||
|
||||
ImGui::SetCursorPosX(center.x - timetextWidth / 2);
|
||||
ImGui::SetCursorPosY(timetextHeight / 2);
|
||||
ImGui::Text("03 : 00");
|
||||
|
||||
ImGui::SetCursorPosX(3 * paddingHeight);
|
||||
ImGui::SetCursorPosY(pvBarPos.y - 2 * paddingHeight);
|
||||
ImGui::BeginGroup();
|
||||
|
||||
74
src/client/gui/LeaderBoard.cpp
Normal file
74
src/client/gui/LeaderBoard.cpp
Normal file
@@ -0,0 +1,74 @@
|
||||
#include "client/gui/LeaderBoard.h"
|
||||
|
||||
#include "blitz/misc/Format.h"
|
||||
#include "blitz/misc/Log.h"
|
||||
#include "client/Client.h"
|
||||
#include "client/game/ClientGame.h"
|
||||
#include "client/gui/GuiWidget.h"
|
||||
#include <imgui.h>
|
||||
|
||||
namespace blitz {
|
||||
namespace gui {
|
||||
|
||||
LeaderBoard::LeaderBoard(GuiWidget* parent, Client* client) : GuiWidget(parent, client) {}
|
||||
|
||||
LeaderBoard::~LeaderBoard() {}
|
||||
|
||||
void LeaderBoard::Draw(const char* title, bool* p_open) {
|
||||
static int leaderboard_width = 640;
|
||||
static int leaderboard_height = 450;
|
||||
|
||||
ImGuiWindowFlags leaderboard_flags =
|
||||
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize;
|
||||
|
||||
ImVec2 center = ImGui::GetMainViewport()->GetCenter();
|
||||
ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
|
||||
ImGui::SetNextWindowSize(ImVec2(leaderboard_width, leaderboard_height));
|
||||
ImGui::Begin(title, p_open, leaderboard_flags);
|
||||
{
|
||||
std::string playerLeaderBoard = "Player";
|
||||
std::string killsLeaderBoard = "Kills";
|
||||
std::string deathsLeaderBoard = "Deaths";
|
||||
std::string kdLeaderBoard = "K/D";
|
||||
std::string precisionLeaderBoard = "Accuracy";
|
||||
for (auto [id, player] : m_Client->GetGame()->GetPlayers()) {
|
||||
playerLeaderBoard += utils::Format("\n%s", player.GetName().c_str());
|
||||
killsLeaderBoard += utils::Format("\n%i", player.GetStats().m_Kills);
|
||||
deathsLeaderBoard += utils::Format("\n%i", player.GetStats().m_Deaths);
|
||||
|
||||
// Check if the denominator is zero before calculating K/D ratio
|
||||
float kdRatio =
|
||||
(player.GetStats().m_Deaths != 0) ? static_cast<float>(player.GetStats().m_Kills) / player.GetStats().m_Deaths : 0.0f;
|
||||
kdLeaderBoard += utils::Format("\n%.2f", kdRatio);
|
||||
|
||||
// Check if the denominator is zero before calculating precision percentage
|
||||
float precisionPercentage =
|
||||
(player.GetStats().m_ShootCount != 0)
|
||||
? static_cast<float>(player.GetStats().m_ShootSuccessCount) / player.GetStats().m_ShootCount * 100.0f
|
||||
: 0.0f;
|
||||
precisionLeaderBoard += utils::Format("\n%.2f%%", precisionPercentage);
|
||||
}
|
||||
ImGui::Text("%s", playerLeaderBoard.c_str());
|
||||
ImGui::SameLine(0.0f, ImGui::GetStyle().ItemInnerSpacing.x * 10);
|
||||
ImGui::Text("%s", killsLeaderBoard.c_str());
|
||||
ImGui::SameLine(0.0f, ImGui::GetStyle().ItemInnerSpacing.x * 10);
|
||||
ImGui::Text("%s", deathsLeaderBoard.c_str());
|
||||
ImGui::SameLine(0.0f, ImGui::GetStyle().ItemInnerSpacing.x * 10);
|
||||
ImGui::Text("%s", kdLeaderBoard.c_str());
|
||||
ImGui::SameLine(0.0f, ImGui::GetStyle().ItemInnerSpacing.x * 10);
|
||||
ImGui::Text("%s", precisionLeaderBoard.c_str());
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
void LeaderBoard::Render() {
|
||||
if (!m_Client->IsConnected())
|
||||
return;
|
||||
|
||||
if (ImGui::IsKeyDown(ImGuiKey_Tab)) {
|
||||
Draw("Leaderboard", nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace gui
|
||||
} // namespace blitz
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "blitz/misc/Log.h"
|
||||
#include "client/Client.h"
|
||||
#include "client/display/InputManager.h"
|
||||
#include "client/display/PlayerController.h"
|
||||
#include "client/gui/FPSMenu.h"
|
||||
#include <SDL2/SDL.h>
|
||||
#include <imgui.h>
|
||||
@@ -160,33 +161,6 @@ void OptionsMenu::Render() {
|
||||
|
||||
ImGui::NewLine();
|
||||
|
||||
if (ImGui::Button("Retour") || (ImGui::IsKeyPressed(ImGuiKey_Escape, false) && !m_IsKeyPopupOpen)) {
|
||||
Disable();
|
||||
if (m_Client->IsConnected()) {
|
||||
ImGui::SetCursorPosX(displaySize.x - buttonSize.x - paddingHeight);
|
||||
ImGui::SetCursorPosY(displaySize.y - 2 * buttonSize.y - paddingHeight);
|
||||
} else {
|
||||
ImGui::SetCursorPosX(displaySize.x - buttonSize.x - paddingHeight);
|
||||
ImGui::SetCursorPosY(displaySize.y - buttonSize.y - paddingHeight);
|
||||
}
|
||||
ImGui::BeginGroup();
|
||||
if (ImGui::Button("Retour", buttonSize) || ImGui::IsKeyPressed(ImGuiKey_Escape)) {
|
||||
Disable();
|
||||
if (m_Client->IsConnected()) {
|
||||
InputManager::GrabMouse(true);
|
||||
} else {
|
||||
m_Parent->Enable();
|
||||
}
|
||||
}
|
||||
if (m_Client->IsConnected()) {
|
||||
if (ImGui::Button("Quitter la partie", buttonSize)) {
|
||||
m_Client->Disconnect();
|
||||
Disable();
|
||||
m_Parent->Enable();
|
||||
}
|
||||
}
|
||||
ImGui::EndGroup();
|
||||
}
|
||||
ImGuiTabBarFlags tab_bar_flags = ImGuiTabBarFlags_None;
|
||||
if (ImGui::BeginTabBar("OPTIONS", tab_bar_flags)) {
|
||||
if (ImGui::BeginTabItem("CONTROLES")) {
|
||||
@@ -196,6 +170,11 @@ void OptionsMenu::Render() {
|
||||
|
||||
HotkeyBindingButton();
|
||||
HotkeyBindingPopUp();
|
||||
float sensitivity = m_Client->GetConfig()->GetMouseSpeed() * 200.0f;
|
||||
ImGui::SetNextItemWidth(300.0f);
|
||||
if (ImGui::DragFloat("Sensibilite", &sensitivity, 0.005f, 0.0f, 10.0f, "%.3f")) {
|
||||
m_Client->GetConfig()->SetMouseSpeed(sensitivity / 200.0f);
|
||||
}
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
if (ImGui::BeginTabItem("GRAPHISMES")) {
|
||||
@@ -214,6 +193,33 @@ void OptionsMenu::Render() {
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
ImGui::EndTabBar();
|
||||
|
||||
if (m_Client->IsConnected()) {
|
||||
ImGui::SetCursorPosX(displaySize.x - buttonSize.x - paddingHeight);
|
||||
ImGui::SetCursorPosY(displaySize.y - 2 * buttonSize.y - paddingHeight);
|
||||
} else {
|
||||
ImGui::SetCursorPosX(displaySize.x - buttonSize.x - paddingHeight);
|
||||
ImGui::SetCursorPosY(displaySize.y - buttonSize.y - paddingHeight);
|
||||
}
|
||||
ImGui::BeginGroup();
|
||||
{
|
||||
if (ImGui::Button("Retour", buttonSize) || ImGui::IsKeyPressed(ImGuiKey_Escape)) {
|
||||
Disable();
|
||||
if (m_Client->IsConnected()) {
|
||||
InputManager::GrabMouse(true);
|
||||
} else {
|
||||
m_Parent->Enable();
|
||||
}
|
||||
}
|
||||
if (m_Client->IsConnected()) {
|
||||
if (ImGui::Button("Quitter la partie", buttonSize)) {
|
||||
m_Client->Disconnect();
|
||||
Disable();
|
||||
m_Parent->Enable();
|
||||
}
|
||||
}
|
||||
}
|
||||
ImGui::EndGroup();
|
||||
}
|
||||
}
|
||||
ImGui::End();
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "blitz/protocol/packets/ChatPacket.h"
|
||||
#include "blitz/protocol/packets/PlayerJoinPacket.h"
|
||||
#include "blitz/protocol/packets/PlayerPositionAndRotationPacket.h"
|
||||
#include "blitz/protocol/packets/PlayerStatsPacket.h"
|
||||
#include "blitz/protocol/packets/UpdateHealthPacket.h"
|
||||
#include "server/Server.h"
|
||||
#include <cmath>
|
||||
@@ -46,16 +47,17 @@ void ServerGame::CheckShoot(game::PlayerID shooter, Vec3f position, float yaw, f
|
||||
|
||||
game::Player* shooterPlayer = GetPlayerById(shooter);
|
||||
|
||||
shooterPlayer->GetStats().m_ShootCount++;
|
||||
|
||||
for (auto& [playerId, player] : GetPlayers()) {
|
||||
if (playerId != shooter && maths::Intersects(shootRay, playerStaticAABB + player.GetPosition())) {
|
||||
if (!shootLanded) {
|
||||
shootLanded = true;
|
||||
shooterPlayer->GetStats().m_ShootSuccessCount++;
|
||||
}
|
||||
DamagePlayer(player, *shooterPlayer);
|
||||
shootLanded = true;
|
||||
}
|
||||
}
|
||||
|
||||
shooterPlayer->GetStats().m_ShootCount++;
|
||||
if (shootLanded)
|
||||
shooterPlayer->GetStats().m_ShootSuccessCount++;
|
||||
}
|
||||
|
||||
void ServerGame::AddPlayer(game::PlayerID player, const std::string& name) {
|
||||
@@ -86,6 +88,8 @@ void ServerGame::DamagePlayer(game::Player& player, game::Player& shooter) {
|
||||
player.GetStats().m_Deaths++;
|
||||
shooter.GetStats().m_Kills++;
|
||||
player.SetPosition({utils::GetRandomReal(-10.0f, 10.0f), 0.0f, utils::GetRandomReal(-10.0f, 10.0f)});
|
||||
|
||||
UpdatePlayerStats();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,5 +103,12 @@ void ServerGame::UpdateHP(game::Player& player, float newHP) {
|
||||
m_Server->GetConnexions().at(player.GetID())->SendPacket(&packet);
|
||||
}
|
||||
|
||||
void ServerGame::UpdatePlayerStats() {
|
||||
for (auto& [playerId, player] : GetPlayers()) {
|
||||
protocol::PlayerStatsPacket packet(playerId, player.GetStats());
|
||||
m_Server->BroadcastPacket(&packet);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace server
|
||||
} // namespace blitz
|
||||
|
||||
Reference in New Issue
Block a user