Merge branch 'Gestions_hitbox' into main

# Conflicts:
#    .gitignore
This commit is contained in:
Ulysse Cura 2024-09-08 14:05:49 +02:00
commit 1e29f7e4a5
3 changed files with 15 additions and 8 deletions

4
.gitignore vendored
View File

@ -1,4 +1,8 @@
# ---> C++
<<<<<<< HEAD
# Executables
=======
# Executable
>>>>>>> refs/heads/Gestions_hitbox
2D_Engine

View File

@ -55,7 +55,7 @@ class HitboxComponent : public Component {
Vector2D<float> position{Vector2D<float>(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<float> scale{Vector2D<float>(1.0f, 1.0f)}; // Par rapport à la taille initiale (0 -> 1)
SDL_Rect hitboxR;
SDL_Rect hitboxR {0, 0, 0, 0};
bool hitboxActivated {true};

View File

@ -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<int>(m_transform->position.x - static_cast<float>(Game::camera.camR.w / 2 - m_transform->dimension.x * m_transform->scale / 2));
Game::camera.camR.y = static_cast<int>(m_transform->position.y - static_cast<float>(Game::camera.camR.h / 2 - m_transform->dimension.y * m_transform->scale / 2));
Game::camera.camR.x = static_cast<int>(m_transform->position.x - static_cast<float>((Game::camera.camR.w >> 1) - ((m_transform->dimension.x * m_transform->scale) / 2)));
Game::camera.camR.y = static_cast<int>(m_transform->position.y - static_cast<float>((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<HitboxComponent>().hitboxActivated)
{
if(SDL_HasIntersection(&futureHitboxR, &it->get()->getComponent<HitboxComponent>().hitboxR))
SDL_Rect entityHitboxR {it->get()->getComponent<HitboxComponent>().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<float>(Game::camera.camR.w / 2 - m_transform->dimension.x * m_transform->scale / 2);
float targetY = m_transform->position.y - static_cast<float>(Game::camera.camR.h / 2 - m_transform->dimension.y * m_transform->scale / 2);
float targetX = m_transform->position.x - static_cast<float>((Game::camera.camR.w >> 1) - ((m_transform->dimension.x * m_transform->scale) >> 2));
float targetY = m_transform->position.y - static_cast<float>((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