diff --git a/Client.cpp b/Client.cpp index 17227e7..32b8adb 100644 --- a/Client.cpp +++ b/Client.cpp @@ -90,6 +90,18 @@ void Client::processCustomPacket(MsgType type, sf::Packet& packet) { switch (type) { case MsgType::Kill: packet >> buffId[0] >> buffId[1]; + _lastEvent = ""; + if(buffId[1] == _socket.ownId()) { + _player->addKill(); + SoundController::playSound(SoundTag("kill"), ShooterConsts::KILL_SOUND); + _lastEvent += _player->playerName(); + } + else { + _players[buffId[1]]->addKill(); + _lastEvent += _players[buffId[1]]->playerName(); + } + _lastEvent += " kill "; + if(buffId[0] == _socket.ownId()) { _player->addDeath(); // respawn @@ -97,15 +109,12 @@ void Client::processCustomPacket(MsgType type, sf::Packet& packet) { _player->initWeapons(); _player->setFullAbility(); SoundController::playSound(SoundTag("death"), ShooterConsts::DEATH_SOUND); + _lastEvent += _player->playerName(); } - else + else { _players[buffId[0]]->addDeath(); - if(buffId[1] == _socket.ownId()) { - _player->addKill(); - SoundController::playSound(SoundTag("kill"), ShooterConsts::KILL_SOUND); + _lastEvent += _players[buffId[0]]->playerName(); } - else - _players[buffId[1]]->addKill(); break; case MsgType::FireTrace: packet >> dbuff[0] >> dbuff[1] >> dbuff[2] >> dbuff[3] >> dbuff[4] >> dbuff[5]; diff --git a/Client.h b/Client.h index e34394f..5dc3598 100644 --- a/Client.h +++ b/Client.h @@ -10,6 +10,8 @@ class Client final : public ClientUDP { private: + std::string _lastEvent; + std::map> _players{}; std::shared_ptr _player; @@ -50,7 +52,9 @@ public: void changeWeapon(const std::string& weaponName); void addPlayer(sf::Uint16 id, std::shared_ptr player); - std::map>const & players() const { return _players; } + [[nodiscard]] std::map>const & players() const { return _players; } + + [[nodiscard]] std::string lastEvent() const { return _lastEvent; } }; diff --git a/Shooter.cpp b/Shooter.cpp index bc55af6..ada46f2 100644 --- a/Shooter.cpp +++ b/Shooter.cpp @@ -173,7 +173,9 @@ void Shooter::gui() { } void Shooter::drawStatsTable() { - int i = 0; + int i = 1; + + screen->drawText(client->lastEvent(),Vec2D{10, 10},25, sf::Color(0, 0, 0, 100)); vector> allPlayers; allPlayers.push_back(player); @@ -185,8 +187,8 @@ void Shooter::drawStatsTable() { } ); for(auto& p : allPlayers) { - screen->drawText(std::to_string(i + 1) + "\t" + p->playerName() + "\t" + std::to_string(p->kills()) + " / " + std::to_string(p->deaths()), - Vec2D{10, 10 + 35.0*i}, 25, sf::Color(0, 0, 0, 150)); + screen->drawText(std::to_string(i) + "\t" + p->playerName() + "\t" + std::to_string(p->kills()) + " / " + std::to_string(p->deaths()), + Vec2D{10, 15 + 35.0*i}, 25, sf::Color(0, 0, 0, 150)); i++; } }