diff --git a/raycaster.cpp b/raycaster.cpp index 5891cc3..aae5759 100644 --- a/raycaster.cpp +++ b/raycaster.cpp @@ -112,47 +112,50 @@ void ray_casting(sf::RenderWindow &window, Matrix& map) { } } +void draw_ceiling_floor(sf::RenderWindow &window) { + draw_rect(window, + {SCREEN_HEIGHT, SCREEN_HEIGHT /2}, + {SCREEN_HEIGHT, SCREEN_HEIGHT}, + 100); + draw_rect(window, + {SCREEN_HEIGHT, (SCREEN_HEIGHT * -1) / 2}, + {SCREEN_HEIGHT, SCREEN_HEIGHT}, + 200); +} + +void draw_everything(sf::RenderWindow &window) { + draw_map(window, MAP); + draw_ceiling_floor(window); + ray_casting(window, MAP); + window.display(); +} + int main() { + using KB = sf::Keyboard; sf::RenderWindow window(sf::VideoMode(SCREEN_WIDTH, SCREEN_HEIGHT), "Raycaster"); window.setVerticalSyncEnabled(true); while(window.isOpen()) { - sf::Event event; + draw_everything(window); - draw_map(window, MAP); - - draw_rect(window, - {480, SCREEN_HEIGHT /2}, - {SCREEN_HEIGHT, SCREEN_HEIGHT}, - 100); - - draw_rect(window, - {480, (SCREEN_HEIGHT * -1) / 2}, - {SCREEN_HEIGHT, SCREEN_HEIGHT}, - 200); - - ray_casting(window, MAP); + if(KB::isKeyPressed(KB::A)) { + player_angle -= 0.1; + } else if(KB::isKeyPressed(KB::D)) { + player_angle += 0.1; + } - window.display(); + if(KB::isKeyPressed(KB::W)) { + player_x += -1 * std::sin(player_angle) * 5; + player_y += std::cos(player_angle) * 5; + } else if(KB::isKeyPressed(KB::S)) { + player_x -= -1 * std::sin(player_angle) * 5; + player_y -= std::cos(player_angle) * 5; + } + sf::Event event; while(window.pollEvent(event)) { - using KB = sf::Keyboard; - if(event.type == sf::Event::Closed) { window.close(); - } else if(event.type == sf::Event::KeyPressed) { - if(KB::isKeyPressed(KB::Left)) { - player_angle -= 0.1; - } else if(KB::isKeyPressed(KB::Right)) { - player_angle += 0.1; - } else if(KB::isKeyPressed(KB::Up)) { - player_x += -1 * std::sin(player_angle) * 5; - player_y += std::cos(player_angle) * 5; - } else if(KB::isKeyPressed(KB::Down)) { - player_x -= -1 * std::sin(player_angle) * 5; - player_y -= std::cos(player_angle) * 5; - - } } } }