Не работает коллизия
This commit is contained in:
parent
f1f865331b
commit
9d01e9ae66
@ -32,12 +32,69 @@ namespace AirBomber
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
|
||||
private bool CanMove(Direction direction, (float Left, float Right, float Top, float Bottom) position)
|
||||
{
|
||||
if (direction == Direction.Left)
|
||||
{
|
||||
for (int i = (int)((position.Left - _drawningObject.Step) / _size_y); i <= (int)(position.Left / _size_y); ++i)
|
||||
{
|
||||
for (int j = (int)(position.Top / _size_x); j <= (int)(position.Bottom / _size_x); ++j)
|
||||
{
|
||||
if (i >= 0 && _map[i,j] == _barrier)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (direction == Direction.Right)
|
||||
{
|
||||
for (int i = (int)(position.Right / _size_y); i <= (int)((position.Right + _drawningObject.Step) / _size_y); ++i)
|
||||
{
|
||||
for (int j = (int)(position.Top / _size_x); j <= (int)(position.Bottom / _size_x); ++j)
|
||||
{
|
||||
if (i <= _map.GetLength(0) && _map[i, j] == _barrier)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (direction == Direction.Up)
|
||||
{
|
||||
for (int i = (int)(position.Left / _size_y); i <= (int)(position.Right / _size_y); ++i)
|
||||
{
|
||||
for (int j = (int)((position.Top - _drawningObject.Step) / _size_x); j <= (int)(position.Top / _size_x); ++j)
|
||||
{
|
||||
if (j >= 0 && _map[i, j] == _barrier)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (direction == Direction.Down)
|
||||
{
|
||||
for (int i = (int)(position.Left / _size_y); i <= (int)(position.Right / _size_y); ++i)
|
||||
{
|
||||
for (int j = (int)(position.Bottom / _size_x); j <= (int)((position.Bottom + _drawningObject.Step) / _size_x); ++j)
|
||||
{
|
||||
if (j <= _map.GetLength(1) && _map[i, j] == _barrier)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public Bitmap MoveObject(Direction direction)
|
||||
{
|
||||
//TODO
|
||||
if (true)
|
||||
{
|
||||
if (CanMove(direction, _drawningObject.GetCurrentPosition()))
|
||||
{
|
||||
_drawningObject.MoveObject(direction);
|
||||
|
||||
}
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
|
@ -133,7 +133,7 @@ namespace AirBomber
|
||||
|
||||
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
|
||||
{
|
||||
return (_startPosX, _startPosY, _startPosX + _airBomberWidth, _airBomberHeight);
|
||||
return (_startPosX, _startPosX + _airBomberWidth, _startPosY, _startPosY + _airBomberHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,12 +13,12 @@ namespace AirBomber
|
||||
|
||||
protected override void DrawBarrierPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(barrierColor, i * _size_x, j * _size_y, 20, 20);
|
||||
g.FillRectangle(barrierColor, j * _size_x, i * _size_y, _size_x, _size_y);
|
||||
}
|
||||
|
||||
protected override void DrawRoadPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(roadColor, i * _size_x, j * _size_y, 20, 20);
|
||||
g.FillRectangle(roadColor, j * _size_x, i * _size_y, _size_x, _size_y);
|
||||
}
|
||||
|
||||
protected override void GenerateMap()
|
||||
|
Loading…
Reference in New Issue
Block a user