|
|
|
#include "amt/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{
|
|
|
|
{8,8,8,8,8,8,8,8,8},
|
|
|
|
{8,0,2,0,0,0,0,0,8},
|
|
|
|
{8,0,7,0,0,5,6,0,8},
|
|
|
|
{8,0,0,0,0,0,0,0,8},
|
|
|
|
{8,8,0,0,0,0,0,8,8},
|
|
|
|
{8,0,0,1,3,4,0,0,8},
|
|
|
|
{8,0,0,0,0,0,8,8,8},
|
|
|
|
{8,0,0,0,0,0,0,0,8},
|
|
|
|
{8,8,8,8,8,8,8,8,8}
|
|
|
|
};
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
using KB = sf::Keyboard;
|
|
|
|
|
|
|
|
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 = MAP.rows() / 2;
|
|
|
|
float player_y = MAP.cols() / 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;
|
|
|
|
|
|
|
|
std::size_t const max_count = 100;
|
|
|
|
std::vector<double> frames(max_count);
|
|
|
|
std::size_t it = 1;
|
|
|
|
while(window.isOpen()) {
|
|
|
|
auto start = std::chrono::high_resolution_clock::now();
|
|
|
|
rayview.render();
|
|
|
|
auto end = std::chrono::high_resolution_clock::now();
|
|
|
|
auto elapsed = std::chrono::duration<double>(end - start);
|
|
|
|
auto frame = 1 / elapsed.count();
|
|
|
|
frames.push_back(frame);
|
|
|
|
if (it % max_count == 0) {
|
|
|
|
auto frame = std::accumulate(frames.begin(), frames.end(), 0., std::plus<>{}) / max_count;
|
|
|
|
std::cout << "Frame: " << frame << '\n';
|
|
|
|
frames.clear();
|
|
|
|
it = 1;
|
|
|
|
}
|
|
|
|
++it;
|
|
|
|
// DRAW GUI
|
|
|
|
window.display();
|
|
|
|
|
|
|
|
if(KB::isKeyPressed(KB::W)) {
|
|
|
|
rayview.run(moveSpeed, 1);
|
|
|
|
} else if(KB::isKeyPressed(KB::S)) {
|
|
|
|
rayview.run(moveSpeed, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(KB::isKeyPressed(KB::D)) {
|
|
|
|
rayview.rotate(rotSpeed, -1);
|
|
|
|
} else if(KB::isKeyPressed(KB::A)) {
|
|
|
|
rayview.rotate(rotSpeed, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
sf::Event event;
|
|
|
|
while(window.pollEvent(event)) {
|
|
|
|
if(event.type == sf::Event::Closed) {
|
|
|
|
window.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|