void Player::tick() { // Collision Detection bool TouchingBottom = false; for (int i = 0;i < m_scene->GetEntityAmount();i++) { if (m_scene->GetEntity(i) != this) { //Bottom Check if (m_char.getGlobalBounds().top + m_char.getGlobalBounds().height + getPosition().y >= m_scene->GetEntity(i)->GetGlobalBounds().top && m_char.getGlobalBounds().left + m_char.getGlobalBounds().width + getPosition().x >= m_scene->GetEntity(i)->GetGlobalBounds().left && m_char.getGlobalBounds().left + getPosition().x <= m_scene->GetEntity(i)->GetGlobalBounds().left + m_scene->GetEntity(i)->GetGlobalBounds().width && m_char.getGlobalBounds().top + m_char.getGlobalBounds().height + getPosition().y <= m_scene->GetEntity(i)->GetGlobalBounds().top + m_scene->GetEntity(i)->GetGlobalBounds().height ) { TouchingBottom = true; } } } // Player Input if (Game::Get()->GetInputManager()->IsKeyDown(sf::Keyboard::Key::Up) && TouchingBottom) SetVelocity(GetVelocity().x, -50); if (Game::Get()->GetInputManager()->IsKeyPressed(sf::Keyboard::Key::Left)) SetVelocity(-20, GetVelocity().y); else if (Game::Get()->GetInputManager()->IsKeyPressed(sf::Keyboard::Key::Right)) SetVelocity(20, GetVelocity().y); else SetVelocity(0, GetVelocity().y); // Apply collision precautions if (!TouchingBottom) SetVelocity(GetVelocity().x, GetVelocity().y+10*Game::Get()->GetFrameTime()->asSeconds()*10); // Apply gravity else if (TouchingBottom && GetVelocity().y > 0) SetVelocity(GetVelocity().x, 0); // Apply frame movement move(GetVelocity().x * Game::Get()->GetFrameTime()->asSeconds()*10, GetVelocity().y * Game::Get()->GetFrameTime()->asSeconds()*10); }