fixes
This commit is contained in:
+25
-36
@@ -1,17 +1,10 @@
|
||||
#include <SFML/Graphics/CircleShape.hpp>
|
||||
#include <SFML/Audio.hpp>
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include <SFML/Graphics/Color.hpp>
|
||||
#include <SFML/Graphics/Font.hpp>
|
||||
#include <SFML/Graphics/Rect.hpp>
|
||||
#include <SFML/Graphics/RectangleShape.hpp>
|
||||
#include <SFML/Graphics/Text.hpp>
|
||||
#include <SFML/Graphics/Texture.hpp>
|
||||
#include <SFML/System/Angle.hpp>
|
||||
#include <SFML/System/Vector2.hpp>
|
||||
#include <SFML/Window/Keyboard.hpp>
|
||||
#include <SFML/Window.hpp>
|
||||
#include <SFML/System.hpp>
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#ifdef __APPLE__
|
||||
#include <range/v3/view/iota.hpp>
|
||||
#include <range/v3/view/cartesian_product.hpp>
|
||||
@@ -21,8 +14,10 @@
|
||||
#include "globals.hpp"
|
||||
#include "elements.hpp"
|
||||
#include "maps.hpp"
|
||||
#include "scheduler.hpp"
|
||||
|
||||
int main() {
|
||||
Timer time;
|
||||
Entity *wall_list[MAX_ROWS][MAX_COLS] = {};
|
||||
struct {
|
||||
sf::Vector2<float> size { TILESIZE / 2.0f, TILESIZE / 2.0f };
|
||||
@@ -30,6 +25,7 @@ int main() {
|
||||
float acceleration { 1.0f };
|
||||
float max_velocity_y { 20.0f };
|
||||
float border_size { -1.0f };
|
||||
float dash_distance { 20.0f };
|
||||
sf::Vector2f velocity { 4.0f, 0 };
|
||||
} player_data;
|
||||
|
||||
@@ -40,20 +36,6 @@ int main() {
|
||||
float border_size { -2.0f };
|
||||
} tile_data;
|
||||
|
||||
struct {
|
||||
sf::Vector2f size { WIDTH, 2.0f };
|
||||
sf::Vector2f pos { 0, HEIGHT - (TILESIZE * 1) };
|
||||
sf::Vector2f velocity { 0, 0 };
|
||||
float border_size { -1.0f };
|
||||
} line_data;
|
||||
|
||||
struct {
|
||||
sf::Vector2f size { TILESIZE / 4.0f, TILESIZE / 4.0f };
|
||||
sf::Vector2f pos { TILESIZE * 3, TILESIZE };
|
||||
sf::Vector2f velocity { 0, 0 };
|
||||
float border_size { -1.0f };
|
||||
} simulated_data;
|
||||
|
||||
#ifdef __APPLE__
|
||||
for(auto[i, j] : ranges::views::cartesian_product(ranges::views::iota(0, MAX_ROWS), ranges::views::iota(0, MAX_COLS))) {
|
||||
if(map_data[i][j] != 1) continue;
|
||||
@@ -64,6 +46,7 @@ int main() {
|
||||
if(wall_list[i][j] == nullptr) continue;
|
||||
wall_list[i][j]->rect.setPosition({ (j * tile_data.size.x), (i * tile_data.size.y) });
|
||||
}
|
||||
|
||||
#else
|
||||
for(auto[i, j] : std::views::cartesian_product(std::views::iota(0, MAX_ROWS), std::views::iota(0, MAX_COLS))) {
|
||||
if(map_data[i][j] != 1) continue;
|
||||
@@ -79,11 +62,9 @@ int main() {
|
||||
Player player {
|
||||
player_data.size, player_data.pos, player_data.velocity,
|
||||
player_data.border_size, player_data.acceleration, player_data.max_velocity_y,
|
||||
sf::Color::Black, sf::Color::White
|
||||
player_data.dash_distance, sf::Color::Black, sf::Color::White
|
||||
};
|
||||
|
||||
Entity line { line_data.size, line_data.pos, line_data.velocity, line_data.border_size, sf::Color::White };
|
||||
|
||||
sf::RenderWindow window(sf::VideoMode({WIDTH, HEIGHT}), "SFML window", sf::Style::Default);
|
||||
window.setFramerateLimit(60);
|
||||
|
||||
@@ -96,31 +77,38 @@ int main() {
|
||||
sf::Text text(font, "0, 0", 16);
|
||||
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.dash_cooldown); } );
|
||||
while (window.isOpen()) {
|
||||
window.clear(sf::Color::Black);
|
||||
text.setString(std::to_string((int)player.rect.getPosition().x) + ", " + std::to_string((int)player.rect.getPosition().y));
|
||||
text.setString(std::to_string(player.timers.dash_cooldown));
|
||||
while (const std::optional event = window.pollEvent()) {
|
||||
if (event->is<sf::Event::Closed>())
|
||||
if (event->is<sf::Event::Closed>()) {
|
||||
running = false;
|
||||
window.close();
|
||||
}
|
||||
}
|
||||
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Escape)) {
|
||||
running = false;
|
||||
window.close();
|
||||
}
|
||||
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::W)) {
|
||||
player.set_velocity_x(20);
|
||||
}
|
||||
|
||||
// Handle Horizontal movement and collisions
|
||||
player.handle_movment();
|
||||
player.get_horizontal_collision(wall_list);
|
||||
player.horizontal_no_out_of_bounds(line);
|
||||
|
||||
if(player.rect.getPosition().y > HEIGHT) {
|
||||
player.rect.setPosition({ player.rect.getPosition().x, HEIGHT - TILESIZE - player.rect.getSize().y });
|
||||
player.set_velocity_y(0);
|
||||
while(player.get_vertical_bottom_collision(wall_list) || player.get_vertical_top_collision(wall_list)) {
|
||||
player.rect.setPosition({ player.rect.getPosition().x, player.rect.getPosition().y - TILESIZE - player.rect.getSize().y });
|
||||
}
|
||||
}
|
||||
|
||||
player.handle_gravity();
|
||||
|
||||
if(!player.get_vertical_bottom_collision(wall_list)) {
|
||||
player.get_vertical_top_collision(wall_list);
|
||||
}
|
||||
player.vertical_no_out_of_bounds(line);
|
||||
|
||||
// Drawing Everything to window
|
||||
#ifdef __APPLE__
|
||||
@@ -136,7 +124,6 @@ int main() {
|
||||
}
|
||||
#endif
|
||||
window.draw(player.rect);
|
||||
window.draw(line.rect);
|
||||
window.draw(text);
|
||||
window.display();
|
||||
}
|
||||
@@ -149,4 +136,6 @@ int main() {
|
||||
delete wall_list[i][j];
|
||||
}
|
||||
#endif
|
||||
player_dash_cooldown.join();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user