Browse Source

test collision below before above

opengl-renderer-broken
Martin Dørum 4 years ago
parent
commit
173db9be7f
1 changed files with 9 additions and 9 deletions
  1. 9
    9
      libswan/src/Body.cc

+ 9
- 9
libswan/src/Body.cc View File

@@ -56,20 +56,20 @@ void Body::collideY(WorldPlane &plane) {
on_ground_ = false;

for (int x = (int)floor(bounds.left() + epsilon); x <= (int)floor(bounds.right() - epsilon); ++x) {
int ty = (int)floor(bounds.top() + epsilon);
Tile &top = plane.getTile({ x, ty });
if (top.is_solid_) {
bounds.pos.y = (float)ty + 1.0;
int by = (int)floor(bounds.bottom() - epsilon);
Tile &bottom = plane.getTile({ x, by });
if (bottom.is_solid_) {
bounds.pos.y = (float)by - bounds.size.y;
collided = true;
on_ground_ = true;
break;
}

int by = (int)floor(bounds.bottom() - epsilon);
Tile &right = plane.getTile({ x, by });
if (right.is_solid_) {
bounds.pos.y = (float)by - bounds.size.y;
int ty = (int)floor(bounds.top() + epsilon);
Tile &top = plane.getTile({ x, ty });
if (top.is_solid_) {
bounds.pos.y = (float)ty + 1.0;
collided = true;
on_ground_ = true;
break;
}
}

Loading…
Cancel
Save