Merge pull request #20 from CegepSTH/SQC-18_Mecanique_de_combat
Sqc 18 mecanique de combat
This commit is contained in:
commit
851d5f0c0b
@ -7,11 +7,19 @@ Bullet::Bullet(Vector3f pos, Vector3f dir, uint64_t tid): m_startpos(pos), m_cur
|
||||
|
||||
Bullet::~Bullet() {}
|
||||
|
||||
bool Bullet::Update(World* world, float elapsedtime, int perframe) {
|
||||
bool Bullet::Update(World* world, float elapsedtime, int perframe, std::map<uint64_t, Player*> mapPlayer) {
|
||||
int max = 100 / perframe;
|
||||
float damage = 0.057f;
|
||||
for (int x = 0; x < max; ++x) {
|
||||
m_currentpos += m_velocity * elapsedtime;
|
||||
|
||||
for (auto& [key, player] : mapPlayer) {
|
||||
if ((m_currentpos - player->GetPosition()).Length() < .4f) {
|
||||
player->InflictDamage(damage);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!world->ChunkAt(m_currentpos))
|
||||
return true;
|
||||
else if (world->BlockAt(m_currentpos) != BTYPE_AIR) {
|
||||
@ -20,6 +28,7 @@ bool Bullet::Update(World* world, float elapsedtime, int perframe) {
|
||||
}
|
||||
else if ((m_currentpos - m_startpos).Length() > VIEW_DISTANCE) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -3,8 +3,12 @@
|
||||
|
||||
#include "define.h"
|
||||
#include "vector3.h"
|
||||
#include <map>
|
||||
#include "player.h"
|
||||
|
||||
|
||||
class World;
|
||||
class Player;
|
||||
|
||||
class Bullet {
|
||||
public:
|
||||
@ -12,7 +16,7 @@ public:
|
||||
Bullet(Vector3f pos, Vector3f dir, uint64_t tid);
|
||||
~Bullet();
|
||||
|
||||
bool Update(World* world, float elapsedtime, int perframe);
|
||||
bool Update(World* world, float elapsedtime, int perframe, std::map<uint64_t, Player*> m_mapPlayer);
|
||||
void Transpose(int& x, int& z);
|
||||
Vector3f getPos() const;
|
||||
Vector3f getVel() const;
|
||||
@ -23,6 +27,8 @@ private:
|
||||
m_currentpos,
|
||||
m_velocity;
|
||||
uint64_t m_tid = 0;
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // BULLET_H__
|
||||
|
@ -4,7 +4,7 @@
|
||||
Player::Player(const Vector3f& position, float rotX, float rotY) : m_position(position), m_rotX(rotX), m_rotY(rotY) {
|
||||
m_velocity = Vector3f(0, 0, 0);
|
||||
m_airborne = true;
|
||||
m_hp = 0.75f; //TODO: Remettre à 1.0f
|
||||
m_hp = 1.0f; //TODO: Remettre <20> 1.0f
|
||||
m_username = "Zelda Bee-Bop56";
|
||||
}
|
||||
|
||||
@ -167,7 +167,7 @@ Player::Sound Player::ApplyPhysics(Vector3f input, World* world, float elapsedTi
|
||||
|
||||
m_position += m_velocity;
|
||||
|
||||
static float bobbingtime = 0; // Gestion de la caméra
|
||||
static float bobbingtime = 0; // Gestion de la cam<EFBFBD>ra
|
||||
static bool leftright = false;
|
||||
static bool isStep = false;
|
||||
if (bobbingtime <= 360.f)
|
||||
@ -208,6 +208,26 @@ void Player::Teleport(int& x, int& z) {
|
||||
m_position.x -= x * CHUNK_SIZE_X;
|
||||
m_position.z -= z * CHUNK_SIZE_Z;
|
||||
}
|
||||
bool Player::AmIDead()
|
||||
{
|
||||
return m_hp <= 0;
|
||||
}
|
||||
|
||||
|
||||
void Player::InflictDamage(float hitPoints)
|
||||
{
|
||||
|
||||
m_hp -= hitPoints;
|
||||
|
||||
|
||||
if (AmIDead())
|
||||
{ // Quand le joueur est mort.
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint64_t Player::getId() const { return id; }
|
||||
|
||||
|
@ -28,6 +28,10 @@ public:
|
||||
float GetHP() const;
|
||||
void Teleport(int& x, int& z);
|
||||
|
||||
bool AmIDead();
|
||||
void InflictDamage(float hitPoints);
|
||||
|
||||
private:
|
||||
uint64_t getId() const;
|
||||
|
||||
protected:
|
||||
|
@ -420,6 +420,12 @@ void Engine::LoadResource() {
|
||||
|
||||
void Engine::UnloadResource() {}
|
||||
|
||||
void Engine::InstantDamage()
|
||||
{
|
||||
m_player.InflictDamage(0.10f);
|
||||
m_damage = false;
|
||||
}
|
||||
|
||||
void Engine::SystemNotification(std::string systemLog) {
|
||||
std::string message = "";
|
||||
|
||||
@ -1003,7 +1009,7 @@ void Engine::Render(float elapsedTime) {
|
||||
for (int x = 0; x < MAX_BULLETS; ++x) { // Array de bullets en jeu.
|
||||
if (m_bullets[x]) {
|
||||
for (int b = 0; b < BULLET_UPDATES_PER_FRAME; ++b) {
|
||||
if (m_bullets[x]->Update(&m_world, elapsedTime, BULLET_UPDATES_PER_FRAME)) {
|
||||
if (m_bullets[x]->Update(&m_world, elapsedTime, BULLET_UPDATES_PER_FRAME, m_players)) {
|
||||
m_bullets[x]->~Bullet();
|
||||
if (m_whoosh[x])
|
||||
m_whoosh[x]->drop();
|
||||
@ -1031,7 +1037,10 @@ void Engine::Render(float elapsedTime) {
|
||||
DrawHud(elapsedTime, bloc);
|
||||
DisplayPovGun();
|
||||
ProcessNotificationQueue();
|
||||
|
||||
if (m_damage)
|
||||
{
|
||||
InstantDamage();
|
||||
}
|
||||
static bool fell = false;
|
||||
if (m_player.GetPosition().y < 1.7f && !fell) {
|
||||
m_audio.Create3DAudioObj(m_scream, AUDIO_PATH "scream.wav", m_player.GetPOV(), m_player.GetVelocity(), false,1.f);
|
||||
@ -1127,6 +1136,8 @@ void Engine::KeyPressEvent(unsigned char key) {
|
||||
break;
|
||||
case 8: // I - Ignorer
|
||||
break;
|
||||
case 9: // J - InstantDamage
|
||||
m_damage = true;
|
||||
case 15: // P - Ignorer
|
||||
break;
|
||||
case 17: // R - Ignorer
|
||||
|
@ -46,6 +46,7 @@ private:
|
||||
|
||||
bool LoadTexture(Texture& texture, const std::string& filename, bool useMipmaps = true, bool stopOnError = true);
|
||||
|
||||
void InstantDamage();
|
||||
void SystemNotification(std::string systemLog);
|
||||
void KillNotification(Player killer, Player killed);
|
||||
void DisplayNotification(std::string message);
|
||||
@ -86,7 +87,7 @@ private:
|
||||
|
||||
Bullet* m_bullets[MAX_BULLETS];
|
||||
|
||||
std::map<uint64_t, RemotePlayer*> m_players;
|
||||
std::map<uint64_t, Player*> m_players;
|
||||
|
||||
//Menu
|
||||
enum class GameState: uint8_t { MAIN_MENU, OPTIONS, QUIT, NEWG, PLAY };
|
||||
@ -107,6 +108,8 @@ private:
|
||||
int m_renderCount = 0;
|
||||
int m_countdown = COUNTDOWN;
|
||||
|
||||
bool m_damage = false;
|
||||
|
||||
bool m_wireframe = false;
|
||||
bool m_isSkybox = true;
|
||||
bool m_block = false;
|
||||
|
Loading…
Reference in New Issue
Block a user