|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace Swan { |
|
|
namespace Swan { |
|
|
|
|
|
|
|
|
static float epsilon = 0.001; |
|
|
|
|
|
|
|
|
static float epsilon = 0.0001; |
|
|
|
|
|
|
|
|
static void collideX( |
|
|
static void collideX( |
|
|
PhysicsTrait::Physics &phys, BodyTrait::Body &body, |
|
|
PhysicsTrait::Physics &phys, BodyTrait::Body &body, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int y = (int)floor(body.top() + epsilon); y <= (int)floor(body.bottom() - epsilon); ++y) { |
|
|
for (int y = (int)floor(body.top() + epsilon); y <= (int)floor(body.bottom() - epsilon); ++y) { |
|
|
int lx = (int)floor(body.left() + epsilon); |
|
|
int lx = (int)floor(body.left() + epsilon); |
|
|
Tile &left = plane.getTile({ lx, y }); |
|
|
|
|
|
|
|
|
Tile &left = plane.getTile({lx, y}); |
|
|
if (left.isSolid) { |
|
|
if (left.isSolid) { |
|
|
body.pos.x = (float)lx + 1.0; |
|
|
body.pos.x = (float)lx + 1.0; |
|
|
collided = true; |
|
|
collided = true; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int rx = (int)floor(body.right() - epsilon); |
|
|
int rx = (int)floor(body.right() - epsilon); |
|
|
Tile &right = plane.getTile({ rx, y }); |
|
|
|
|
|
|
|
|
Tile &right = plane.getTile({rx, y}); |
|
|
if (right.isSolid) { |
|
|
if (right.isSolid) { |
|
|
body.pos.x = (float)rx - body.size.x; |
|
|
body.pos.x = (float)rx - body.size.x; |
|
|
collided = true; |
|
|
collided = true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int x = (int)floor(body.left() + epsilon); x <= (int)floor(body.right() - epsilon); ++x) { |
|
|
for (int x = (int)floor(body.left() + epsilon); x <= (int)floor(body.right() - epsilon); ++x) { |
|
|
int ty = (int)floor(body.top() + epsilon); |
|
|
int ty = (int)floor(body.top() + epsilon); |
|
|
Tile &top = plane.getTile({ x, ty }); |
|
|
|
|
|
|
|
|
Tile &top = plane.getTile({x, ty}); |
|
|
if (top.isSolid) { |
|
|
if (top.isSolid) { |
|
|
body.pos.y = (float)ty + 1.0; |
|
|
body.pos.y = (float)ty + 1.0; |
|
|
collided = true; |
|
|
collided = true; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int by = (int)floor(body.bottom() - epsilon); |
|
|
int by = (int)floor(body.bottom() - epsilon); |
|
|
Tile &bottom = plane.getTile({ x, by }); |
|
|
|
|
|
|
|
|
Tile &bottom = plane.getTile({x, by}); |
|
|
if (bottom.isSolid) { |
|
|
if (bottom.isSolid) { |
|
|
body.pos.y = (float)by - body.size.y; |
|
|
body.pos.y = (float)by - body.size.y; |
|
|
collided = true; |
|
|
collided = true; |