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 <cstdio>
#include "FastNoiseLite.h" #include "FastNoiseLite.h"
#include <random> #include <random>
//#include <SFML/System.hpp> #include <SFML/Window.hpp>
//#include <SFML/Window.hpp>
NodeRenderer renderer; NodeRenderer renderer;
//BlockManager blockManager; //BlockManager blockManager;
@ -49,12 +48,6 @@ void display()
{ {
for(int z = 0; z < 64; z++) 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) if(blockManager.getNodeAt(x, y, z) > 0)
{ {
textureHandler.getTextureForNode(x, y, z); textureHandler.getTextureForNode(x, y, z);
@ -92,79 +85,57 @@ void reshape(int width, int height)
void updateTimer(int time) void updateTimer(int time)
{ {
glutPostRedisplay(); // Movement
glutTimerFunc(30, &updateTimer, 0); if(sf::Keyboard::isKeyPressed(sf::Keyboard::W))
}
void KeyboardFunc(unsigned char key, int x, int y)
{
if(key == 'a')
{
playerX += .8F;
}
if(key == 'd')
{
playerX -= .8F;
}
if(key == 'w')
{ {
playerZ += .8; playerZ += .8;
} }
if(key == 's') else if(sf::Keyboard::isKeyPressed(sf::Keyboard::S))
{ {
playerZ -= .8; 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(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
if(key == 27)
{ {
exit(0); exit(0);
} }
glutPostRedisplay();
glutTimerFunc(30, &updateTimer, 0);
} }
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
glutInit(&argc, argv); glutInit(&argc, argv);
@ -240,7 +211,6 @@ int main(int argc, char **argv)
updateTimer(0); updateTimer(0);
glutDisplayFunc(&display); glutDisplayFunc(&display);
glutReshapeFunc(&reshape); glutReshapeFunc(&reshape);
glutKeyboardFunc(&KeyboardFunc);
glutMainLoop(); glutMainLoop();