Skip to content

Commit

Permalink
Make player use the keyboard class
Browse files Browse the repository at this point in the history
  • Loading branch information
Hopson97 committed Jul 28, 2019
1 parent 758451a commit 2598b8b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions Source/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ void Application::handleEvents()
sf::Event e;
while (m_context.window.pollEvent(e))
{
m_states.back()->handleEvent(e);
switch(e.type)
{
case sf::Event::Closed:
Expand Down
12 changes: 6 additions & 6 deletions Source/Player/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,34 +208,34 @@ float speed = 0.2f;

void Player::keyboardInput(Keyboard& keyboard)
{
if (sf::Keyboard::isKeyPressed(sf::Keyboard::W))
if (keyboard.isKeyDown(sf::Keyboard::W))
{
float s = speed;
if (sf::Keyboard::isKeyPressed(sf::Keyboard::LControl)) s *= 5;
m_acceleration.x += -glm::cos(glm::radians(rotation.y + 90)) * s;
m_acceleration.z += -glm::sin(glm::radians(rotation.y + 90)) * s;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::S))
if (keyboard.isKeyDown(sf::Keyboard::S))
{
m_acceleration.x += glm::cos(glm::radians(rotation.y + 90)) * speed;
m_acceleration.z += glm::sin(glm::radians(rotation.y + 90)) * speed;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::A))
if (keyboard.isKeyDown(sf::Keyboard::A))
{
m_acceleration.x += -glm::cos(glm::radians(rotation.y)) * speed;
m_acceleration.z += -glm::sin(glm::radians(rotation.y)) * speed;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::D))
if (keyboard.isKeyDown(sf::Keyboard::D))
{
m_acceleration.x += glm::cos(glm::radians(rotation.y)) * speed;
m_acceleration.z += glm::sin(glm::radians(rotation.y)) * speed;
}

if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space))
if (keyboard.isKeyDown(sf::Keyboard::Space))
{
jump();
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::LShift) && m_isFlying)
else if (keyboard.isKeyDown(sf::Keyboard::LShift) && m_isFlying)
{
m_acceleration.y -= speed * 3;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/World/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ World::World(const Camera& camera, const Config& config, Player& player)
setSpawnPoint();
player.position = m_playerSpawnPoint;

for (int i = 0; i < 2; i++)
for (int i = 0; i < 1; i++)
{
std::this_thread::sleep_for(std::chrono::milliseconds(50));
m_chunkLoadThreads.emplace_back([&]()
Expand Down

0 comments on commit 2598b8b

Please sign in to comment.