fix error

This commit is contained in:
MaxKarme 2022-10-05 08:38:42 +03:00
parent 908ca82192
commit 5fb60274de

View File

@ -32,10 +32,12 @@ namespace AirFighter
private (int mapI, int mapJ) checkBarrier((float Left, float Right, float Top, float Bottom) rect) private (int mapI, int mapJ) checkBarrier((float Left, float Right, float Top, float Bottom) rect)
{ {
for (int i = (int)(rect.Top / _size_y); i <= (int)(rect.Bottom / _size_y); ++i) for (int i = (int)(rect.Top / _size_y); i <= (int)(rect.Bottom / _size_y) && i < _map.GetLength(0); ++i)
{ {
for (int j = (int)(rect.Left / _size_x); j <= (int)(rect.Right / _size_x); ++j) for (int j = (int)(rect.Left / _size_x); j <= (int)(rect.Right / _size_x) && j < _map.GetLength(1); ++j)
{ {
if (j < 0) j = 0;
if (i < 0) i = 0;
if (_map[i, j] == _barrier) return (i, j); if (_map[i, j] == _barrier) return (i, j);
} }
} }
@ -56,6 +58,8 @@ namespace AirFighter
if (direction == Direction.Up) position.Top -= _drawningObject.Step; if (direction == Direction.Up) position.Top -= _drawningObject.Step;
if (direction == Direction.Down) position.Top += _drawningObject.Step; if (direction == Direction.Down) position.Top += _drawningObject.Step;
position.Right = position.Left + drawningWidth; position.Right = position.Left + drawningWidth;
position.Bottom = position.Top + drawningHeight; position.Bottom = position.Top + drawningHeight;