There's a bullet without my name on it.
This commit is contained in:
parent
d3c6353f17
commit
18d6d58203
@ -5,6 +5,9 @@ Bullet::Bullet(Vector3f pos, Vector3f dir) : m_startpos(pos), m_currentpos(pos),
|
||||
|
||||
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() {}
|
||||
|
||||
bool Bullet::Update(World* world, float elapsedtime, int perframe, std::unordered_map<uint64_t, Player*> mapPlayer, netprot::ChunkMod** chunkmod) {
|
||||
@ -23,6 +26,7 @@ bool Bullet::Update(World* world, float elapsedtime, int perframe, std::unordere
|
||||
hit = true;
|
||||
}
|
||||
if (hit && !player->AmIDead()) {
|
||||
if (m_canhurt)
|
||||
player->InflictDamage(damage);
|
||||
player->m_hit = true;
|
||||
|
||||
|
@ -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<uint64_t, Player*> m_mapPlayer, netprot::ChunkMod** chunkmod);
|
||||
@ -28,6 +29,8 @@ private:
|
||||
m_velocity;
|
||||
uint64_t m_shooter_id = 0;
|
||||
|
||||
bool m_canhurt = true;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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,6 +280,9 @@ 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()) {
|
||||
@ -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)
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user