From 4ffa008c7318f0bb369b545bcbfd3a9fa3ed1284 Mon Sep 17 00:00:00 2001 From: DarthMooMancer Date: Sat, 18 Oct 2025 01:55:14 -0400 Subject: [PATCH] something changed --- CMakeLists.txt | 1 + include/maps.hpp | 11 +++++++++++ src/main.cpp | 36 +++++++++++++++++++++--------------- src/maps.cpp | 3 +++ 4 files changed, 36 insertions(+), 15 deletions(-) create mode 100644 include/maps.hpp create mode 100644 src/maps.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index e6a04e0..2ebf93a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,7 @@ include_directories(include) set(SOURCES src/main.cpp src/elements.cpp + src/maps.cpp ) include(FetchContent) diff --git a/include/maps.hpp b/include/maps.hpp new file mode 100644 index 0000000..fdc4c9b --- /dev/null +++ b/include/maps.hpp @@ -0,0 +1,11 @@ +#ifndef MAPS_HPP +#define MAPS_HPP + +#include "globals.hpp" + +const +int map_data[WIDTH / 32][HEIGHT / 32]; + +// Add code here + +#endif diff --git a/src/main.cpp b/src/main.cpp index 6572177..38595d3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -13,7 +13,7 @@ #include "elements.hpp" int main() { - int map = [[]]; + std::vector wall_list = {}; struct { sf::Vector2 size { 16.0f, 16.0f }; sf::Vector2 pos { 40, 40 }; @@ -31,19 +31,25 @@ int main() { } tile_data; struct { + sf::Vector2f size { WIDTH, 2.0f }; + sf::Vector2f pos { 0, HEIGHT - 50 }; + sf::Vector2f velocity { 0, 0 }; + float border_size { 1.0f }; + } line_data; - } simulated_object_data; - std::vector wall_list = {}; - for(int i = 0; i < 19; i++) { + struct { + sf::Vector2f size { 8, 8 }; + sf::Vector2f pos { 100, 40 }; + sf::Vector2f velocity { 0, 0 }; + float border_size { 1.0f }; + } simulated_data; + + for(int i = 0; i < (WIDTH / 32); i++) { wall_list.push_back(Entity { tile_data.size, tile_data.pos, tile_data.velocity, tile_data.border_size, sf::Color::Black }); } for(int i = 0; i < wall_list.size(); i++) { wall_list[i].rect.setPosition({ (i * tile_data.size.x), tile_data.border_size }); } - float floor_height = 2.0f; - sf::RenderWindow window(sf::VideoMode({WIDTH, HEIGHT}), "SFML window", sf::Style::Default); - window.setFramerateLimit(60); - Player player { player_data.size, player_data.pos, player_data.acceleration, @@ -51,11 +57,11 @@ int main() { sf::Color::Black }; - Entity line { { WIDTH, floor_height }, { 0, HEIGHT - 50 }, { 0, 0 }, 1.0f, sf::Color::White }; - // sf::RectangleShape line({ WIDTH, floor_height }); - // line.setPosition({ 0, HEIGHT - 50}); + Entity line { line_data.size, line_data.pos, line_data.velocity, line_data.border_size, sf::Color::White }; + Entity test_square { simulated_data.size, simulated_data.pos, simulated_data.pos, simulated_data.border_size, sf::Color::Black }; - Entity test_square { { 8, 8 }, { 100, 40 }, { 0, 0 }, 1.0f, sf::Color::Black }; + sf::RenderWindow window(sf::VideoMode({WIDTH, HEIGHT}), "SFML window", sf::Style::Default); + window.setFramerateLimit(60); while (window.isOpen()) { window.clear(sf::Color::Black); @@ -88,7 +94,7 @@ int main() { } test_square.rect.move({ test_square.velocity.x, test_square.velocity.y }); - float groundY = line.rect.getPosition().y - floor_height - player.rect.getSize().x; + float groundY = line.rect.getPosition().y - line.rect.getSize().y - player.rect.getSize().x; if (player.rect.getPosition().y >= groundY) { player.rect.setPosition({player.rect.getPosition().x, groundY}); player.velocity.y = 0; @@ -103,7 +109,7 @@ int main() { } float right_border_rect = WIDTH - test_square.rect.getSize().x - test_square.rect.getOutlineThickness(); - float groundY_rect = line.rect.getPosition().y - floor_height - (test_square.rect.getSize().y); + float groundY_rect = line.rect.getPosition().y - line.rect.getSize().y - (test_square.rect.getSize().y); if(test_square.rect.getPosition().x > right_border_rect) { test_square.rect.setPosition({ right_border_rect, test_square.rect.getPosition().y }); test_square.velocity = { -20, 0 }; @@ -115,8 +121,8 @@ int main() { if(test_square.rect.getPosition().y >= groundY_rect) { test_square.rect.setPosition({ test_square.rect.getPosition().x, groundY_rect }); } + auto collision = player.find_intersection(test_square); - switch (collision) { case CollisionDir::Top: test_square.velocity = { 0, -20 }; diff --git a/src/maps.cpp b/src/maps.cpp new file mode 100644 index 0000000..b6aa5be --- /dev/null +++ b/src/maps.cpp @@ -0,0 +1,3 @@ +#include "maps.hpp" + +int map_data[] = [ [ 1, 0, 1, 1, 1, 0, 0] ];