something changed
This commit is contained in:
@@ -10,6 +10,7 @@ include_directories(include)
|
|||||||
set(SOURCES
|
set(SOURCES
|
||||||
src/main.cpp
|
src/main.cpp
|
||||||
src/elements.cpp
|
src/elements.cpp
|
||||||
|
src/maps.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
include(FetchContent)
|
include(FetchContent)
|
||||||
|
|||||||
@@ -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
|
||||||
+21
-15
@@ -13,7 +13,7 @@
|
|||||||
#include "elements.hpp"
|
#include "elements.hpp"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
int map = [[]];
|
std::vector<Entity> wall_list = {};
|
||||||
struct {
|
struct {
|
||||||
sf::Vector2<float> size { 16.0f, 16.0f };
|
sf::Vector2<float> size { 16.0f, 16.0f };
|
||||||
sf::Vector2<float> pos { 40, 40 };
|
sf::Vector2<float> pos { 40, 40 };
|
||||||
@@ -31,19 +31,25 @@ int main() {
|
|||||||
} tile_data;
|
} tile_data;
|
||||||
|
|
||||||
struct {
|
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;
|
struct {
|
||||||
std::vector<Entity> wall_list = {};
|
sf::Vector2f size { 8, 8 };
|
||||||
for(int i = 0; i < 19; i++) {
|
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 });
|
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++) {
|
for(int i = 0; i < wall_list.size(); i++) {
|
||||||
wall_list[i].rect.setPosition({ (i * tile_data.size.x), tile_data.border_size });
|
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 player {
|
||||||
player_data.size, player_data.pos, player_data.acceleration,
|
player_data.size, player_data.pos, player_data.acceleration,
|
||||||
@@ -51,11 +57,11 @@ int main() {
|
|||||||
sf::Color::Black
|
sf::Color::Black
|
||||||
};
|
};
|
||||||
|
|
||||||
Entity line { { WIDTH, floor_height }, { 0, HEIGHT - 50 }, { 0, 0 }, 1.0f, sf::Color::White };
|
Entity line { line_data.size, line_data.pos, line_data.velocity, line_data.border_size, sf::Color::White };
|
||||||
// sf::RectangleShape line({ WIDTH, floor_height });
|
Entity test_square { simulated_data.size, simulated_data.pos, simulated_data.pos, simulated_data.border_size, sf::Color::Black };
|
||||||
// line.setPosition({ 0, HEIGHT - 50});
|
|
||||||
|
|
||||||
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()) {
|
while (window.isOpen()) {
|
||||||
window.clear(sf::Color::Black);
|
window.clear(sf::Color::Black);
|
||||||
@@ -88,7 +94,7 @@ int main() {
|
|||||||
}
|
}
|
||||||
test_square.rect.move({ test_square.velocity.x, test_square.velocity.y });
|
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) {
|
if (player.rect.getPosition().y >= groundY) {
|
||||||
player.rect.setPosition({player.rect.getPosition().x, groundY});
|
player.rect.setPosition({player.rect.getPosition().x, groundY});
|
||||||
player.velocity.y = 0;
|
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 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) {
|
if(test_square.rect.getPosition().x > right_border_rect) {
|
||||||
test_square.rect.setPosition({ right_border_rect, test_square.rect.getPosition().y });
|
test_square.rect.setPosition({ right_border_rect, test_square.rect.getPosition().y });
|
||||||
test_square.velocity = { -20, 0 };
|
test_square.velocity = { -20, 0 };
|
||||||
@@ -115,8 +121,8 @@ int main() {
|
|||||||
if(test_square.rect.getPosition().y >= groundY_rect) {
|
if(test_square.rect.getPosition().y >= groundY_rect) {
|
||||||
test_square.rect.setPosition({ test_square.rect.getPosition().x, groundY_rect });
|
test_square.rect.setPosition({ test_square.rect.getPosition().x, groundY_rect });
|
||||||
}
|
}
|
||||||
|
|
||||||
auto collision = player.find_intersection(test_square);
|
auto collision = player.find_intersection(test_square);
|
||||||
|
|
||||||
switch (collision) {
|
switch (collision) {
|
||||||
case CollisionDir::Top:
|
case CollisionDir::Top:
|
||||||
test_square.velocity = { 0, -20 };
|
test_square.velocity = { 0, -20 };
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
#include "maps.hpp"
|
||||||
|
|
||||||
|
int map_data[] = [ [ 1, 0, 1, 1, 1, 0, 0] ];
|
||||||
Reference in New Issue
Block a user