Skip to content

Instantly share code, notes, and snippets.

@rightfold

rightfold/.cs Secret

Created June 26, 2016 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rightfold/ceb48fa474f447d8055ec8efe285e360 to your computer and use it in GitHub Desktop.
Save rightfold/ceb48fa474f447d8055ec8efe285e360 to your computer and use it in GitHub Desktop.
var boundingBox = BoundingBox;
int leftTile = (int)Math.Floor(boundingBox.TopLeft.X / 16f);
int rightTile = (int)Math.Ceiling(boundingBox.BottomRight.X / 16f) - 1;
int topTile = (int)Math.Floor(boundingBox.TopLeft.Y / 16f);
int bottomTile = (int)Math.Ceiling(boundingBox.BottomRight.Y / 16f) - 1;
for (int x = leftTile; x <= rightTile; ++x)
{
for (int y = topTile; y <= bottomTile; ++y)
{
if (w.Map.GetTileAt(x, y).IsWall)
{
Velocity = -Velocity;
goto endCollisionDetect;
}
}
}
endCollisionDetect:
Position += Velocity;
if (dt.ElapsedTime.TotalMilliseconds != 0f)
{
Velocity /= Friction / (float)dt.ElapsedTime.TotalMilliseconds;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment