diff --git a/data/testtraze/sound/README.md b/data/testtraze/sound/README.md new file mode 100644 index 000000000..095308aba --- /dev/null +++ b/data/testtraze/sound/README.md @@ -0,0 +1,4 @@ +Digital SFX set by Kenney Vleugels (www.kenney.nl) + +You may use these sounds in personal and commercial projects. +Credit (www.kenney.nl) would be nice but is not mandatory. diff --git a/data/testtraze/sound/collision.ogg b/data/testtraze/sound/collision.ogg new file mode 100644 index 000000000..cf6098e73 Binary files /dev/null and b/data/testtraze/sound/collision.ogg differ diff --git a/data/testtraze/sound/frag.ogg b/data/testtraze/sound/frag.ogg new file mode 100644 index 000000000..b46593ded Binary files /dev/null and b/data/testtraze/sound/frag.ogg differ diff --git a/data/testtraze/sound/join.ogg b/data/testtraze/sound/join.ogg new file mode 100644 index 000000000..7a1545ca3 Binary files /dev/null and b/data/testtraze/sound/join.ogg differ diff --git a/data/testtraze/sound/suicide.ogg b/data/testtraze/sound/suicide.ogg new file mode 100644 index 000000000..46a3a0a6e Binary files /dev/null and b/data/testtraze/sound/suicide.ogg differ diff --git a/data/testtraze/sound/you_lose.ogg b/data/testtraze/sound/you_lose.ogg new file mode 100644 index 000000000..d9bc815c5 Binary files /dev/null and b/data/testtraze/sound/you_lose.ogg differ diff --git a/data/testtraze/sound/you_win.ogg b/data/testtraze/sound/you_win.ogg new file mode 100644 index 000000000..35997119c Binary files /dev/null and b/data/testtraze/sound/you_win.ogg differ diff --git a/src/tests/testtraze/CMakeLists.txt b/src/tests/testtraze/CMakeLists.txt index 6ed33047f..f7173253d 100644 --- a/src/tests/testtraze/CMakeLists.txt +++ b/src/tests/testtraze/CMakeLists.txt @@ -11,6 +11,12 @@ if (MOSQUITTO_FOUND) set(FILES shared/font.ttf testtraze/testtraze-keybindings.cfg + testtraze/sound/frag.ogg + testtraze/sound/suicide.ogg + testtraze/sound/collision.ogg + testtraze/sound/join.ogg + testtraze/sound/you_lose.ogg + testtraze/sound/you_win.ogg ) engine_add_executable(TARGET ${PROJECT_NAME} SRCS ${SRCS} FILES ${FILES} WINDOWED NOINSTALL) engine_target_link_libraries(TARGET ${PROJECT_NAME} DEPENDENCIES testcore voxelrender voxelfont util audio ${MOSQUITTO_LIBRARIES}) diff --git a/src/tests/testtraze/TestTraze.cpp b/src/tests/testtraze/TestTraze.cpp index 4977b4b5b..d0b47a049 100644 --- a/src/tests/testtraze/TestTraze.cpp +++ b/src/tests/testtraze/TestTraze.cpp @@ -18,7 +18,9 @@ TestTraze::TestTraze(const metric::MetricPtr& metric, const io::FilesystemPtr& f Super(metric, filesystem, eventBus, timeProvider), _protocol(eventBus), _voxelFontRender(FontSize, 4, voxel::VoxelFont::OriginUpperLeft), _soundMgr(filesystem) { init(ORGANISATION, "testtraze"); setRenderAxis(false); + setRelativeMouseMode(false); setFramesPerSecondsCap(60); + _allowRelativeMouseMode = false; _eventBus->subscribe(*this); _eventBus->subscribe(*this); _eventBus->subscribe(*this); @@ -142,19 +144,37 @@ void TestTraze::onEvent(const traze::BikeEvent& event) { void TestTraze::onEvent(const traze::TickerEvent& event) { const traze::Ticker& ticker = event.get(); - const std::string& name = playerName(ticker.fragger); + const std::string& fraggerName = playerName(ticker.fragger); + const std::string& casualtyName = playerName(ticker.casualty); switch (ticker.type) { case traze::TickerType::Frag: - sound("frag"); - _messageQueue.message("%s fragged another player", name.c_str()); + if (ticker.fragger == _protocol.playerId()) { + sound("you_win"); + _messageQueue.message("You fragged %s", casualtyName.c_str()); + } else if (ticker.casualty == _protocol.playerId()) { + sound("you_lose"); + _messageQueue.message("You were fragged by %s", fraggerName.c_str()); + } else { + _messageQueue.message("%s fragged %s", fraggerName.c_str(), casualtyName.c_str()); + } break; case traze::TickerType::Suicide: - sound("suicide"); - _messageQueue.message("%s committed suicide", name.c_str()); + if (ticker.casualty == (int)_protocol.playerId()) { + sound("you_lose"); + } else { + sound("suicide"); + } + _messageQueue.message("%s committed suicide", fraggerName.c_str()); break; case traze::TickerType::Collision: - sound("collision"); - _messageQueue.message("%s - collision with another player", name.c_str()); + if (ticker.casualty == (int)_protocol.playerId()) { + sound("you_lose"); + } else if (ticker.fragger == _protocol.playerId()) { + sound("you_win"); + } else { + sound("collision"); + } + _messageQueue.message("%s - collision with another player", fraggerName.c_str()); break; default: break; @@ -172,6 +192,7 @@ void TestTraze::onEvent(const traze::SpawnEvent& event) { if (spawn.own) { _spawnPosition = spawn.position; _spawnTime = _now; + sound("join"); } } diff --git a/src/tests/testtraze/TrazeProtocol.cpp b/src/tests/testtraze/TrazeProtocol.cpp index 4f7b8c810..6c17661ee 100644 --- a/src/tests/testtraze/TrazeProtocol.cpp +++ b/src/tests/testtraze/TrazeProtocol.cpp @@ -283,7 +283,7 @@ void Protocol::parseGridAndUpdateVolume(const std::string& json) { const int height = j["height"].get(); const int width = j["width"].get(); // x and z and swapped here - const voxel::Region region(glm::ivec3(-1), glm::ivec3(height + 1, 1, width + 1)); + const voxel::Region region(glm::ivec3(-1), glm::ivec3(height, 1, width)); voxel::RawVolume* v = new voxel::RawVolume(region); const auto& grid = j["tiles"]; int x = 0; diff --git a/src/tests/testtraze/TrazeProtocol.h b/src/tests/testtraze/TrazeProtocol.h index ccfaec8d7..947a41e31 100644 --- a/src/tests/testtraze/TrazeProtocol.h +++ b/src/tests/testtraze/TrazeProtocol.h @@ -20,7 +20,7 @@ private: std::string _instanceName; std::string _playerToken; std::string _clientToken; - uint32_t _playerId = 0u; + PlayerId _playerId = 0u; struct mosquitto *_mosquitto = nullptr; bool _connected = false; bool _subscribed = false; @@ -46,6 +46,8 @@ public: bool connect(); + PlayerId playerId() const; + bool joined() const; bool connected() const; @@ -208,6 +210,10 @@ public: bool bail(); }; +inline PlayerId Protocol::playerId() const { + return _playerId; +} + inline bool Protocol::joined() const { return _playerId != 0u; }