data drivin all code sucess

This commit is contained in:
Andrew Haynes Macbook
2026-01-16 15:03:16 -05:00
parent 7bbf50b581
commit 06d3f27b1e
13 changed files with 358 additions and 115 deletions
+23 -19
View File
@@ -4,6 +4,7 @@
#include "elements.hpp"
#include "globals.hpp"
#include <SFML/Graphics/RenderWindow.hpp>
#include <array>
#ifdef __APPLE__
#include <range/v3/view/cartesian_product.hpp>
@@ -14,34 +15,37 @@ namespace rv = ranges::views;
namespace rv = std::views;
#endif
void Manager::clear_map() {
void Manager::clear() {
for (auto [i, j] : rv::cartesian_product(rv::iota(0, MAX_ROWS), rv::iota(0, MAX_COLS))) {
delete wall_list[i][j];
wall_list[i][j] = nullptr;
}
}
int Manager::get_current_level() { return current_level; }
int Manager::get_active() { return _active; }
void Manager::set_current_level(int level) { current_level = level; }
void Manager::set_active(int level) { _active = level; }
// bool is_tiles_clear_x(std::array<std::array<char, MAX_COLS>, MAX_ROWS> draw_list, int y_level, int start_x, int end_x) {
// for (int i : rv::iota(start_x, end_x)) {
// if (draw_list[i][y_level] == ' ') continue;
// return false;
// }
// return true;
// }
//
// bool is_tiles_clear_y(std::array<std::array<char, MAX_COLS>, MAX_ROWS> draw_list, int x_level, int start_y, int end_y) {
// for (int i : rv::iota(start_y, end_y)) {
// if (draw_list[i][x_level] == ' ') continue;
// return false;
// }
// return true;
// }
void Manager::set_next() {
_active++;
clear();
load(level_data[_active].data);
}
void Manager::load_map(const std::array<std::array<char, MAX_COLS>, MAX_ROWS> map_data) {
void Manager::set_previous() {
_active--;
clear();
load(level_data[_active].data);
}
void Manager::draw(sf::RenderWindow& window) {
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);
}
}
void Manager::load(const std::array<std::array<char, MAX_COLS>, MAX_ROWS> map_data) {
for (auto [i, j] : rv::cartesian_product(rv::iota(0, MAX_ROWS), rv::iota(0, MAX_COLS))) {
if (map_data[i][j] == ' ') continue;
if (map_data[i][j] == '0') {