fixes and optimizations
This commit is contained in:
+15
-32
@@ -5,17 +5,17 @@
|
||||
#include <SFML/System/Vector2.hpp>
|
||||
#include <SFML/Window.hpp>
|
||||
#include <SFML/Window/Mouse.hpp>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <range/v3/view/cartesian_product.hpp>
|
||||
#include <range/v3/view/iota.hpp>
|
||||
namespace rv = ranges::views;
|
||||
#else
|
||||
#include <ranges>
|
||||
namespace rv = std::views;
|
||||
#endif
|
||||
|
||||
#include "elements.hpp"
|
||||
@@ -25,29 +25,22 @@
|
||||
|
||||
int main() {
|
||||
Timer time;
|
||||
Entity *wall_list[MAX_ROWS][MAX_COLS] = {};
|
||||
sf::Vector2i local_position;
|
||||
sf::Vector2i start_mouse_pos;
|
||||
sf::Vector2i end_mouse_pos;
|
||||
std::array<std::array<Entity*, MAX_COLS>, MAX_ROWS> wall_list = {};
|
||||
bool dragging = false;
|
||||
bool prev_dragging = false;
|
||||
int current_level = 0;
|
||||
|
||||
load_map(wall_list, );
|
||||
load_map(wall_list, levels[3].data);
|
||||
|
||||
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 };
|
||||
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);
|
||||
window.setFramerateLimit(FPS);
|
||||
|
||||
#ifdef __APPLE__
|
||||
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) });
|
||||
@@ -55,10 +48,8 @@ int main() {
|
||||
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("Test");
|
||||
while (const std::optional event = window.pollEvent()) {
|
||||
if (event->is<sf::Event::Closed>()) {
|
||||
running = false;
|
||||
@@ -76,20 +67,19 @@ int main() {
|
||||
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);
|
||||
load_map(wall_list, levels[1].data);
|
||||
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);
|
||||
load_map(wall_list, levels[2].data);
|
||||
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);
|
||||
load_map(wall_list, levels[3].data);
|
||||
current_level = 0;
|
||||
player.timers.level_switch_cooldown = player.timers.level_switch_cooldown_max;
|
||||
}
|
||||
@@ -117,25 +107,18 @@ int main() {
|
||||
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)
|
||||
for (auto [i, j] : rv::cartesian_product(rv::iota(0, MAX_ROWS), rv::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);
|
||||
}
|
||||
#endif
|
||||
|
||||
window.draw(player.rect);
|
||||
window.draw(text);
|
||||
window.display();
|
||||
}
|
||||
|
||||
clear_map(wall_list);
|
||||
player_dash_cooldown.join();
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user