Compare commits

..

3 Commits

Author SHA1 Message Date
tovjemam
2ee6d61231 Add messages on player join/leave 2026-03-14 22:45:06 +01:00
tovjemam
9bc8984a21 Increase destructible respawn to 120s 2026-03-14 22:40:33 +01:00
tovjemam
e0951c39a7 Add basic settings 2026-03-14 22:39:53 +01:00
6 changed files with 67 additions and 16 deletions

View File

@ -12,12 +12,7 @@ App::App() :
{
std::cout << "Initializing App..." << std::endl;
#ifndef EMSCRIPTEN
audiomaster_.SetMasterVolume(1.0f);
#else
audiomaster_.SetMasterVolume(2.0f);
#endif
ApplySettings();
AddChatMessage("Test!");
}
@ -141,7 +136,11 @@ void App::Input(game::PlayerInputType in, bool pressed, bool repeated)
{
if (in == game::IN_MENU && pressed)
{
OpenSettings();
if (!menu_)
OpenSettings();
else
menu_.reset();
return;
}
@ -159,10 +158,8 @@ void App::Input(game::PlayerInputType in, bool pressed, bool repeated)
void App::MouseMove(const glm::vec2& delta)
{
float sensitivity = 0.002f; // Sensitivity factor for mouse movement
float delta_yaw = -delta.x * sensitivity;
float delta_pitch = -delta.y * sensitivity;
float delta_yaw = -delta.x * sensitivity_;
float delta_pitch = -delta.y * sensitivity_;
if (session_)
session_->ProcessMouseMove(delta_yaw, delta_pitch);
@ -210,10 +207,10 @@ void App::DrawChat()
}
}
static void AddSlider(gui::Menu& menu, std::string text, int& value, int min, int max)
static void AddSlider(gui::Menu& menu, std::string text, int& value, int min, int max, std::function<void()> changed)
{
auto& slider = menu.Add<gui::SelectMenuItem>(std::move(text));
auto on_switch = [&slider, &value, min, max] (int v) {
auto on_switch = [&slider, &value, min, max, changed] (int v) {
value += v;
// clamp
@ -223,6 +220,7 @@ static void AddSlider(gui::Menu& menu, std::string text, int& value, int min, in
value = max;
slider.SetSelectionText(std::to_string(value));
changed();
};
slider.SetSwitchCallback(on_switch);
@ -233,12 +231,41 @@ void App::OpenSettings()
{
menu_ = std::make_unique<gui::Menu>();
AddSlider(*menu_, "jak moc to řve", volume_, 0, 100);
AddSlider(*menu_, "jak moc to řve", volume_, 0, 100, [this]{
ApplyVolume();
});
AddSlider(*menu_, "agresivita krysy", sens_, 0, 100, [this]{
ApplySensitivity();
});
auto& ok = menu_->Add<gui::ButtonMenuItem>("0k");
ok.SetClickCallback([this] { menu_.reset(); });
}
void App::ApplySettings()
{
ApplyVolume();
ApplySensitivity();
}
void App::ApplyVolume()
{
float vol_f = static_cast<float>(volume_) / 50.0f;
#ifndef EMSCRIPTEN
audiomaster_.SetMasterVolume(vol_f);
#else
audiomaster_.SetMasterVolume(2.0f * vol_f);
#endif
}
void App::ApplySensitivity()
{
float f = static_cast<float>(sens_) / 100.0f;
sensitivity_ = glm::mix(0.0005f, 0.0035f, f);
}
#define COL_LABEL "^ccc"
#define COL_VALUE "^5ff"

View File

@ -57,6 +57,9 @@ private:
void DrawChat();
void OpenSettings();
void ApplySettings();
void ApplyVolume();
void ApplySensitivity();
void UpdateStats();
void DrawStats();
@ -83,6 +86,8 @@ private:
// settings
int volume_ = 50;
int sens_ = 50;
float sensitivity_ = 0.0f;
// stats
float stats_time_ = 0.0f;

View File

@ -1,5 +1,7 @@
#include "game.hpp"
#include <format>
#include "player.hpp"
#include "openworld.hpp"
@ -22,13 +24,26 @@ void game::Game::FinishFrame()
void game::Game::PlayerJoined(Player& player)
{
player.SetWorld(default_world_);
players_.insert(&player);
BroadcastChat(std::format("{}^r se připoojil jupí jupí jupííí", player.GetName()));
}
void game::Game::PlayerLeft(Player& player)
{
players_.erase(&player);
BroadcastChat(std::format("{}^r se vodpojil zmrd", player.GetName()));
}
bool game::Game::PlayerInput(Player& player, PlayerInputType type, bool enabled)
{
return false; // not handled here
}
void game::Game::BroadcastChat(const std::string& text)
{
for (auto player : players_)
{
player->SendChat(text);
}
}

View File

@ -1,6 +1,7 @@
#pragma once
#include <map>
#include <set>
#include "world.hpp"
@ -21,9 +22,12 @@ public:
void PlayerLeft(Player& player);
bool PlayerInput(Player& player, PlayerInputType type, bool enabled);
private:
void BroadcastChat(const std::string& text);
private:
std::shared_ptr<World> default_world_;
std::set<Player*> players_;
};

View File

@ -119,7 +119,7 @@ void game::OpenWorld::DestructibleDestroyed(net::ObjNum num, std::unique_ptr<Map
{
auto& destroyed_obj = Spawn<DestroyedObject>(std::move(col));
Schedule(10000, [this, num] {
Schedule(120000, [this, num] {
RespawnObj(num);
});
}

View File

@ -85,7 +85,7 @@ bool sv::Client::ProcessLoginMsg(net::InMessage& msg)
// check ver
if (ver != FEKAL_VERSION)
{
SendChat(std::format("^f55špatná verze {}, server je na verzi {}", ver, FEKAL_VERSION));
SendChat(std::format("^f55máš nahovno verzi {}, server je na {}", ver, FEKAL_VERSION));
return false;
}