157 lines
4.8 KiB
C#
157 lines
4.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace AirFighter
|
|
{
|
|
internal class DrawingAirFighter
|
|
{
|
|
public EntityAirFighter AirFighter { get; private set; }
|
|
|
|
private float _startPosX;
|
|
private float _startPosY;
|
|
|
|
private int? _pictureWidth = null;
|
|
private int? _pictureHeight = null;
|
|
|
|
private readonly int _airFighterWidth = 195;
|
|
private readonly int _airFighterHeight = 166;
|
|
|
|
public void Init(int speed, float weight, Color bodyColor)
|
|
{
|
|
AirFighter = new EntityAirFighter();
|
|
AirFighter.Init(speed, weight, bodyColor);
|
|
}
|
|
|
|
public void SetPosition(int x, int y, int width, int height)
|
|
{
|
|
if (width < _airFighterWidth || height < _airFighterHeight) return;
|
|
|
|
if (x + _airFighterWidth > width || x < 0) return;
|
|
if (y + _airFighterHeight > height || y < 0) return;
|
|
|
|
_startPosX = x;
|
|
_startPosY = y;
|
|
|
|
_pictureWidth = width;
|
|
_pictureHeight = height;
|
|
}
|
|
|
|
public void MoveTransport(Direction direction)
|
|
{
|
|
if (!_pictureWidth.HasValue || !_pictureHeight.HasValue)
|
|
{
|
|
return;
|
|
}
|
|
|
|
|
|
switch (direction)
|
|
{
|
|
case Direction.Right:
|
|
if (_startPosX + _airFighterWidth + AirFighter.Step < _pictureWidth)
|
|
{
|
|
_startPosX += AirFighter.Step;
|
|
}
|
|
break;
|
|
case Direction.Left:
|
|
if (_startPosX - AirFighter.Step > 0)
|
|
{
|
|
_startPosX -= AirFighter.Step;
|
|
}
|
|
break;
|
|
case Direction.Up:
|
|
if (_startPosY - AirFighter.Step > 0)
|
|
{
|
|
_startPosY -= AirFighter.Step;
|
|
}
|
|
break;
|
|
case Direction.Down:
|
|
if (_startPosY + _airFighterHeight + AirFighter.Step < _pictureHeight)
|
|
{
|
|
_startPosY += AirFighter.Step;
|
|
}
|
|
break;
|
|
}
|
|
|
|
}
|
|
|
|
public void DrawTransport(Graphics g)
|
|
{
|
|
if (!_pictureWidth.HasValue || !_pictureHeight.HasValue)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Pen pen = new(AirFighter.BodyColor);
|
|
Brush brushBlack = new SolidBrush(AirFighter.BodyColor);
|
|
|
|
PointF[] front = {
|
|
new(_startPosX + 160, _startPosY + 70),
|
|
new(_startPosX + 195, _startPosY + 83),
|
|
new(_startPosX + 160, _startPosY + 96)
|
|
};
|
|
|
|
PointF[] tailTop = {
|
|
new(_startPosX, _startPosY + 30),
|
|
new(_startPosX, _startPosY + 70),
|
|
new(_startPosX + 25, _startPosY + 70),
|
|
new(_startPosX + 25, _startPosY + 55)
|
|
};
|
|
|
|
PointF[] tailBottom = {
|
|
new(_startPosX, _startPosY + 96),
|
|
new(_startPosX, _startPosY + 136),
|
|
new(_startPosX + 25, _startPosY + 111),
|
|
new(_startPosX + 25, _startPosY + 96)
|
|
};
|
|
|
|
PointF[] wingTop =
|
|
{
|
|
new(_startPosX + 100, _startPosY),
|
|
new(_startPosX + 100, _startPosY + 70),
|
|
new(_startPosX + 75, _startPosY + 70),
|
|
new(_startPosX + 90, _startPosY),
|
|
};
|
|
|
|
|
|
PointF[] wingBottom =
|
|
{
|
|
new(_startPosX + 100, _startPosY + 96),
|
|
new(_startPosX + 100, _startPosY + 166),
|
|
new(_startPosX + 90, _startPosY + 166),
|
|
new(_startPosX + 75, _startPosY + 96),
|
|
};
|
|
|
|
g.FillPolygon(brushBlack, front);
|
|
g.DrawPolygon(pen, tailTop);
|
|
g.DrawPolygon(pen, tailBottom);
|
|
g.DrawPolygon(pen, wingTop);
|
|
g.DrawPolygon(pen, wingBottom);
|
|
g.DrawRectangle(pen, _startPosX, _startPosY + 70, 160, 26);
|
|
}
|
|
|
|
public void ChangeBorders(int width, int height)
|
|
{
|
|
_pictureWidth = width;
|
|
_pictureHeight = height;
|
|
if (_pictureWidth <= _airFighterWidth || _pictureHeight <= _airFighterHeight)
|
|
{
|
|
_pictureWidth = null;
|
|
_pictureHeight = null;
|
|
return;
|
|
}
|
|
if (_startPosX + _airFighterWidth > _pictureWidth)
|
|
{
|
|
_startPosX = _pictureWidth.Value - _airFighterWidth;
|
|
}
|
|
if (_startPosY + _airFighterHeight > _pictureHeight)
|
|
{
|
|
_startPosY = _pictureHeight.Value - _airFighterHeight;
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|