Lisov N.A. Lab_work2 #2

Merged
eegov merged 11 commits from LabWork02 into LabWork01 2022-09-30 09:43:17 +04:00
Showing only changes of commit 517fc78f0c - Show all commits

View File

@ -24,6 +24,7 @@ namespace AirFighter
_height = height;
_drawingObject = drawingObject;
GenerateMap();
while (!SetObjectOnMap())
{
GenerateMap();
@ -37,7 +38,7 @@ namespace AirFighter
int CollisionFlag = 0;
Size objSize1 = new Size(100,100);
@ -56,9 +57,10 @@ namespace AirFighter
Rectangle objectRect = new Rectangle(LeftTop, objSize1);
Rectangle rectBarrier = new Rectangle((int)(i * _size_x), (int)(j * _size_y), (int)_size_x, (int)(_size_y));
if (objectRect.Contains(rectBarrier))
Rectangle rectBarrier = new Rectangle((int)(i * _size_x), (int)(j * _size_y), (int)_size_x, (int)_size_y);
if (objectRect.IntersectsWith(rectBarrier))
{
CollisionFlag = 1;
}
@ -78,9 +80,9 @@ namespace AirFighter
Point LeftTop = new Point((int)_drawingObject.GetCurrentPosition().Left, (int)(_drawingObject.GetCurrentPosition().Top + _drawingObject.Step));
Rectangle objectRect = new Rectangle(LeftTop, objSize1);
Rectangle rectBarrier = new Rectangle((int)(i * _size_x), (int)(j * _size_y), (int)(_size_x + 1), (int)(_size_y + 1));
Rectangle rectBarrier = new Rectangle((int)(i * _size_x), (int)(j * _size_y),(int) _size_x,(int) _size_y);
if (objectRect.Contains(rectBarrier))
if (objectRect.IntersectsWith(rectBarrier))
{
CollisionFlag = 1;
}
@ -101,10 +103,9 @@ namespace AirFighter
Rectangle objectRect = new Rectangle(LeftTop, objSize1);
Rectangle rectBarrier = new Rectangle((int)(i * _size_x), (int)(j * _size_y), (int)(_size_x + 1), (int)(_size_y + 1));
Rectangle rectBarrier = new Rectangle((int)(i * _size_x), (int)(j * _size_y), (int)_size_x, (int)_size_y);
if (objectRect.Contains(rectBarrier))
if (objectRect.IntersectsWith(rectBarrier))
{
CollisionFlag = 1;
}
@ -124,9 +125,11 @@ namespace AirFighter
Rectangle objectRect = new Rectangle(LeftTop, objSize1);
Rectangle rectBarrier = new Rectangle((int)(i * _size_x), (int)(j * _size_y), (int)(_size_x + 1), (int)(_size_y + 1));
if (objectRect.Contains(rectBarrier))
Rectangle rectBarrier = new Rectangle((int)(i * _size_x), (int)(j * _size_y), (int)_size_x, (int)_size_y);
if (objectRect.IntersectsWith(rectBarrier))
{
CollisionFlag = 1;
}
@ -138,6 +141,7 @@ namespace AirFighter
if (CollisionFlag != 1)
{
_drawingObject.MoveObject(direction);
_drawingObject.DoSomething();
}
return DrawMapWithObject();
}
@ -153,7 +157,27 @@ namespace AirFighter
int x = _random.Next(0, 10);
int y = _random.Next(0,10);
_drawingObject.SetObject(x, y, _width, _height);
//CHECK IF BARRIER IS ALREADY SPAWANED ON OBJECT SPAWN
Rectangle rectObject = new Rectangle(x, y, 100, 100);
for (int i = 0; i < _map.GetLength(0); i++)
{
for (int j = 0; j < _map.GetLength(1); j++)
{
if (_map[i, j] == _barrier)
{
Rectangle rectBarrier = new Rectangle((int)(i * _size_x), (int)(j * _size_y), (int)_size_x, (int)_size_y);
if (rectObject.IntersectsWith(rectBarrier))
{
return false;
}
}
}
}
return true;
}
@ -184,10 +208,14 @@ namespace AirFighter
return bmp;
}
protected abstract void GenerateMap();
protected abstract void DrawRoadPart(Graphics g, int i, int j);
protected abstract void DrawBarrierPart(Graphics g, int i, int j);
}
}