player bounding box almost there
This commit is contained in:
+52
-39
@@ -1,5 +1,3 @@
|
||||
#include "data.hpp"
|
||||
|
||||
#include <SFML/Audio.hpp>
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include <SFML/Graphics/CircleShape.hpp>
|
||||
@@ -31,85 +29,100 @@ std::string assets = "/home/andrew/personal/Projects/CPP/engine/assets/";
|
||||
#include "maps.hpp"
|
||||
#include "scheduler.hpp"
|
||||
|
||||
int main() {
|
||||
int
|
||||
main()
|
||||
{
|
||||
// float dist = total_distance(12);
|
||||
// std::cout << "Distance: " << dist << "\n";
|
||||
// float acc = distance_to_acceleration(total_distance(12));
|
||||
// std::cout << "Distance: " << acc << "\n";
|
||||
Scheduler scheduler;
|
||||
Manager map_manager;
|
||||
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);
|
||||
map_manager.load(level_data[BASE]);
|
||||
|
||||
std::atomic<bool> running { true };
|
||||
|
||||
sf::RenderWindow window(sf::VideoMode({ WIDTH, HEIGHT }), "engine", sf::Style::Default);
|
||||
window.setFramerateLimit(FPS);
|
||||
|
||||
player.initialize_bounding_box();
|
||||
map_manager.load(level_data[4].data);
|
||||
Player player { player_data, GRAVITY };
|
||||
// player.initialize_bounding_box(player.get_velocity().x);
|
||||
|
||||
sf::Font font(assets + "pixel.ttf");
|
||||
sf::Text text(font, "0, 0", 16);
|
||||
text.setPosition({ WIDTH - (TILESIZE * 11.5), HEIGHT - (int)(TILESIZE / 1.5) });
|
||||
|
||||
std::thread scheduler_thread([&] { scheduler.update(running); });
|
||||
std::jthread scheduler_thread([&] { scheduler.update(running); });
|
||||
|
||||
while (window.isOpen()) {
|
||||
std::cout <<
|
||||
while (window.isOpen())
|
||||
{
|
||||
window.clear(sf::Color::Black);
|
||||
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>()) {
|
||||
while (const std::optional event = window.pollEvent())
|
||||
{
|
||||
if (event->is<sf::Event::Closed>())
|
||||
{
|
||||
running = false;
|
||||
window.close();
|
||||
}
|
||||
}
|
||||
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Escape)) {
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Escape))
|
||||
{
|
||||
running = false;
|
||||
window.close();
|
||||
}
|
||||
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::B)) {
|
||||
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";
|
||||
}
|
||||
std::cout << "\n";
|
||||
// sf::FloatRect a = player.bounding_box.getGlobalBounds();
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::C))
|
||||
{
|
||||
player.bounding_box->rect.setSize(
|
||||
{ total_distance(player.max_dash_acceleration),
|
||||
player.bounding_box->rect.getSize().y });
|
||||
}
|
||||
|
||||
if (map_manager.get_active() >= level_data.size()) {
|
||||
if (map_manager.get_active() >= level_data.size())
|
||||
{
|
||||
map_manager.set_active(DEFAULT);
|
||||
map_manager.load(level_data[DEFAULT].data);
|
||||
map_manager.load(level_data[DEFAULT]);
|
||||
}
|
||||
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Enter) && scheduler.timers.at(1).below_or_zero()) {
|
||||
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.get_horizontal_collision(map_manager.tilemap);
|
||||
|
||||
player.handle_gravity();
|
||||
if (player.get_velocity().y > ((float)TILESIZE / 2 - GRAVITY)) {
|
||||
std::cout << "Vel: " << player.get_velocity().x << ", " << player.get_velocity().y
|
||||
<< "\n";
|
||||
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)) {
|
||||
player.get_vertical_top_collision(map_manager.wall_list);
|
||||
if (!player.get_vertical_bottom_collision(map_manager.tilemap))
|
||||
{
|
||||
player.get_vertical_top_collision(map_manager.tilemap);
|
||||
}
|
||||
if (player.bounding_box != nullptr)
|
||||
{
|
||||
player.update_bounding_box();
|
||||
player.check_bounding_box(map_manager.tilemap);
|
||||
}
|
||||
|
||||
map_manager.draw(window);
|
||||
window.draw(player.rect);
|
||||
window.draw(player.bounding_box);
|
||||
if (player.bounding_box != nullptr)
|
||||
{
|
||||
window.draw(player.bounding_box->rect);
|
||||
}
|
||||
window.draw(text);
|
||||
window.draw(test_object.rect);
|
||||
window.display();
|
||||
}
|
||||
scheduler_thread.join();
|
||||
|
||||
map_manager.clear();
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user