something changed

This commit is contained in:
DarthMooMancer
2025-10-19 02:56:17 -04:00
parent d384dff919
commit 023b638e54
3 changed files with 70 additions and 60 deletions
+37 -37
View File
@@ -8,14 +8,11 @@
#include <SFML/System/Vector2.hpp>
#include <SFML/Window/Keyboard.hpp>
#include <cstdlib>
#include <iostream>
#include <vector>
#include "globals.hpp"
#include "elements.hpp"
#include "maps.hpp"
int main() {
// std::vector<Entity> wall_list = {};
Entity *wall_list[MAX_ROWS][MAX_COLS] = {};
struct {
sf::Vector2<float> size { TILESIZE / 2.0f, TILESIZE / 2.0f };
@@ -54,6 +51,7 @@ int main() {
}
}
}
for(int i = 0; i < MAX_ROWS; i++) {
for(int j = 0; j < MAX_COLS; j++) {
if(wall_list[i][j] != nullptr) {
@@ -63,9 +61,9 @@ int main() {
}
Player player {
player_data.size, player_data.pos, player_data.acceleration,
player_data.max_velocity_y, player_data.border_size, player_data.velocity,
sf::Color::Black
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
};
Entity line { line_data.size, line_data.pos, line_data.velocity, line_data.border_size, sf::Color::White };
@@ -87,29 +85,29 @@ int main() {
// FOR TESTING
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Space)) {
if(test_square.rect.getPosition().x < 30) {
test_square.velocity = { 20, 0 };
test_square.set_velocity({ 20, 0 });
}
if(test_square.rect.getPosition().x > WIDTH - 30) {
test_square.velocity = { -20, 0 };
test_square.set_velocity({ -20, 0 });
}
}
player.handle_movment();
player.velocity.y += player.m_acceleration;
player.rect.move({0, player.velocity.y});
player.set_velocity_y(player.get_velocity().y + player.m_acceleration);
player.rect.move({0, player.get_velocity().y});
test_square.velocity.y++;
if(test_square.velocity.x > 0) {
test_square.velocity.x--;
test_square.set_velocity_y(player.get_velocity().y + 1);
if(test_square.get_velocity().x > 0) {
test_square.set_velocity_x(test_square.get_velocity().x - 1);
}
if(test_square.velocity.x < 0) {
test_square.velocity.x++;
if(test_square.get_velocity().x < 0) {
test_square.set_velocity_x(test_square.get_velocity().x + 1);
}
test_square.rect.move({ test_square.velocity.x, test_square.velocity.y });
test_square.rect.move({ test_square.get_velocity().x, test_square.get_velocity().y });
float groundY = line.rect.getPosition().y - line.rect.getSize().y - player.rect.getSize().y - line_data.border_size - player_data.border_size;
if (player.rect.getPosition().y >= groundY) {
player.rect.setPosition({player.rect.getPosition().x, groundY});
player.velocity.y = 0;
player.set_velocity_y(0);
player.m_jumping = false;
}
float right_border = WIDTH - player.rect.getSize().x;
@@ -124,11 +122,11 @@ int main() {
float groundY_rect = line.rect.getPosition().y - line.rect.getSize().y - test_square.rect.getSize().y - line_data.border_size - simulated_data.border_size;
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 };
test_square.set_velocity({ -20, 0 });
}
if(test_square.rect.getPosition().x < std::abs(test_square.rect.getOutlineThickness())) {
test_square.rect.setPosition({ 0, test_square.rect.getPosition().y });
test_square.velocity = { 20, 0 };
test_square.set_velocity({ 20, 0 });
}
if(test_square.rect.getPosition().y >= groundY_rect) {
test_square.rect.setPosition({ test_square.rect.getPosition().x, groundY_rect });
@@ -137,39 +135,41 @@ int main() {
auto collision = player.find_intersection(test_square);
switch (collision) {
case CollisionDir::Top:
test_square.velocity = { 0, -20 };
test_square.set_velocity({ 0, -20 });
break;
case CollisionDir::Bottom:
test_square.velocity = { 0, -20 };
test_square.set_velocity({ 0, -20 });
break;
case CollisionDir::Left:
test_square.velocity = { -20, 0 };
test_square.set_velocity({ -20, 0 });
break;
case CollisionDir::Right:
test_square.velocity = { 20, 0 };
test_square.set_velocity({ 20, 0 });
break;
default: break;
}
// for(int i = 0; i < MAX_ROWS; i++) {
// for(int j = 0; j < MAX_COLS; j++) {
// auto collision = player.find_intersection(*wall_list[i][j]);
// if(wall_list[i][j] == nullptr) continue;
// auto collision = wall_list[i][j]->find_intersection(player);
// switch (collision) {
// case CollisionDir::Top:
// player.velocity = { player.velocity.x, -player.velocity.y };
// player.velocity = { player.velocity.x, 0 };
// player.velocity.y -= player.m_acceleration;
// break;
// case CollisionDir::Bottom:
// player.velocity = { player.velocity.x, -player.velocity.y };
// break;
// case CollisionDir::Left:
// player.velocity = { player.velocity.x, 0 };
// break;
// case CollisionDir::Right:
// player.velocity = { player.velocity.x, 0 };
// break;
// default: break;
// }
//
// }
// player.velocity = { player.velocity.x, 0 };
// break;
// case CollisionDir::Left:
// player.velocity = { player.velocity.x, 0 };
// break;
// case CollisionDir::Right:
// player.velocity = { player.velocity.x, 0 };
// break;
// default: break;
// }
//
// }
// }
for(int i = 0; i < MAX_ROWS; i++) {