You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
1.8 KiB
74 lines
1.8 KiB
#include "raycaster.hpp"
|
|
#include <iostream>
|
|
#include <chrono>
|
|
#include <numeric>
|
|
#include <functional>
|
|
|
|
#define RAY_VIEW_WIDTH 960
|
|
#define RAY_VIEW_HEIGHT 720
|
|
#define RAY_VIEW_X (1280 - RAY_VIEW_WIDTH)
|
|
#define RAY_VIEW_Y 0
|
|
|
|
static const int SCREEN_HEIGHT=720;
|
|
static const int SCREEN_WIDTH=1280;
|
|
|
|
Matrix MAP{
|
|
{1,1,1,1,1,1,1,1,1},
|
|
{1,0,2,0,0,0,0,0,1},
|
|
{1,0,4,0,0,5,2,0,1},
|
|
{1,0,0,0,0,0,0,0,1},
|
|
{1,1,0,0,0,0,0,1,1},
|
|
{1,0,0,1,3,4,0,0,1},
|
|
{1,0,0,0,0,0,1,1,1},
|
|
{1,0,0,0,0,0,0,0,1},
|
|
{1,1,1,1,1,1,1,1,1}
|
|
};
|
|
|
|
void draw_gui(sf::RenderWindow &window) {
|
|
sf::RectangleShape rect({SCREEN_WIDTH - RAY_VIEW_WIDTH, 300});
|
|
rect.setPosition({0,0});
|
|
rect.setFillColor({100, 100, 100});
|
|
window.draw(rect);
|
|
}
|
|
|
|
int main() {
|
|
sf::RenderWindow window(sf::VideoMode({SCREEN_WIDTH, SCREEN_HEIGHT}), "Zed's Ray Caster Game Thing");
|
|
|
|
//ZED this should set with a function
|
|
float player_x = matrix::width(MAP) / 2;
|
|
float player_y = matrix::height(MAP) / 2;
|
|
|
|
Raycaster rayview(window, MAP, RAY_VIEW_WIDTH, RAY_VIEW_HEIGHT);
|
|
rayview.set_position(RAY_VIEW_X, RAY_VIEW_Y);
|
|
rayview.position_camera(player_x, player_y);
|
|
|
|
double moveSpeed = 0.1;
|
|
double rotSpeed = 0.1;
|
|
|
|
const auto onClose = [&window](const sf::Event::Closed&)
|
|
{
|
|
window.close();
|
|
};
|
|
|
|
while(window.isOpen()) {
|
|
rayview.render();
|
|
draw_gui(window);
|
|
window.display();
|
|
|
|
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::W)) {
|
|
rayview.run(moveSpeed, 1);
|
|
} else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::S)) {
|
|
rayview.run(moveSpeed, -1);
|
|
}
|
|
|
|
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::D)) {
|
|
rayview.rotate(rotSpeed, -1);
|
|
} else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::A)) {
|
|
rayview.rotate(rotSpeed, 1);
|
|
}
|
|
|
|
window.handleEvents(onClose);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|