|
|
|
@ -130,6 +130,13 @@ void draw_everything(sf::RenderWindow &window) { |
|
|
|
|
window.display(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool collision(float x, float y) { |
|
|
|
|
int col = int(x / TILE_SIZE); |
|
|
|
|
int row = int(y / TILE_SIZE); |
|
|
|
|
|
|
|
|
|
return MAP[row][col] == 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int main() { |
|
|
|
|
using KB = sf::Keyboard; |
|
|
|
|
sf::RenderWindow window(sf::VideoMode(SCREEN_WIDTH, SCREEN_HEIGHT), "Raycaster"); |
|
|
|
@ -138,6 +145,9 @@ int main() { |
|
|
|
|
while(window.isOpen()) { |
|
|
|
|
draw_everything(window); |
|
|
|
|
|
|
|
|
|
float x = player_x; |
|
|
|
|
float y = player_y; |
|
|
|
|
|
|
|
|
|
if(KB::isKeyPressed(KB::A)) { |
|
|
|
|
player_angle -= 0.1; |
|
|
|
|
} else if(KB::isKeyPressed(KB::D)) { |
|
|
|
@ -145,11 +155,16 @@ int main() { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(KB::isKeyPressed(KB::W)) { |
|
|
|
|
player_x += -1 * std::sin(player_angle) * 5; |
|
|
|
|
player_y += std::cos(player_angle) * 5; |
|
|
|
|
x += -1 * std::sin(player_angle) * 5; |
|
|
|
|
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; |
|
|
|
|
x -= -1 * std::sin(player_angle) * 5; |
|
|
|
|
y -= std::cos(player_angle) * 5; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(!collision(x, y)) { |
|
|
|
|
player_x = x; |
|
|
|
|
player_y = y; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sf::Event event; |
|
|
|
|