From 5fb60274de9ba09ac4674d7b01167f44a657f117 Mon Sep 17 00:00:00 2001 From: MaxKarme <91691525+MaxKarme@users.noreply.github.com> Date: Wed, 5 Oct 2022 08:38:42 +0300 Subject: [PATCH] fix error --- AirFighter/AirFighter/AbstractMap.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/AirFighter/AirFighter/AbstractMap.cs b/AirFighter/AirFighter/AbstractMap.cs index c8d3134..35e2ad6 100644 --- a/AirFighter/AirFighter/AbstractMap.cs +++ b/AirFighter/AirFighter/AbstractMap.cs @@ -32,10 +32,12 @@ namespace AirFighter 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); } } @@ -56,6 +58,8 @@ namespace AirFighter if (direction == Direction.Up) position.Top -= _drawningObject.Step; if (direction == Direction.Down) position.Top += _drawningObject.Step; + + position.Right = position.Left + drawningWidth; position.Bottom = position.Top + drawningHeight;