Small tweak to allow changing the map, and then added a hirdrac suggestion to vsync.
This commit is contained in:
parent
d5a372e751
commit
ec332a3e2d
1 changed files with 15 additions and 14 deletions
|
@ -8,9 +8,21 @@
|
|||
using matrix::Matrix;
|
||||
using namespace fmt;
|
||||
|
||||
Matrix MAP{
|
||||
{1,1,1,1,1,1,1,1,1},
|
||||
{1,0,1,0,0,0,0,0,1},
|
||||
{1,0,1,0,0,1,1,0,1},
|
||||
{1,0,0,0,0,0,0,0,1},
|
||||
{1,1,0,0,0,0,0,0,1},
|
||||
{1,0,0,1,1,1,0,0,1},
|
||||
{1,0,0,0,1,0,0,0,1},
|
||||
{1,0,0,0,0,0,1,1,1},
|
||||
{1,1,1,1,1,1,1,1,1}
|
||||
};
|
||||
|
||||
const int SCREEN_HEIGHT=480;
|
||||
const int SCREEN_WIDTH=SCREEN_HEIGHT * 2;
|
||||
const int MAP_SIZE=8;
|
||||
const int MAP_SIZE=matrix::width(MAP);
|
||||
const int TILE_SIZE=(SCREEN_WIDTH/2) / MAP_SIZE;
|
||||
const float FOV = std::numbers::pi / 3.0;
|
||||
const float HALF_FOV = FOV / 2;
|
||||
|
@ -19,17 +31,6 @@ const float STEP_ANGLE = FOV / CASTED_RAYS;
|
|||
const int MAX_DEPTH = MAP_SIZE * TILE_SIZE;
|
||||
const float SCALE = (SCREEN_WIDTH / 2) / CASTED_RAYS;
|
||||
|
||||
Matrix MAP{
|
||||
{1,1,1,1,1,1,1,1},
|
||||
{1,0,1,0,0,0,0,1},
|
||||
{1,0,1,0,0,1,1,1},
|
||||
{1,0,0,0,0,0,0,1},
|
||||
{1,1,0,0,0,0,0,1},
|
||||
{1,0,0,1,1,1,0,1},
|
||||
{1,0,0,0,1,0,0,1},
|
||||
{1,1,1,1,1,1,1,1}
|
||||
};
|
||||
|
||||
float player_x = SCREEN_WIDTH / 4;
|
||||
float player_y = SCREEN_WIDTH / 4;
|
||||
float player_angle = std::numbers::pi;
|
||||
|
@ -44,7 +45,7 @@ void draw_rect(sf::RenderWindow &window, sf::Vector2f pos, sf::Vector2f size, ui
|
|||
void draw_map_rect(sf::RenderWindow &window, int x, int y, uint8_t color) {
|
||||
draw_rect(window,
|
||||
{float(x * TILE_SIZE), float(y * TILE_SIZE)},
|
||||
{TILE_SIZE-1, TILE_SIZE-1},
|
||||
{float(TILE_SIZE-1), float(TILE_SIZE-1)},
|
||||
color);
|
||||
}
|
||||
|
||||
|
@ -107,6 +108,7 @@ void ray_casting(sf::RenderWindow &window, Matrix& map) {
|
|||
|
||||
int main() {
|
||||
sf::RenderWindow window(sf::VideoMode(SCREEN_WIDTH, SCREEN_HEIGHT), "Raycaster");
|
||||
window.setVerticalSyncEnabled(true);
|
||||
|
||||
while(window.isOpen()) {
|
||||
sf::Event event;
|
||||
|
@ -125,7 +127,6 @@ int main() {
|
|||
|
||||
ray_casting(window, MAP);
|
||||
|
||||
|
||||
window.display();
|
||||
|
||||
while(window.pollEvent(event)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue