Еще немножк

This commit is contained in:
devil_1nc 2022-10-02 18:56:26 +04:00
parent d3e23a1905
commit 397a890de9

View File

@ -18,35 +18,6 @@ namespace ProjectPlane
protected readonly int _freeRoad = 0; protected readonly int _freeRoad = 0;
protected readonly int _barrier = 1; protected readonly int _barrier = 1;
public bool IsMoveable(float x, float y)
{
var getPos = _drawingObject.GetCurrentPosition();
int Right = Convert.ToInt32((getPos.Right + x) / _size_x) > 0
? Convert.ToInt32((getPos.Right + x) / _size_x) : 0;
int Left = Convert.ToInt32((getPos.Left + x) / _size_x) > 0
? Convert.ToInt32((getPos.Left + x) / _size_x) : 0;
int Top = Convert.ToInt32((getPos.Top + y) / _size_y) > 0
? Convert.ToInt32((getPos.Top + y) / _size_y) : 0;
int Bottom = Convert.ToInt32((getPos.Bottom + y) / _size_y) > 0
? Convert.ToInt32((getPos.Bottom + y) / _size_y) : 0;
for (int i = Left; i <= Right; i++)
{
for (int j = Top; j <= Bottom; j++)
{
if (_map[i, j] == _barrier) return false;
}
}
return true;
}
public Bitmap CreateMap(int width, int height, IDrawingObject drawingObject) public Bitmap CreateMap(int width, int height, IDrawingObject drawingObject)
{ {
_width = width; _width = width;
@ -65,16 +36,59 @@ namespace ProjectPlane
switch (direction) switch (direction)
{ {
case Direction.Right: case Direction.Right:
isMoveable = IsMoveable(_drawingObject.Step, 0); for (int i = _objWidth; i <= _objWidth + Convert.ToInt32(_drawingObject.Step / _size_x); i++)
{
for (int j = _startY; j <= _objHeight; j++)
{
if (_map[i, j] == _barrier)
{
isMoveable = false;
break;
}
}
}
break; break;
case Direction.Left: case Direction.Left:
isMoveable = IsMoveable(-_drawingObject.Step, 0); for (int i = _startX; i >= Convert.ToInt32(_drawingObject.Step / _size_x); i--)
{
for (int j = _startY; j <= _objHeight; j++)
{
if (_map[i, j] == _barrier)
{
isMoveable = false;
break;
}
}
}
break; break;
case Direction.Up: case Direction.Up:
isMoveable = IsMoveable(0, -_drawingObject.Step); for (int i = _startX; i <= _objWidth; i++)
{
for (int j = _startY; j >= Convert.ToInt32(_drawingObject.Step / _size_y); j--)
{
if (_map[i, j] == _barrier)
{
isMoveable = false;
break;
}
}
}
break; break;
case Direction.Down: case Direction.Down:
isMoveable = IsMoveable(0, _drawingObject.Step); for (int i = _startX; i <= _objWidth; i++)
{
for (int j = _objHeight; j <= _objHeight + Convert.ToInt32(_drawingObject.Step / _size_y); j++)
{
if (_map[i, j] == _barrier)
{
isMoveable = false;
break;
}
}
}
break; break;
} }
@ -93,17 +107,21 @@ namespace ProjectPlane
int x = _random.Next(0, 10); int x = _random.Next(0, 10);
int y = _random.Next(0, 10); int y = _random.Next(0, 10);
_drawingObject.SetObject(x, y, _width, _height); _drawingObject.SetObject(x, y, _width, _height);
while (!IsMoveable(0, 0))
{
x += 5;
if (x < _width) for (int i = 0; i < _map.GetLength(0); ++i)
{
for (int j = 0; j < _map.GetLength(1); ++j)
{ {
x = 0; if (i * _size_x >= x && j * _size_y >= y &&
y += 5; i * _size_x <= x + _drawingObject.GetCurrentPosition().Right &&
j * _size_y <= j + _drawingObject.GetCurrentPosition().Bottom)
{
if (_map[i, j] == _barrier)
{
return false;
}
}
} }
_drawingObject.SetObject(x, y, _width, _height);
} }
return true; return true;