wall merging
This commit is contained in:
+4
-29
@@ -56,10 +56,9 @@ CollisionDir Entity::find_intersection(Entity &entity) {
|
||||
? CollisionDir::Right // a hit b from the left side
|
||||
: CollisionDir::Left; // a hit b from the right side
|
||||
} else {
|
||||
// Vertical collision
|
||||
return (a.position.y < b.position.y)
|
||||
? CollisionDir::Bottom // a hit b from above
|
||||
: CollisionDir::Top; // a hit b from below
|
||||
? CollisionDir::Bottom
|
||||
: CollisionDir::Top;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,16 +152,14 @@ for(auto [i, j] : ranges::views::cartesian_product(ranges::views::iota(0, MAX_RO
|
||||
return false;
|
||||
}
|
||||
|
||||
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() };
|
||||
|
||||
bool Player::get_vertical_bottom_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] : 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 = bounding_box.find_intersection(*wall_list[i][j]);
|
||||
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 });
|
||||
@@ -173,25 +170,3 @@ for(auto [i, j] : ranges::views::cartesian_product(ranges::views::iota(0, MAX_RO
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user