1
0
Fork 0
Toy-Raytracer/main.cpp
Teo-CD b47052aa4d Implement moving the player
Player: Add rotation and linear speeds, as well as their current state.
Player: Allow to move in the local coordinates and compute
    world-speed equivalent.
Player: Update movement axis while rotating.

World: Add a function to advance a step.
Main: Handle key events, add world step in the main loop.
2024-01-21 22:11:46 +00:00

72 lines
2.1 KiB
C++

#include <iostream>
#include <SFML/Graphics.hpp>
#include "World.h"
// TODO: Find a way to go to edges instead of just equally split (?)
int main()
{
World world(10,10);
world.setBlock(BlockType::AIR,1,1,8,8);
world.setBlock(BlockType::WALL,4,4,2,2);
world.player.move(2,2);
std::cout << world << std::endl;
sf::RenderWindow window(sf::VideoMode(800,600),"Da raycasting");
world.render(window);
window.display();
sf::Event event{};
sf::Clock frameTime;
while (window.isOpen())
{
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
else if (event.type == sf::Event::KeyPressed) {
switch (event.key.code) {
case sf::Keyboard::Key::Escape:
window.close();
break;
case sf::Keyboard::Key::Left:
world.player.currentRotationSpeed = -world.player.rotationSpeed;
break;
case sf::Keyboard::Key::Right:
world.player.currentRotationSpeed = world.player.rotationSpeed;
break;
case sf::Keyboard::Key::Up:
world.player.updateSpeed(1, 0);
break;
case sf::Keyboard::Key::Down:
world.player.updateSpeed(-1, 0);
break;
default:
break;
}
}
else if (event.type == sf::Event::KeyReleased) {
switch (event.key.code) {
case sf::Keyboard::Key::Left:
case sf::Keyboard::Key::Right:
world.player.currentRotationSpeed = 0;
break;
case sf::Keyboard::Key::Up:
case sf::Keyboard::Key::Down:
world.player.updateSpeed(0, 0);
break;
default:
break;
}
}
}
window.clear();
world.step(frameTime.restart().asSeconds());
world.render(window);
window.display();
}
return 0;
}