Transitioned to SFML for keyboard input

This commit is contained in:
Functioning Member of Society 2022-10-30 18:19:59 -04:00
parent 5471f17bad
commit 04ad3afe7d

View File

@ -9,8 +9,7 @@
#include <cstdio>
#include "FastNoiseLite.h"
#include <random>
//#include <SFML/System.hpp>
//#include <SFML/Window.hpp>
#include <SFML/Window.hpp>
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();