Merge branch 'Gestions_hitbox' into main
# Conflicts: # .gitignore
This commit is contained in:
commit
1e29f7e4a5
|
@ -1,4 +1,8 @@
|
||||||
# ---> C++
|
# ---> C++
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
# Executables
|
# Executables
|
||||||
|
=======
|
||||||
|
# Executable
|
||||||
|
>>>>>>> refs/heads/Gestions_hitbox
|
||||||
2D_Engine
|
2D_Engine
|
|
@ -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> 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)
|
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};
|
bool hitboxActivated {true};
|
||||||
|
|
||||||
|
|
|
@ -92,7 +92,7 @@ class PlayerSystem : public Component {
|
||||||
|
|
||||||
SDL_SetRenderDrawColor(Game::renderer, 20, 20, 18, 255);
|
SDL_SetRenderDrawColor(Game::renderer, 20, 20, 18, 255);
|
||||||
}
|
}
|
||||||
#endif
|
#endif // DEBUG_MODE
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void m_getInputs()
|
void m_getInputs()
|
||||||
|
@ -140,8 +140,8 @@ class PlayerSystem : public Component {
|
||||||
Game::tileMap.LoadNextMap(touchedHitbox);
|
Game::tileMap.LoadNextMap(touchedHitbox);
|
||||||
m_transform->position = Game::tileMap.getPlayerInitPos();
|
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.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 / 2 - m_transform->dimension.y * 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;
|
playerState = State::None;
|
||||||
break;
|
break;
|
||||||
|
@ -154,10 +154,13 @@ class PlayerSystem : public Component {
|
||||||
{
|
{
|
||||||
if(it->get()->getComponent<HitboxComponent>().hitboxActivated)
|
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 == 0) m_transform->velocity.x = 0;
|
||||||
if(i == 1) m_transform->velocity.y = 0;
|
if(i == 1) m_transform->velocity.y = 0;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -199,8 +202,8 @@ class PlayerSystem : public Component {
|
||||||
|
|
||||||
void m_setCamera()
|
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 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 / 2 - m_transform->dimension.y * 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};
|
float smoothingFactor {0.08f};
|
||||||
|
|
||||||
|
@ -274,4 +277,4 @@ class PlayerSystem : public Component {
|
||||||
State playerState {State::None};
|
State playerState {State::None};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif // PLAYER_HPP
|
||||||
|
|
Loading…
Reference in New Issue