Raycaster is smoother without changing much. Big debate is should left-right and forward-back at the same time cancel out motion or should they be exclusive since you can't do both.

master
Zed A. Shaw 10 months ago
parent bf77723f70
commit cf539296a5
  1. 47
      raycaster.cpp

@ -112,47 +112,50 @@ 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;
draw_map(window, MAP);
void draw_ceiling_floor(sf::RenderWindow &window) {
draw_rect(window,
{480, SCREEN_HEIGHT /2},
{SCREEN_HEIGHT, SCREEN_HEIGHT /2},
{SCREEN_HEIGHT, SCREEN_HEIGHT},
100);
draw_rect(window,
{480, (SCREEN_HEIGHT * -1) / 2},
{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();
}
while(window.pollEvent(event)) {
int main() {
using KB = sf::Keyboard;
sf::RenderWindow window(sf::VideoMode(SCREEN_WIDTH, SCREEN_HEIGHT), "Raycaster");
window.setVerticalSyncEnabled(true);
if(event.type == sf::Event::Closed) {
window.close();
} else if(event.type == sf::Event::KeyPressed) {
if(KB::isKeyPressed(KB::Left)) {
while(window.isOpen()) {
draw_everything(window);
if(KB::isKeyPressed(KB::A)) {
player_angle -= 0.1;
} else if(KB::isKeyPressed(KB::Right)) {
} else if(KB::isKeyPressed(KB::D)) {
player_angle += 0.1;
} else if(KB::isKeyPressed(KB::Up)) {
}
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::Down)) {
} 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)) {
if(event.type == sf::Event::Closed) {
window.close();
}
}
}