From 04ad3afe7dc401b4d678ac8a57de32496a0f208f Mon Sep 17 00:00:00 2001 From: Migdyn Date: Sun, 30 Oct 2022 18:19:59 -0400 Subject: [PATCH] Transitioned to SFML for keyboard input --- main.cpp | 70 ++++++++++++++++---------------------------------------- 1 file changed, 20 insertions(+), 50 deletions(-) diff --git a/main.cpp b/main.cpp index 4bc2687..6a22b88 100644 --- a/main.cpp +++ b/main.cpp @@ -9,8 +9,7 @@ #include #include "FastNoiseLite.h" #include -//#include -//#include +#include NodeRenderer renderer; //BlockManager blockManager; @@ -49,12 +48,6 @@ void display() { for(int z = 0; z < 64; z++) { - - - // Math explanation for future reference: - // The if statement below checks if the node at the coordinate is greater than 0 (0 = air), the x and z coordinates - // need to be have block.[AXIS] * 16 subtracted from them so that the coordinates passed to the function are local - // block coordinates instead of global node coordinates (e.g. 1, and not 17) if(blockManager.getNodeAt(x, y, z) > 0) { textureHandler.getTextureForNode(x, y, z); @@ -92,79 +85,57 @@ void reshape(int width, int height) void updateTimer(int time) { - glutPostRedisplay(); - glutTimerFunc(30, &updateTimer, 0); -} - -void KeyboardFunc(unsigned char key, int x, int y) -{ - if(key == 'a') - { - playerX += .8F; - } - - if(key == 'd') - { - playerX -= .8F; - } - - if(key == 'w') + // Movement + if(sf::Keyboard::isKeyPressed(sf::Keyboard::W)) { playerZ += .8; } - if(key == 's') + else if(sf::Keyboard::isKeyPressed(sf::Keyboard::S)) { playerZ -= .8; } - if(key == 'q') + if(sf::Keyboard::isKeyPressed(sf::Keyboard::A)) { - playerY += .8F; + playerX += .8; } - if(key == 'e') + else if(sf::Keyboard::isKeyPressed(sf::Keyboard::D)) { - playerY -= .8F; + playerX -= .8; } - if(key == 't') + // Rotation + if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) { - playerRotX -= .8F; + playerRotY -= .8; } - if(key == 'g') + else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) { - playerRotX += .8F; + playerRotY += .8; } - if(key == 'f') + if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) { - playerRotY -= .8F; + playerRotX -= .8; } - if(key == 'h') + else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) { - playerRotY += .8F; + playerRotX += .8; } - - - - if(key == 27) + if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) { exit(0); } - + glutPostRedisplay(); + glutTimerFunc(30, &updateTimer, 0); } - - - - - - int main(int argc, char **argv) { glutInit(&argc, argv); @@ -240,7 +211,6 @@ int main(int argc, char **argv) updateTimer(0); glutDisplayFunc(&display); glutReshapeFunc(&reshape); - glutKeyboardFunc(&KeyboardFunc); glutMainLoop();