Исправление выхода за границы массива
This commit is contained in:
parent
10a75c38fc
commit
9e57fd3aeb
@ -32,17 +32,17 @@ namespace WarPlanes
|
|||||||
}
|
}
|
||||||
public Bitmap MoveObject(Direction direction)
|
public Bitmap MoveObject(Direction direction)
|
||||||
{
|
{
|
||||||
// TODO проверка, что объект может переместится в требуемом направлении
|
|
||||||
float xStep = 0;
|
|
||||||
float yStep = 0;
|
|
||||||
RectangleF rectObject = _drawningObject.GetCurrentPosition();
|
RectangleF rectObject = _drawningObject.GetCurrentPosition();
|
||||||
|
|
||||||
if (direction == Direction.Up) yStep = -_drawningObject.Step;
|
if (direction == Direction.Up) rectObject.Y -= _drawningObject.Step;
|
||||||
else if (direction == Direction.Down) yStep = +_drawningObject.Step;
|
else if (direction == Direction.Down) rectObject.Y += _drawningObject.Step;
|
||||||
else if (direction == Direction.Left) xStep = -_drawningObject.Step;
|
else if (direction == Direction.Left) rectObject.X -= _drawningObject.Step;
|
||||||
else if (direction == Direction.Right) xStep = _drawningObject.Step;
|
else if (direction == Direction.Right) rectObject.X += _drawningObject.Step;
|
||||||
rectObject.X += xStep;
|
|
||||||
rectObject.Y += yStep;
|
if(rectObject.X < 0 || rectObject.Right >= _width || rectObject.Y < 0 || rectObject.Bottom >= _height)
|
||||||
|
{
|
||||||
|
return DrawMapWithObject();
|
||||||
|
}
|
||||||
if (isCollision(rectObject))
|
if (isCollision(rectObject))
|
||||||
{
|
{
|
||||||
_drawningObject.MoveObject(direction);
|
_drawningObject.MoveObject(direction);
|
||||||
|
@ -29,7 +29,6 @@
|
|||||||
void IDrawningObject.DrawningObject(Graphics g)
|
void IDrawningObject.DrawningObject(Graphics g)
|
||||||
{
|
{
|
||||||
_warplane.DrawTransport(g);
|
_warplane.DrawTransport(g);
|
||||||
// TODO
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user