changing cmake
This commit is contained in:
@@ -47,6 +47,7 @@ public:
|
||||
bool get_vertical_top_collision(Entity *wall_list[MAX_ROWS][MAX_COLS]);
|
||||
bool get_vertical_bottom_collision(Entity *wall_list[MAX_ROWS][MAX_COLS]);
|
||||
private:
|
||||
bool get_vertical_bottom_collision_by_offset(Entity *wall_list[MAX_ROWS][MAX_COLS]);
|
||||
sf::Vector2f _min_velocity;
|
||||
};
|
||||
|
||||
|
||||
+35
-12
@@ -116,13 +116,12 @@ void Player::vertical_no_out_of_bounds(Entity &base) {
|
||||
}
|
||||
}
|
||||
|
||||
// bool Player::get_horizontal_collision(Entity *wall_list[MAX_ROWS][MAX_COLS]) {
|
||||
bool Player::get_horizontal_collision(Entity *wall_list[MAX_ROWS][MAX_COLS]) {
|
||||
#ifdef __APPLE__
|
||||
for(auto [i, j] : ranges::views::cartesian_product(ranges::views::iota(0, MAX_ROWS), ranges::views::iota(0, MAX_COLS))) {
|
||||
#else
|
||||
for(auto [i, j] : ranges::views::cartesian_product(ranges::views::iota(0, MAX_ROWS), ranges::views::iota(0, MAX_COLS))) {
|
||||
#else
|
||||
for(auto [i, j] : std::views::cartesian_product(std::views::iota(0, MAX_ROWS), std::views::iota(0, MAX_COLS))) {
|
||||
#endif
|
||||
#endif
|
||||
if(wall_list[i][j] == nullptr) continue;
|
||||
auto collision = wall_list[i][j]->find_intersection(*this);
|
||||
if(collision == CollisionDir::None) continue;
|
||||
@@ -138,10 +137,10 @@ bool Player::get_horizontal_collision(Entity *wall_list[MAX_ROWS][MAX_COLS]) {
|
||||
|
||||
bool Player::get_vertical_top_collision(Entity *wall_list[MAX_ROWS][MAX_COLS]) {
|
||||
#ifdef __APPLE__
|
||||
for(auto [i, j] : ranges::views::cartesian_product(ranges::views::iota(0, MAX_ROWS), ranges::views::iota(0, MAX_COLS))) {
|
||||
#else
|
||||
for(auto [i, j] : ranges::views::cartesian_product(ranges::views::iota(0, MAX_ROWS), ranges::views::iota(0, MAX_COLS))) {
|
||||
#else
|
||||
for(auto [i, j] : std::views::cartesian_product(std::views::iota(0, MAX_ROWS), std::views::iota(0, MAX_COLS))) {
|
||||
#endif
|
||||
#endif
|
||||
if(wall_list[i][j] == nullptr) continue;
|
||||
auto collision = find_intersection(*wall_list[i][j]);
|
||||
if(collision == CollisionDir::None) continue;
|
||||
@@ -154,14 +153,16 @@ bool Player::get_vertical_top_collision(Entity *wall_list[MAX_ROWS][MAX_COLS]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Player::get_vertical_bottom_collision(Entity *wall_list[MAX_ROWS][MAX_COLS]) {
|
||||
bool Player::get_vertical_bottom_collision_by_offset(Entity *wall_list[MAX_ROWS][MAX_COLS]) {
|
||||
Entity bounding_box { { rect.getSize() }, { rect.getPosition().x, rect.getPosition().y + get_velocity().y }, { get_velocity() }, rect.getOutlineThickness() };
|
||||
|
||||
#ifdef __APPLE__
|
||||
for(auto [i, j] : ranges::views::cartesian_product(ranges::views::iota(0, MAX_ROWS), ranges::views::iota(0, MAX_COLS))) {
|
||||
#else
|
||||
for(auto [i, j] : ranges::views::cartesian_product(ranges::views::iota(0, MAX_ROWS), ranges::views::iota(0, MAX_COLS))) {
|
||||
#else
|
||||
for(auto [i, j] : std::views::cartesian_product(std::views::iota(0, MAX_ROWS), std::views::iota(0, MAX_COLS))) {
|
||||
#endif
|
||||
#endif
|
||||
if(wall_list[i][j] == nullptr) continue;
|
||||
auto collision = find_intersection(*wall_list[i][j]);
|
||||
auto collision = bounding_box.find_intersection(*wall_list[i][j]);
|
||||
if(collision == CollisionDir::None) continue;
|
||||
if(collision == CollisionDir::Bottom && get_velocity().y > 0) {
|
||||
rect.setPosition({ rect.getPosition().x, wall_list[i][j]->rect.getPosition().y - rect.getSize().y });
|
||||
@@ -172,3 +173,25 @@ bool Player::get_vertical_bottom_collision(Entity *wall_list[MAX_ROWS][MAX_COLS]
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Player::get_vertical_bottom_collision(Entity *wall_list[MAX_ROWS][MAX_COLS]) {
|
||||
|
||||
if(!get_vertical_bottom_collision_by_offset(wall_list)) {
|
||||
#ifdef __APPLE__
|
||||
for(auto [i, j] : ranges::views::cartesian_product(ranges::views::iota(0, MAX_ROWS), ranges::views::iota(0, MAX_COLS))) {
|
||||
#else
|
||||
for(auto [i, j] : std::views::cartesian_product(std::views::iota(0, MAX_ROWS), std::views::iota(0, MAX_COLS))) {
|
||||
#endif
|
||||
if(wall_list[i][j] == nullptr) continue;
|
||||
auto collision = find_intersection(*wall_list[i][j]);
|
||||
if(collision == CollisionDir::None) continue;
|
||||
if(collision == CollisionDir::Bottom && get_velocity().y > 0) {
|
||||
rect.setPosition({ rect.getPosition().x, wall_list[i][j]->rect.getPosition().y - rect.getSize().y });
|
||||
m_jumping = false;
|
||||
set_velocity_y(0);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
+7
-7
@@ -97,13 +97,13 @@ int main() {
|
||||
player.handle_movment();
|
||||
player.get_horizontal_collision(wall_list);
|
||||
|
||||
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 });
|
||||
}
|
||||
}
|
||||
// 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)) {
|
||||
|
||||
Reference in New Issue
Block a user