diff --git a/SQCSim-common/bullet.cpp b/SQCSim-common/bullet.cpp index a489c55..53fe339 100644 --- a/SQCSim-common/bullet.cpp +++ b/SQCSim-common/bullet.cpp @@ -3,7 +3,10 @@ Bullet::Bullet(Vector3f pos, Vector3f dir) : m_startpos(pos), m_currentpos(pos), m_velocity(dir) {} -Bullet::Bullet(Vector3f pos, Vector3f dir, uint64_t shooter_id): m_startpos(pos), m_currentpos(pos), m_velocity(dir), m_shooter_id(shooter_id) {} +Bullet::Bullet(Vector3f pos, Vector3f dir, uint64_t shooter_id) : m_startpos(pos), m_currentpos(pos), m_velocity(dir), m_shooter_id(shooter_id) {} + + +Bullet::Bullet(Vector3f pos, Vector3f dir, uint64_t shooter_id, bool canhurt): m_startpos(pos), m_currentpos(pos), m_velocity(dir), m_shooter_id(shooter_id), m_canhurt(canhurt) {} Bullet::~Bullet() {} @@ -23,7 +26,8 @@ bool Bullet::Update(World* world, float elapsedtime, int perframe, std::unordere hit = true; } if (hit && !player->AmIDead()) { - player->InflictDamage(damage); + if (m_canhurt) + player->InflictDamage(damage); player->m_hit = true; if (player->AmIDead()) diff --git a/SQCSim-common/bullet.h b/SQCSim-common/bullet.h index 3f875d9..252fd70 100644 --- a/SQCSim-common/bullet.h +++ b/SQCSim-common/bullet.h @@ -14,6 +14,7 @@ class Bullet { public: Bullet(Vector3f pos, Vector3f dir); Bullet(Vector3f pos, Vector3f dir, uint64_t tid); + Bullet(Vector3f pos, Vector3f dir, uint64_t tid, bool canhurt); ~Bullet(); bool Update(World* world, float elapsedtime, int perframe, std::unordered_map m_mapPlayer, netprot::ChunkMod** chunkmod); @@ -27,6 +28,8 @@ private: m_currentpos, m_velocity; uint64_t m_shooter_id = 0; + + bool m_canhurt = true; }; diff --git a/SQCSim-srv/connection.cpp b/SQCSim-srv/connection.cpp index 1c823ce..c125974 100644 --- a/SQCSim-srv/connection.cpp +++ b/SQCSim-srv/connection.cpp @@ -147,7 +147,7 @@ Timestamp Connection::Run(World* world) { } out.states.jumping = player->GetIsAirborne(); - out.states.running = player->GetVelocity().Length() > .5f; + out.states.running = player->GetVelocity().Length() > .2f; out.states.still = !out.states.running && !out.states.jumping; out.states.hit = player->m_hit; player->m_hit = false; diff --git a/SQCSim-srv/server.cpp b/SQCSim-srv/server.cpp index edf740c..b997b12 100644 --- a/SQCSim-srv/server.cpp +++ b/SQCSim-srv/server.cpp @@ -202,8 +202,8 @@ void Server::Run() { m_conns.erase(key); continue; } - int x = (rand() % (CHUNK_SIZE_X * WORLD_SIZE_X - 1) - (CHUNK_SIZE_X * WORLD_SIZE_X / 2)) / 8, - y = (rand() % (CHUNK_SIZE_Y * WORLD_SIZE_Y - 1) - (CHUNK_SIZE_Y * WORLD_SIZE_Y / 2)) / 8; + int x = (rand() % (CHUNK_SIZE_X * WORLD_SIZE_X - 1) - (CHUNK_SIZE_X * WORLD_SIZE_X / 2)) / 16, + y = (rand() % (CHUNK_SIZE_Y * WORLD_SIZE_Y - 1) - (CHUNK_SIZE_Y * WORLD_SIZE_Y / 2)) / 16; conn->player = new Player(Vector3f(x + .5f, CHUNK_SIZE_Y + 1.8f, y + .5f)); conn->player->m_username = conn->GetName(); m_players[key] = conn->player; @@ -280,11 +280,14 @@ void Server::Run() { /* Process */ if (conn->m_nsync) { + if (conn->player->AmIDead()) + conn->m_nsync = false; + Timestamp tstamp = conn->Run(m_world); if (conn->player->AmIDead()) { Chat* chat = new Chat(); - chat->dest_id = chat->dest_team_id = chat->src_id = 0; + chat->dest_id = chat->dest_team_id = chat->src_id = 0; std::string killer = m_conns.at(conn->player->Killer)->player->GetUsername(); @@ -293,7 +296,6 @@ void Server::Run() { strcpy(chat->mess, 140, mess.c_str()); chatlog.emplace_back(chat); ++deadplayers; - conn->m_nsync = false; } else { for (auto& chmo : conn->ChunkDiffs) diff --git a/SQCSim2021/engine.cpp b/SQCSim2021/engine.cpp index 89a4029..db23ef3 100644 --- a/SQCSim2021/engine.cpp +++ b/SQCSim2021/engine.cpp @@ -1512,7 +1512,8 @@ void Engine::Render(float elapsedTime) { std::cout << sync.hp << std::endl; m_otherplayerpos = sync.position; - m_player.InflictDamage(sync.hp - comp.hp); + + m_player.InflictDamage(sync.hp - m_player.GetHP()); Vector3f diff = sync.position - comp.position; @@ -1558,7 +1559,7 @@ void Engine::Render(float elapsedTime) { break; case BULLET: if (Deserialize(&bull, pck, &bsize)) { - Bullet* bult = new Bullet(bull.pos, bull.dir); + Bullet* bult = new Bullet(bull.pos, bull.dir, bull.id, false); for (int x = 0; x < MAX_BULLETS; ++x) // Ajouter une balle dans l'array (aussi connu sous le nom de "faire pow pow"). if (!m_bullets[x]) { m_bullets[x] = bult; @@ -2333,6 +2334,12 @@ void Engine::MousePressEvent(const MOUSE_BUTTON& button, int x, int y) { m_gamestate = GameState::MAIN_MENU; m_selectedPlayOptions = false; m_audio.ToggleMusicState(m_gamestate); + if (m_networkgame) { + if (m_conn.m_sock_udp) + closesocket(m_conn.m_sock_udp); + if (m_conn.m_sock_udp) + closesocket(m_conn.m_sock_udp); + } } } }