something changed
This commit is contained in:
+21
-15
@@ -13,7 +13,7 @@
|
||||
#include "elements.hpp"
|
||||
|
||||
int main() {
|
||||
int map = [[]];
|
||||
std::vector<Entity> wall_list = {};
|
||||
struct {
|
||||
sf::Vector2<float> size { 16.0f, 16.0f };
|
||||
sf::Vector2<float> 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<Entity> 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 };
|
||||
|
||||
Reference in New Issue
Block a user