-
-
Save rightfold/ceb48fa474f447d8055ec8efe285e360 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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