26 Commits

Author SHA1 Message Date
81bb294297 remove useless window code
All checks were successful
Linux arm64 / Build (push) Successful in 4m34s
2024-03-30 10:04:55 +01:00
42966b1095 remove useless includes 2024-03-30 10:04:18 +01:00
Morph01
6ab9126cd7 Add mouse speed setting to BlitzConfig
All checks were successful
Linux arm64 / Build (push) Successful in 4m49s
2024-03-29 22:08:18 +01:00
0f0d2cb5e0 Merge branch 'gui' of git.ale-pri.com:Blitz/Blitz into gui
All checks were successful
Linux arm64 / Build (push) Successful in 4m46s
2024-03-26 12:51:49 +01:00
d5c52e8626 Merge branch 'main' into gui 2024-03-26 12:51:08 +01:00
Morph01
e16cea7214 timer and leaderboard
Some checks failed
Linux arm64 / Build (push) Failing after 4m53s
2024-03-26 12:38:20 +01:00
42a37abe45 im stupid
Some checks failed
Linux arm64 / Build (push) Failing after 4m30s
2024-03-26 10:42:18 +01:00
fdc0d69605 update shoot on death
Some checks failed
Linux arm64 / Build (push) Has been cancelled
2024-03-26 10:40:32 +01:00
c115602419 Merge branch 'stats' into gui
Some checks failed
Linux arm64 / Build (push) Has been cancelled
2024-03-26 10:35:34 +01:00
4590672b36 add PlayerStatsPacket
Some checks failed
Linux arm64 / Build (push) Failing after 4m28s
2024-03-26 10:35:05 +01:00
f79c65a563 fix merge
Some checks failed
Linux arm64 / Build (push) Failing after 4m29s
2024-03-26 09:44:44 +01:00
da76ae3d33 Merge branch 'gui' of git.ale-pri.com:Blitz/Blitz into gui
Some checks failed
Linux arm64 / Build (push) Failing after 2m40s
2024-03-26 09:39:27 +01:00
ad389aa576 Merge branch 'dev' into gui 2024-03-26 09:38:59 +01:00
Morph01
bd517c6cfe fix retour / quitter button
All checks were successful
Linux arm64 / Build (push) Successful in 4m35s
2024-03-26 09:32:07 +01:00
Morph01
63c33e4bc5 simple leaderboard
All checks were successful
Linux arm64 / Build (push) Successful in 4m34s
2024-03-22 09:13:17 +01:00
bea98cbe45 fix merge
All checks were successful
Linux arm64 / Build (push) Successful in 8m2s
2024-03-20 16:59:31 +01:00
bc84906b56 remove old KeyAction
Some checks failed
Linux arm64 / Build (push) Failing after 6m47s
2024-03-20 16:40:10 +01:00
Morph01
292fac185d Squashed commit of the following:
Some checks failed
Linux arm64 / Build (push) Failing after 2m48s
commit 2b0930a734
Author: Morph01 <thibaut6969delastreet@gmail.com>
Date:   Tue Mar 19 10:43:55 2024 +0100

    hud of blitz (#16)

    Résoudre partiellement #12

    Co-authored-by: Persson-dev <sim16.prib@gmail.com>
    Co-authored-by: Morph01 <145839520+Morph01@users.noreply.github.com>
    Co-authored-by: Simon Pribylski <sim16.prib@gmail.com>
    Reviewed-on: #16

commit 84b6acad4c
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Tue Mar 19 10:15:54 2024 +0100

    less spooky light

commit 9f94d51fc4
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Thu Mar 14 16:36:15 2024 +0100

    Ajout de tests d'intégration (#17)

    Le paquet fournissant OpenGL a été temporairement remplacé par glew

    Reviewed-on: #17
    Co-authored-by: Persson-dev <sim16.prib@gmail.com>
    Co-committed-by: Persson-dev <sim16.prib@gmail.com>

commit 9951256881
Author: Simon Pribylski <sim16.prib@gmail.com>
Date:   Wed Mar 13 20:19:37 2024 +0100

    action: install libsdl via apt

commit 4a02054648
Author: Morph01 <145839520+Morph01@users.noreply.github.com>
Date:   Wed Mar 13 13:53:20 2024 +0100

    compression tests

commit 19c39312bf
Author: Morph01 <145839520+Morph01@users.noreply.github.com>
Date:   Wed Mar 13 13:51:57 2024 +0100

    setup action

commit d5014b1e8a
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Tue Mar 12 10:26:47 2024 +0100

    Revert "extend Vec3"

    This reverts commit dccfa9c936.

commit dccfa9c936
Author: = <=>
Date:   Tue Mar 12 10:01:00 2024 +0100

    extend Vec3

commit e39fc8aa70
Author: Simon Pribylski <sim16.prib@gmail.com>
Date:   Tue Mar 12 08:55:49 2024 +0100

    Star Wars (#14)

    Reviewed-on: #14

commit d42f67724d
Author: AquaEBM <AquaEBM@gmail.com>
Date:   Tue Mar 12 08:32:53 2024 +0100

    fix error

commit 71bc4dd249
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Sat Mar 9 18:37:54 2024 +0100

    add keybindings (#13)

    Co-authored-by: Morph01 <thibaut6969delastreet@gmail.com>
    Reviewed-on: #13
    Co-authored-by: Persson-dev <sim16.prib@gmail.com>
    Co-committed-by: Persson-dev <sim16.prib@gmail.com>

commit 2cb5074140
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Sat Mar 9 11:01:30 2024 +0100

    better server logs

commit 269ac16d28
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Fri Mar 8 22:59:50 2024 +0100

    more precise logging

commit b7926d7a98
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Fri Mar 8 22:57:38 2024 +0100

    pretty log

commit 52da1cf19b
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Thu Mar 7 23:10:37 2024 +0100

    explicit server in logs

commit 2da89c8dab
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Thu Mar 7 21:12:41 2024 +0100

    xmake: remove global include

commit 88cb433ecf
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Thu Mar 7 21:03:23 2024 +0100

    xmake: relative paths

commit d96b01074e
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Thu Mar 7 20:50:14 2024 +0100

    split xmake targets

commit a1effa05cd
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Thu Mar 7 20:14:12 2024 +0100

    remove github ci

commit 7b58117f36
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Thu Mar 7 20:13:05 2024 +0100

    fix warnings

commit bf8a6458a0
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Tue Mar 5 12:30:09 2024 +0100

    valgrind full info

commit 18ddede8c0
Author: Persson-dev <sim16.prib@gmail.com>
Date:   Tue Mar 5 12:29:39 2024 +0100

    add shoot
2024-03-19 12:14:46 +01:00
Morph01
b2ecc690c2 repositioning the back and exit buttons 2024-03-10 17:40:57 +01:00
Morph01
80dbd73bfb keybind change works in game 2024-03-09 14:47:18 +01:00
4399787209 fix windows build 2024-03-08 19:59:41 +01:00
25fe2eb6d5 fix warnings 2024-03-08 19:53:25 +01:00
Morph01
9c5e788ee0 hotkey save 2024-03-07 15:31:24 +01:00
Morph01
f28eb338d7 add title bar in option menu and a hotkey binding interface 2024-03-05 12:18:45 +01:00
Morph01
fdd0b185ac Revert "add getkeyname"
This reverts commit 49ca6043bf.
2024-03-05 10:50:08 +01:00
49ca6043bf add getkeyname 2024-03-05 10:45:08 +01:00
21 changed files with 257 additions and 41 deletions

View File

@@ -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;
}
};

View File

@@ -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) {}
};

View File

@@ -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"

View File

@@ -13,6 +13,7 @@ class PlayerListPacket;
class PlayerLoginPacket;
class PlayerPositionAndRotationPacket;
class PlayerShootPacket;
class PlayerStatsPacket;
class ServerTpsPacket;
class UpdateHealthPacket;

View File

@@ -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

View 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

View File

@@ -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();

View File

@@ -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();

View 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

View File

@@ -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

View File

@@ -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>(),

View File

@@ -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

View 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

View File

@@ -37,6 +37,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 +51,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 +66,7 @@ void BlitzConfig::SaveConfig() {
{"pseudo", GetPseudo().data()},
{"vsync", IsVSyncEnabled()},
{"fps", IsFPSDisplayEnabled()},
{"sensitivity", GetMouseSpeed()},
{"keys", GetKeys()},
};

View File

@@ -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);

View File

@@ -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());

View File

@@ -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();
}

View File

@@ -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();

View 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

View File

@@ -160,42 +160,16 @@ 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")) {
// Always center this window when appearing
ImVec2 center = ImGui::GetMainViewport()->GetCenter();
ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
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 +188,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();

View File

@@ -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