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_top_collision(Entity *wall_list[MAX_ROWS][MAX_COLS]);
|
||||||
bool get_vertical_bottom_collision(Entity *wall_list[MAX_ROWS][MAX_COLS]);
|
bool get_vertical_bottom_collision(Entity *wall_list[MAX_ROWS][MAX_COLS]);
|
||||||
private:
|
private:
|
||||||
|
bool get_vertical_bottom_collision_by_offset(Entity *wall_list[MAX_ROWS][MAX_COLS]);
|
||||||
sf::Vector2f _min_velocity;
|
sf::Vector2f _min_velocity;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+24
-1
@@ -116,7 +116,6 @@ 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]) {
|
bool Player::get_horizontal_collision(Entity *wall_list[MAX_ROWS][MAX_COLS]) {
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
for(auto [i, j] : ranges::views::cartesian_product(ranges::views::iota(0, MAX_ROWS), ranges::views::iota(0, MAX_COLS))) {
|
for(auto [i, j] : ranges::views::cartesian_product(ranges::views::iota(0, MAX_ROWS), ranges::views::iota(0, MAX_COLS))) {
|
||||||
@@ -154,7 +153,30 @@ bool Player::get_vertical_top_collision(Entity *wall_list[MAX_ROWS][MAX_COLS]) {
|
|||||||
return false;
|
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() };
|
||||||
|
|
||||||
|
#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]);
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
bool Player::get_vertical_bottom_collision(Entity *wall_list[MAX_ROWS][MAX_COLS]) {
|
bool Player::get_vertical_bottom_collision(Entity *wall_list[MAX_ROWS][MAX_COLS]) {
|
||||||
|
|
||||||
|
if(!get_vertical_bottom_collision_by_offset(wall_list)) {
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
for(auto [i, j] : ranges::views::cartesian_product(ranges::views::iota(0, MAX_ROWS), ranges::views::iota(0, MAX_COLS))) {
|
for(auto [i, j] : ranges::views::cartesian_product(ranges::views::iota(0, MAX_ROWS), ranges::views::iota(0, MAX_COLS))) {
|
||||||
#else
|
#else
|
||||||
@@ -170,5 +192,6 @@ bool Player::get_vertical_bottom_collision(Entity *wall_list[MAX_ROWS][MAX_COLS]
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-7
@@ -97,13 +97,13 @@ int main() {
|
|||||||
player.handle_movment();
|
player.handle_movment();
|
||||||
player.get_horizontal_collision(wall_list);
|
player.get_horizontal_collision(wall_list);
|
||||||
|
|
||||||
if(player.rect.getPosition().y > HEIGHT) {
|
// if(player.rect.getPosition().y > HEIGHT) {
|
||||||
player.rect.setPosition({ player.rect.getPosition().x, HEIGHT - TILESIZE - player.rect.getSize().y });
|
// player.rect.setPosition({ player.rect.getPosition().x, HEIGHT - TILESIZE - player.rect.getSize().y });
|
||||||
player.set_velocity_y(0);
|
// player.set_velocity_y(0);
|
||||||
while(player.get_vertical_bottom_collision(wall_list) || player.get_vertical_top_collision(wall_list)) {
|
// 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.rect.setPosition({ player.rect.getPosition().x, player.rect.getPosition().y - TILESIZE - player.rect.getSize().y });
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
player.handle_gravity();
|
player.handle_gravity();
|
||||||
if(!player.get_vertical_bottom_collision(wall_list)) {
|
if(!player.get_vertical_bottom_collision(wall_list)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user