1
0
Fork 0
Toy-Raytracer/main.cpp

82 lines
2.4 KiB
C++
Raw Normal View History

2019-05-27 13:50:49 +02:00
#include <iostream>
#include <SFML/Graphics.hpp>
2019-05-27 13:50:49 +02:00
#include "World.h"
// TODO: Find a way to go to edges instead of just equally split (?)
2019-05-27 13:50:49 +02:00
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);
2019-05-27 13:50:49 +02:00
std::cout << world << std::endl;
sf::RenderWindow window(sf::VideoMode(800,600),"Da raycasting");
sf::RenderWindow window(sf::VideoMode(1000,1000),"Da raycasting");
sf::Event event{};
sf::Clock frameTime;
while (window.isOpen())
{
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed) {
window.close();
continue;
}
if (event.type == sf::Event::Resized) {
// Keep the view area fit to the window.
sf::FloatRect newView(0, 0,
static_cast<float>(event.size.width),
static_cast<float>(event.size.height));
window.setView(sf::View(newView));
continue;
}
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();
}
2019-05-27 13:50:49 +02:00
return 0;
}