data drivin all code sucess
This commit is contained in:
+47
-54
@@ -2,60 +2,62 @@
|
||||
|
||||
#include <SFML/Audio.hpp>
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include <SFML/Graphics/CircleShape.hpp>
|
||||
#include <SFML/Graphics/Color.hpp>
|
||||
#include <SFML/Graphics/Rect.hpp>
|
||||
#include <SFML/Graphics/RectangleShape.hpp>
|
||||
#include <SFML/System.hpp>
|
||||
#include <SFML/System/Vector2.hpp>
|
||||
#include <SFML/Window.hpp>
|
||||
#include <SFML/Window/Mouse.hpp>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <iostream>
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <range/v3/view/cartesian_product.hpp>
|
||||
#include <range/v3/view/iota.hpp>
|
||||
namespace rv = ranges::views;
|
||||
std::string assets = "/Users/andrew/personal/Projects/CPP/engine/assets/";
|
||||
#else
|
||||
#include <ranges>
|
||||
namespace rv = std::views;
|
||||
std::string assets = "/home/andrew/personal/Projects/CPP/engine/assets/";
|
||||
#endif
|
||||
|
||||
#include "data.hpp"
|
||||
#include "elements.hpp"
|
||||
#include "globals.hpp"
|
||||
#include "maps.hpp"
|
||||
#include "scheduler.hpp"
|
||||
#include "data.hpp"
|
||||
|
||||
int main() {
|
||||
Scheduler time;
|
||||
Scheduler scheduler;
|
||||
Manager map_manager;
|
||||
std::vector<Timer> timers = {
|
||||
Timer("dash", .5),
|
||||
Timer("level_switch", 1),
|
||||
};
|
||||
|
||||
map_manager.load_map(level_data[1].data);
|
||||
|
||||
sf::Font font(assets + "pixel.ttf");
|
||||
Player player { player_data, GRAVITY };
|
||||
|
||||
Object test_object { object_data[0] };
|
||||
sf::RenderWindow window(sf::VideoMode({ WIDTH, HEIGHT }), "engine", sf::Style::Default);
|
||||
bool running { true };
|
||||
sf::Text text(font, "0, 0", 16);
|
||||
|
||||
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
|
||||
player.initialize_bounding_box();
|
||||
map_manager.load(level_data[4].data);
|
||||
|
||||
sf::Text text(font, "0, 0", 16);
|
||||
text.setPosition({ WIDTH - (TILESIZE * 11.5), HEIGHT - (int)(TILESIZE / 1.5) });
|
||||
|
||||
bool running = true;
|
||||
std::thread scheduler([&] { time.update(running, timers); });
|
||||
std::thread scheduler_thread([&] { scheduler.update(running); });
|
||||
|
||||
while (window.isOpen()) {
|
||||
std::cout <<
|
||||
window.clear(sf::Color::Black);
|
||||
text.setString(std::to_string(timers.at(0).get_time()));
|
||||
test_object.rect.setPosition(
|
||||
{ player.rect.getPosition().x + 108 - player.rect.getSize().x, player.rect.getPosition().y });
|
||||
test_object.rect.setPosition({ player.rect.getPosition().x - 108, player.rect.getPosition().y });
|
||||
|
||||
text.setString(std::to_string(scheduler.timers.at(0).get_time()));
|
||||
while (const std::optional event = window.pollEvent()) {
|
||||
if (event->is<sf::Event::Closed>()) {
|
||||
running = false;
|
||||
@@ -67,57 +69,48 @@ int main() {
|
||||
running = false;
|
||||
window.close();
|
||||
}
|
||||
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::B)) {
|
||||
map_manager.clear_map();
|
||||
}
|
||||
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Enter) && timers.at(1).below_or_zero()) {
|
||||
map_manager.clear_map();
|
||||
if (map_manager.get_current_level() == 1) {
|
||||
map_manager.load_map(level_data[1].data);
|
||||
map_manager.set_current_level(2);
|
||||
} else if (map_manager.get_current_level() == 2) {
|
||||
map_manager.load_map(level_data[2].data);
|
||||
map_manager.set_current_level(3);
|
||||
} else if (map_manager.get_current_level() == 3) {
|
||||
map_manager.load_map(level_data[3].data);
|
||||
map_manager.set_current_level(1);
|
||||
} else {
|
||||
map_manager.load_map(level_data[1].data);
|
||||
map_manager.set_current_level(1);
|
||||
for (int i = 0; i < player.bounding_box.getPointCount(); i++) {
|
||||
std::cout << "(" << player.bounding_box.getPoint(i).x << ", " << player.bounding_box.getPoint(i).y
|
||||
<< ")\n";
|
||||
}
|
||||
timers.at(1).reset();
|
||||
std::cout << "\n";
|
||||
// sf::FloatRect a = player.bounding_box.getGlobalBounds();
|
||||
}
|
||||
|
||||
player.handle_movment(timers.at(time.pull(timers, "dash")));
|
||||
if (map_manager.get_active() >= level_data.size()) {
|
||||
map_manager.set_active(DEFAULT);
|
||||
map_manager.load(level_data[DEFAULT].data);
|
||||
}
|
||||
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Enter) && scheduler.timers.at(1).below_or_zero()) {
|
||||
map_manager.set_next();
|
||||
scheduler.timers.at(1).reset();
|
||||
}
|
||||
|
||||
player.update_bounding_box();
|
||||
player.handle_movment(scheduler.timers.at(scheduler.pull("Dash")));
|
||||
player.get_horizontal_collision(map_manager.wall_list);
|
||||
|
||||
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(map_manager.wall_list)) {
|
||||
std::cout << "\n";
|
||||
if (!player.get_vertical_top_collision(map_manager.wall_list)) {
|
||||
std::cout << "\n";
|
||||
} else {
|
||||
std::cout << "Yes vertical top collision\n";
|
||||
}
|
||||
} else { std::cout << "Yes vertical bottom collision\n"; }
|
||||
|
||||
for (auto [i, j] : rv::cartesian_product(rv::iota(0, MAX_ROWS), rv::iota(0, MAX_COLS))) {
|
||||
if (map_manager.wall_list[i][j] == nullptr) {
|
||||
continue;
|
||||
}
|
||||
window.draw(map_manager.wall_list[i][j]->rect);
|
||||
if (!player.get_vertical_bottom_collision(map_manager.wall_list)) {
|
||||
player.get_vertical_top_collision(map_manager.wall_list);
|
||||
}
|
||||
|
||||
map_manager.draw(window);
|
||||
window.draw(player.rect);
|
||||
window.draw(player.bounding_box);
|
||||
window.draw(text);
|
||||
window.draw(test_object.rect);
|
||||
window.display();
|
||||
}
|
||||
scheduler.join();
|
||||
scheduler_thread.join();
|
||||
|
||||
map_manager.clear_map();
|
||||
map_manager.clear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user