diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..bdcd5c9 Binary files /dev/null and b/.DS_Store differ diff --git a/assets/pixel.ttf b/assets/pixel.ttf new file mode 100644 index 0000000..2442aff Binary files /dev/null and b/assets/pixel.ttf differ diff --git a/src/main.cpp b/src/main.cpp index 999a2f5..b875b6b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -72,12 +72,11 @@ int main() { }; Entity line { line_data.size, line_data.pos, line_data.velocity, line_data.border_size, sf::Color::White }; - // Entity test_square { simulated_data.size, simulated_data.pos, simulated_data.velocity, simulated_data.border_size, sf::Color::Black }; sf::RenderWindow window(sf::VideoMode({WIDTH, HEIGHT}), "SFML window", sf::Style::Default); window.setFramerateLimit(60); - sf::Font font("pixel.ttf"); + sf::Font font("/Users/andrewhaynes/personal/Projects/CPP/SFML_game_engine/assets/pixel.ttf"); sf::Text text(font, "0, 0", 16); text.setPosition({ WIDTH - (TILESIZE * 11.5), HEIGHT - (int)(TILESIZE / 1.5)}); @@ -93,28 +92,43 @@ int main() { window.close(); } - // FOR TESTING - // if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Space)) { - // if(test_square.rect.getPosition().x < 30) { - // test_square.set_velocity({ 20, 0 }); - // } - // if(test_square.rect.getPosition().x > WIDTH - 30) { - // test_square.set_velocity({ -20, 0 }); - // } - // } - // player.handle_movment(); + for(int i = 0; i < MAX_ROWS; i++) { + for(int j = 0; j < MAX_COLS; j++) { + if(wall_list[i][j] == nullptr) continue; + auto collision = wall_list[i][j]->find_intersection(player); + if(collision == CollisionDir::None) continue; + switch (collision) { + case CollisionDir::Left: + player.rect.setPosition({ wall_list[i][j]->rect.getPosition().x - player.rect.getSize().x, player.rect.getPosition().y }); + break; + case CollisionDir::Right: + player.rect.setPosition({ wall_list[i][j]->rect.getPosition().x + wall_list[i][j]->rect.getSize().x, player.rect.getPosition().y }); + break; + default: break; + } + } + } player.set_velocity_y(player.get_velocity().y + player.m_acceleration); player.rect.move({0, player.get_velocity().y}); - - // test_square.set_velocity_y(test_square.get_velocity().y + 1); - // if(test_square.get_velocity().x > 0) { - // test_square.set_velocity_x(test_square.get_velocity().x - 1); - // } - // if(test_square.get_velocity().x < 0) { - // test_square.set_velocity_x(test_square.get_velocity().x + 1); - // } - // test_square.rect.move({ test_square.get_velocity().x, test_square.get_velocity().y }); + for(int i = 0; i < MAX_ROWS; i++) { + for(int j = 0; j < MAX_COLS; j++) { + if(wall_list[i][j] == nullptr) continue; + auto collision = wall_list[i][j]->find_intersection(player); + if(collision == CollisionDir::None) continue; + switch (collision) { + case CollisionDir::Bottom: + player.rect.setPosition({ player.rect.getPosition().x, wall_list[i][j]->rect.getPosition().y - player.rect.getSize().y }); + player.set_velocity_y(0); + break; + case CollisionDir::Top: + player.rect.setPosition({ player.rect.getPosition().x, wall_list[i][j]->rect.getPosition().y + player.rect.getSize().y }); + player.set_velocity_y(0); + break; + default: break; + } + } + } float groundY = line.rect.getPosition().y - line.rect.getSize().y - player.rect.getSize().y - line_data.border_size - player_data.border_size; if (player.rect.getPosition().y >= groundY) { @@ -130,60 +144,6 @@ int main() { player.rect.setPosition({ 0, player.rect.getPosition().y}); } - // float right_border_rect = WIDTH - test_square.rect.getSize().x; - // float groundY_rect = line.rect.getPosition().y - line.rect.getSize().y - test_square.rect.getSize().y - line_data.border_size - simulated_data.border_size; - // if(test_square.rect.getPosition().x > right_border_rect) { - // test_square.rect.setPosition({ right_border_rect, test_square.rect.getPosition().y }); - // test_square.set_velocity({ -20, 0 }); - // } - // if(test_square.rect.getPosition().x < std::abs(test_square.rect.getOutlineThickness())) { - // test_square.rect.setPosition({ 0, test_square.rect.getPosition().y }); - // test_square.set_velocity({ 20, 0 }); - // } - // if(test_square.rect.getPosition().y >= groundY_rect) { - // test_square.rect.setPosition({ test_square.rect.getPosition().x, groundY_rect }); - // } - - // auto collision = player.find_intersection(test_square); - // switch (collision) { - // case CollisionDir::Top: - // test_square.set_velocity({ 0, -20 }); - // break; - // case CollisionDir::Bottom: - // test_square.set_velocity({ 0, -20 }); - // break; - // case CollisionDir::Left: - // test_square.set_velocity({ -20, 0 }); - // break; - // case CollisionDir::Right: - // test_square.set_velocity({ 20, 0 }); - // break; - // default: break; - // } - for(int i = 0; i < MAX_ROWS; i++) { - for(int j = 0; j < MAX_COLS; j++) { - if(wall_list[i][j] == nullptr) continue; - auto collision = wall_list[i][j]->find_intersection(player); - switch (collision) { - case CollisionDir::Bottom: - player.rect.setPosition({ player.rect.getPosition().x, wall_list[i][j]->rect.getPosition().y + player.rect.getSize().y }); - // player.set_velocity_y(0); - break; - case CollisionDir::Top: - player.rect.setPosition({ player.rect.getPosition().x, wall_list[i][j]->rect.getPosition().y - player.rect.getSize().y }); - // player.set_velocity_y(0); - break; - case CollisionDir::Left: - player.rect.setPosition({ wall_list[i][j]->rect.getPosition().x - player.rect.getSize().x, player.rect.getPosition().y }); - break; - case CollisionDir::Right: - player.rect.setPosition({ wall_list[i][j]->rect.getPosition().x + wall_list[i][j]->rect.getSize().x, player.rect.getPosition().y }); - break; - default: break; - } - } - } - for(int i = 0; i < MAX_ROWS; i++) { for(int j = 0; j < MAX_COLS; j++) { if(wall_list[i][j] != nullptr) { @@ -192,7 +152,6 @@ int main() { } } window.draw(player.rect); - // window.draw(test_square.rect); window.draw(line.rect); window.draw(text); window.display();