breaking changes: optimizing code and added .clang-format
This commit is contained in:
+73
-81
@@ -1,25 +1,25 @@
|
||||
#include <SFML/Audio.hpp>
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include <SFML/Graphics/RectangleShape.hpp>
|
||||
#include <SFML/System.hpp>
|
||||
#include <SFML/System/Vector2.hpp>
|
||||
#include <SFML/Window.hpp>
|
||||
#include <SFML/System.hpp>
|
||||
#include <SFML/Window/Mouse.hpp>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <iostream>
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <range/v3/view/iota.hpp>
|
||||
#include <range/v3/view/cartesian_product.hpp>
|
||||
#include <range/v3/view/iota.hpp>
|
||||
#else
|
||||
#include <ranges>
|
||||
#endif
|
||||
|
||||
#include "globals.hpp"
|
||||
#include "elements.hpp"
|
||||
#include "globals.hpp"
|
||||
#include "maps.hpp"
|
||||
#include "scheduler.hpp"
|
||||
|
||||
@@ -31,120 +31,112 @@ int main() {
|
||||
sf::Vector2i end_mouse_pos;
|
||||
bool dragging = false;
|
||||
bool prev_dragging = false;
|
||||
// int current_level = 0;
|
||||
// struct {
|
||||
// sf::Vector2<float> size { TILESIZE / 2.0f, TILESIZE / 2.0f };
|
||||
// sf::Vector2<float> pos { TILESIZE, TILESIZE };
|
||||
// float max_velocity_y { 15.0f };
|
||||
// float border_size { -1.0f };
|
||||
// float dash_distance { 20.0f };
|
||||
// sf::Vector2f velocity { 3.0f, 0 };
|
||||
// } player_data;
|
||||
int current_level = 0;
|
||||
|
||||
load_map(wall_list, test_level_0);
|
||||
load_map(wall_list, );
|
||||
|
||||
// Player player {
|
||||
// player_data.size, player_data.pos, player_data.velocity,
|
||||
// player_data.border_size, GRAVITY, player_data.max_velocity_y,
|
||||
// player_data.dash_distance, sf::Color::Black, sf::Color::White
|
||||
// };
|
||||
player_data player_data;
|
||||
Player player { player_data.size, player_data.pos, player_data.velocity,
|
||||
player_data.border_size, GRAVITY, player_data.max_velocity_y,
|
||||
player_data.dash_distance, sf::Color::Black, sf::Color::White };
|
||||
|
||||
sf::RenderWindow window(sf::VideoMode({WIDTH, HEIGHT}), "engine", sf::Style::Default);
|
||||
sf::RenderWindow window(sf::VideoMode({ WIDTH, HEIGHT }), "engine", sf::Style::Default);
|
||||
window.setFramerateLimit(FPS);
|
||||
|
||||
#ifdef __APPLE__
|
||||
sf::Font font("/Users/andrewhaynes/personal/Projects/CPP/engine/assets/pixel.ttf");
|
||||
sf::Font font("/Users/andrew/personal/Projects/CPP/engine/assets/pixel.ttf");
|
||||
#else
|
||||
sf::Font font("/home/andrew/personal/Projects/CPP/engine/assets/pixel.ttf");
|
||||
#endif
|
||||
|
||||
sf::Text text(font, "0, 0", 16);
|
||||
text.setPosition({ WIDTH - (TILESIZE * 11.5), HEIGHT - (int)(TILESIZE / 1.5)});
|
||||
text.setPosition({ WIDTH - (TILESIZE * 11.5), HEIGHT - (int)(TILESIZE / 1.5) });
|
||||
|
||||
// bool running = true;
|
||||
// std::thread player_dash_cooldown([&] { time.update_timers(running, player.timers); } );
|
||||
bool running = true;
|
||||
std::thread player_dash_cooldown([&] { time.update_timers(running, player.timers); });
|
||||
while (window.isOpen()) {
|
||||
local_position = sf::Mouse::getPosition(window);
|
||||
window.clear(sf::Color::Black);
|
||||
text.setString(std::to_string((int)std::floor(local_position.x / 32)) + ", " + std::to_string((int)std::floor(local_position.y / 32)));
|
||||
text.setString(std::to_string((int)std::floor(local_position.x / 32)) + ", " +
|
||||
std::to_string((int)std::floor(local_position.y / 32)));
|
||||
while (const std::optional event = window.pollEvent()) {
|
||||
if (event->is<sf::Event::Closed>()) {
|
||||
// running = false;
|
||||
running = false;
|
||||
window.close();
|
||||
}
|
||||
}
|
||||
|
||||
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Escape)) {
|
||||
// running = false;
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Escape)) {
|
||||
running = false;
|
||||
window.close();
|
||||
}
|
||||
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::B)) {
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::B)) {
|
||||
clear_map(wall_list);
|
||||
}
|
||||
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::A)) {
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::A)) {
|
||||
dragging = false;
|
||||
}
|
||||
create_map(window, local_position, start_mouse_pos, end_mouse_pos, dragging, prev_dragging, wall_list);
|
||||
|
||||
// if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Enter) && player.timers.level_switch_cooldown <= 0) {
|
||||
// clear_map(wall_list);
|
||||
// if(current_level == 0) {
|
||||
// load_map(wall_list, test_level_1);
|
||||
// current_level = 1;
|
||||
// player.timers.level_switch_cooldown = player.timers.level_switch_cooldown_max;
|
||||
// }
|
||||
// else if(current_level == 1) {
|
||||
// load_map(wall_list, test_level_2);
|
||||
// current_level = 2;
|
||||
// player.timers.level_switch_cooldown = player.timers.level_switch_cooldown_max;
|
||||
// }
|
||||
// else if(current_level == 2) {
|
||||
// load_map(wall_list, test_level_0);
|
||||
// current_level = 0;
|
||||
// player.timers.level_switch_cooldown = player.timers.level_switch_cooldown_max;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// player.handle_movment();
|
||||
// if(!player.get_horizontal_collision(wall_list)) {
|
||||
// std::cout << "\n";
|
||||
// }
|
||||
// else {
|
||||
// std::cout << "Yes horizontal collision\n";
|
||||
// }
|
||||
//
|
||||
// player.handle_gravity();
|
||||
// if(player.get_velocity().y > ((float)TILESIZE / 2 - GRAVITY)) {
|
||||
// player.set_velocity_y((TILESIZE / 2) - GRAVITY);
|
||||
// }
|
||||
// if(!player.get_vertical_bottom_collision(wall_list)) {
|
||||
// std::cout << "\n";
|
||||
// if(!player.get_vertical_top_collision(wall_list)) {
|
||||
// std::cout << "\n";
|
||||
// } else {
|
||||
// std::cout << "Yes vertical top collision\n";
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
// std::cout << "Yes vertical bottom collision\n";
|
||||
// }
|
||||
//
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Enter) && player.timers.level_switch_cooldown <= 0) {
|
||||
clear_map(wall_list);
|
||||
if (current_level == 0) {
|
||||
load_map(wall_list, test_level_1);
|
||||
current_level = 1;
|
||||
player.timers.level_switch_cooldown = player.timers.level_switch_cooldown_max;
|
||||
} else if (current_level == 1) {
|
||||
load_map(wall_list, test_level_2);
|
||||
current_level = 2;
|
||||
player.timers.level_switch_cooldown = player.timers.level_switch_cooldown_max;
|
||||
} else if (current_level == 2) {
|
||||
load_map(wall_list, test_level_0);
|
||||
current_level = 0;
|
||||
player.timers.level_switch_cooldown = player.timers.level_switch_cooldown_max;
|
||||
}
|
||||
}
|
||||
|
||||
player.handle_movment();
|
||||
if (!player.get_horizontal_collision(wall_list)) {
|
||||
std::cout << "\n";
|
||||
} else {
|
||||
std::cout << "Yes horizontal collision\n";
|
||||
}
|
||||
|
||||
player.handle_gravity();
|
||||
if (player.get_velocity().y > ((float)TILESIZE / 2 - GRAVITY)) {
|
||||
player.set_velocity_y((TILESIZE / 2) - GRAVITY);
|
||||
}
|
||||
if (!player.get_vertical_bottom_collision(wall_list)) {
|
||||
std::cout << "\n";
|
||||
if (!player.get_vertical_top_collision(wall_list)) {
|
||||
std::cout << "\n";
|
||||
} else {
|
||||
std::cout << "Yes vertical top collision\n";
|
||||
}
|
||||
} else {
|
||||
std::cout << "Yes vertical bottom collision\n";
|
||||
}
|
||||
|
||||
#ifdef __APPLE__
|
||||
for(auto[i, j] : ranges::views::cartesian_product(ranges::views::iota(0, MAX_ROWS), ranges::views::iota(0, MAX_COLS))) {
|
||||
if(wall_list[i][j] == nullptr) continue;
|
||||
window.draw(wall_list[i][j]->rect);
|
||||
for (auto [i, j] : ranges::views::cartesian_product(ranges::views::iota(0, MAX_ROWS),
|
||||
ranges::views::iota(0, MAX_COLS))) {
|
||||
if (wall_list[i][j] == nullptr)
|
||||
continue;
|
||||
window.draw(wall_list[i][j]->rect);
|
||||
}
|
||||
#else
|
||||
for(auto[i, j] : std::views::cartesian_product(std::views::iota(0, MAX_ROWS), std::views::iota(0, MAX_COLS))) {
|
||||
if(wall_list[i][j] == nullptr) continue;
|
||||
window.draw(wall_list[i][j]->rect);
|
||||
for (auto [i, j] :
|
||||
std::views::cartesian_product(std::views::iota(0, MAX_ROWS), std::views::iota(0, MAX_COLS))) {
|
||||
if (wall_list[i][j] == nullptr)
|
||||
continue;
|
||||
window.draw(wall_list[i][j]->rect);
|
||||
}
|
||||
#endif
|
||||
// window.draw(player.rect);
|
||||
window.draw(player.rect);
|
||||
window.draw(text);
|
||||
window.display();
|
||||
}
|
||||
clear_map(wall_list);
|
||||
// player_dash_cooldown.join();
|
||||
player_dash_cooldown.join();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user