diff --git a/.gitignore b/.gitignore index 1a44371..1ac9560 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,8 @@ # ---> C++ +<<<<<<< HEAD # Executables +======= +# Executable +>>>>>>> refs/heads/Gestions_hitbox 2D_Engine \ No newline at end of file diff --git a/ECS/HitboxComponent.hpp b/ECS/HitboxComponent.hpp index 073d4d7..1025001 100644 --- a/ECS/HitboxComponent.hpp +++ b/ECS/HitboxComponent.hpp @@ -55,7 +55,7 @@ class HitboxComponent : public Component { Vector2D position{Vector2D(1.0f, 1.0f)}; // Dans l'entitée (0 -> 1) 0=>tout a gauche de l'entitée, 1=>tout a droite et pareil pour le Y Vector2D scale{Vector2D(1.0f, 1.0f)}; // Par rapport à la taille initiale (0 -> 1) - SDL_Rect hitboxR; + SDL_Rect hitboxR {0, 0, 0, 0}; bool hitboxActivated {true}; diff --git a/ECS/PlayerSystem.hpp b/ECS/PlayerSystem.hpp index 7d41c88..f3f679d 100644 --- a/ECS/PlayerSystem.hpp +++ b/ECS/PlayerSystem.hpp @@ -92,7 +92,7 @@ class PlayerSystem : public Component { SDL_SetRenderDrawColor(Game::renderer, 20, 20, 18, 255); } -#endif +#endif // DEBUG_MODE private: void m_getInputs() @@ -140,8 +140,8 @@ class PlayerSystem : public Component { Game::tileMap.LoadNextMap(touchedHitbox); m_transform->position = Game::tileMap.getPlayerInitPos(); - Game::camera.camR.x = static_cast(m_transform->position.x - static_cast(Game::camera.camR.w / 2 - m_transform->dimension.x * m_transform->scale / 2)); - Game::camera.camR.y = static_cast(m_transform->position.y - static_cast(Game::camera.camR.h / 2 - m_transform->dimension.y * m_transform->scale / 2)); + Game::camera.camR.x = static_cast(m_transform->position.x - static_cast((Game::camera.camR.w >> 1) - ((m_transform->dimension.x * m_transform->scale) / 2))); + Game::camera.camR.y = static_cast(m_transform->position.y - static_cast((Game::camera.camR.h >> 1) - ((m_transform->dimension.y * m_transform->scale) / 2))); playerState = State::None; break; @@ -154,10 +154,13 @@ class PlayerSystem : public Component { { if(it->get()->getComponent().hitboxActivated) { - if(SDL_HasIntersection(&futureHitboxR, &it->get()->getComponent().hitboxR)) + SDL_Rect entityHitboxR {it->get()->getComponent().hitboxR}; + + if(SDL_HasIntersection(&futureHitboxR, &entityHitboxR)) { if(i == 0) m_transform->velocity.x = 0; if(i == 1) m_transform->velocity.y = 0; + break; } } @@ -199,8 +202,8 @@ class PlayerSystem : public Component { void m_setCamera() { - float targetX = m_transform->position.x - static_cast(Game::camera.camR.w / 2 - m_transform->dimension.x * m_transform->scale / 2); - float targetY = m_transform->position.y - static_cast(Game::camera.camR.h / 2 - m_transform->dimension.y * m_transform->scale / 2); + float targetX = m_transform->position.x - static_cast((Game::camera.camR.w >> 1) - ((m_transform->dimension.x * m_transform->scale) >> 2)); + float targetY = m_transform->position.y - static_cast((Game::camera.camR.h >> 1) - ((m_transform->dimension.y * m_transform->scale) >> 2)); float smoothingFactor {0.08f}; @@ -274,4 +277,4 @@ class PlayerSystem : public Component { State playerState {State::None}; }; -#endif +#endif // PLAYER_HPP