251 lines
8.6 KiB
C#
251 lines
8.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Drawing.Drawing2D;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace AirFighter
|
|
{
|
|
internal class DrawingAircraft
|
|
{
|
|
public EntityAircraft Plane { get; protected set; }
|
|
|
|
protected float _startPosX;
|
|
|
|
protected float _startPosY;
|
|
|
|
private int? _pictureWidth = null;
|
|
private int? _pictureHeight = null;
|
|
|
|
private readonly int _aircraftWidth = 100;
|
|
private readonly int _aircraftHeight = 100;
|
|
|
|
public DrawingAircraft(int speed, float weight, Color bodyColor)
|
|
{
|
|
Plane = new EntityAircraft(speed, weight, bodyColor);
|
|
}
|
|
|
|
protected DrawingAircraft(int speed, float weight, Color bodyColor, int aircraftWidth, int aircraftHeight) : this(speed, weight,bodyColor)
|
|
{
|
|
|
|
_aircraftHeight = aircraftHeight;
|
|
_aircraftWidth = aircraftWidth;
|
|
}
|
|
|
|
public void SetPosition(int x, int y, int width, int height)
|
|
{
|
|
|
|
if (x + _aircraftWidth > width || x < 0 || y + _aircraftHeight > height || y < 0)
|
|
{
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
_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 + _aircraftWidth + Plane.Step < _pictureWidth)
|
|
{
|
|
_startPosX += Plane.Step;
|
|
}
|
|
}
|
|
break;
|
|
case Direction.Left:
|
|
{
|
|
if (_startPosX - Plane.Step > 0)
|
|
{
|
|
_startPosX -= Plane.Step;
|
|
}
|
|
}
|
|
break;
|
|
case Direction.Up:
|
|
{
|
|
if (_startPosY - Plane.Step > 0)
|
|
{
|
|
_startPosY -= Plane.Step;
|
|
}
|
|
}
|
|
break;
|
|
case Direction.Down:
|
|
{
|
|
if (_startPosY + _aircraftHeight + Plane.Step < _pictureHeight)
|
|
{
|
|
_startPosY += Plane.Step;
|
|
}
|
|
}
|
|
break;
|
|
case Direction.UpRight:
|
|
{
|
|
if (_startPosY - Plane.Step > 0 && _startPosX + _aircraftWidth + Plane.Step < _pictureWidth)
|
|
{
|
|
_startPosY -= Plane.Step;
|
|
_startPosX += Plane.Step;
|
|
}
|
|
}
|
|
break;
|
|
case Direction.UpLeft:
|
|
{
|
|
if (_startPosY - Plane.Step > 0 && _startPosX - Plane.Step > 0)
|
|
{
|
|
_startPosX -= Plane.Step;
|
|
_startPosY -= Plane.Step;
|
|
|
|
}
|
|
}
|
|
break;
|
|
case Direction.DownRight:
|
|
{
|
|
if (_startPosY + _aircraftHeight + Plane.Step < _pictureHeight && _startPosX + _aircraftWidth + Plane.Step < _pictureWidth)
|
|
{
|
|
_startPosY += Plane.Step;
|
|
_startPosX += Plane.Step;
|
|
}
|
|
}
|
|
break;
|
|
case Direction.DownLeft:
|
|
{
|
|
if (_startPosY + _aircraftHeight + Plane.Step < _pictureHeight && _startPosX - Plane.Step > 0)
|
|
{
|
|
_startPosY += Plane.Step;
|
|
_startPosX -= Plane.Step;
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
public virtual void DrawTransport(Graphics g)
|
|
{
|
|
if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
|
{
|
|
return;
|
|
}
|
|
|
|
|
|
|
|
//Aircraft Body
|
|
Pen pen = new(Color.Black);
|
|
Brush brWhite = new SolidBrush(Plane.BodyColor);
|
|
|
|
g.FillRectangle(brWhite, _startPosX + 20, _startPosY + 45, 80, 14);
|
|
g.DrawRectangle(pen,_startPosX + 20, _startPosY + 45, 80, 14);
|
|
|
|
//Wings
|
|
|
|
GraphicsPath pathWing1 = new GraphicsPath();
|
|
|
|
Point point1B = new Point((int)(_startPosX + 50), (int)(_startPosY + 45));
|
|
Point point2B = new Point(point1B.X, point1B.Y - 40);
|
|
Point point3B = new Point(point2B.X + 6, point2B.Y);
|
|
Point point4B = new Point(point3B.X + 27, point1B.Y);
|
|
Point[] pointsWings = new Point[] { point1B, point2B, point3B, point4B };
|
|
|
|
pathWing1.AddLines(pointsWings);
|
|
g.DrawPath(pen, pathWing1);
|
|
g.FillPath(brWhite, pathWing1);
|
|
|
|
|
|
GraphicsPath pathWing2 = new GraphicsPath();
|
|
|
|
Point point1B2 = new Point((int)(_startPosX + 50), (int)(_startPosY + 60));
|
|
Point point2B2 = new Point(point1B2.X, point1B2.Y + 40);
|
|
Point point3B2 = new Point(point2B2.X + 6, point2B2.Y);
|
|
Point point4B2 = new Point(point3B2.X + 27, point1B2.Y);
|
|
Point[] pointsWings2 = new Point[] { point1B2, point2B2, point3B2, point4B2 };
|
|
|
|
pathWing2.AddLines(pointsWings2);
|
|
g.DrawPath(pen, pathWing2);
|
|
g.FillPath(brWhite, pathWing2);
|
|
|
|
|
|
//BackWings
|
|
GraphicsPath pathBackWing1 = new GraphicsPath();
|
|
|
|
Point point1W = new Point((int)(_startPosX + 85), (int)(_startPosY + 45));
|
|
Point point2W = new Point(point1W.X, point1W.Y - 7);
|
|
Point point3W = new Point(point2W.X + 15, point2W.Y - 16);
|
|
Point point4W = new Point(point3W.X, point1W.Y);
|
|
Point[] pointsBackWing1 = new Point[] { point1W, point2W, point3W, point4W };
|
|
|
|
pathBackWing1.AddLines(pointsBackWing1);
|
|
g.DrawPath(pen, pathBackWing1);
|
|
g.FillPath(brWhite, pathBackWing1);
|
|
|
|
GraphicsPath pathBackWing2 = new GraphicsPath();
|
|
|
|
Point point1W2 = new Point((int)(_startPosX + 85), (int)(_startPosY + 60));
|
|
Point point2W2 = new Point(point1W2.X, point1W2.Y + 7);
|
|
Point point3W2 = new Point(point2W2.X + 15, point2W2.Y +16);
|
|
Point point4W2 = new Point(point3W2.X, point1W2.Y);
|
|
Point[] pointsBackWing2 = new Point[] { point1W2, point2W2, point3W2, point4W2 };
|
|
|
|
pathBackWing2.AddLines(pointsBackWing2);
|
|
g.DrawPath(pen,pathBackWing2);
|
|
g.FillPath(brWhite,pathBackWing2);
|
|
|
|
Brush brBlack = new SolidBrush(Color.Black);
|
|
|
|
//Nose
|
|
GraphicsPath pathBoseBody = new GraphicsPath();
|
|
|
|
Point point1N = new Point((int)(_startPosX + 20), (int)(_startPosY + 45));
|
|
Point point2N = new Point(point1N.X - 15 ,point1N.Y + 7);
|
|
Point point3N = new Point(point1N.X, point1N.Y + 15);
|
|
|
|
Point[] pointsBoseBody = new Point[] { point1N,point2N,point3N};
|
|
|
|
pathBoseBody.AddLines(pointsBoseBody);
|
|
g.FillPath(brBlack,pathBoseBody);
|
|
|
|
|
|
|
|
}
|
|
|
|
public void ChangeBorders(int width, int height)
|
|
{
|
|
_pictureWidth = width;
|
|
_pictureHeight = height;
|
|
|
|
if (_pictureWidth <= _aircraftWidth || _pictureHeight <= _aircraftHeight)
|
|
{
|
|
_pictureHeight = null;
|
|
_pictureWidth = null;
|
|
return;
|
|
}
|
|
if (_startPosX + _aircraftWidth > _pictureWidth)
|
|
{
|
|
_startPosX = _pictureWidth.Value - _aircraftWidth;
|
|
}
|
|
if (_startPosY + _aircraftHeight > _pictureHeight)
|
|
{
|
|
_startPosY = _pictureHeight.Value - _aircraftHeight;
|
|
}
|
|
|
|
}
|
|
|
|
public (float Left, float Top, float Right, float Bottom) GetCurrentPosition()
|
|
{
|
|
return (_startPosX, _startPosY, _startPosX + _aircraftWidth - 1, _startPosY + _aircraftHeight - 1);
|
|
}
|
|
}
|
|
}
|