Добавлен класс для прорисовки простого объекта
This commit is contained in:
parent
9c8cc5cd23
commit
2182968867
211
ProjectStormtrooper/ProjectStormtrooper/DrawingPlane.cs
Normal file
211
ProjectStormtrooper/ProjectStormtrooper/DrawingPlane.cs
Normal file
@ -0,0 +1,211 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectStormtrooper
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawingPlane
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityPlane? EntityPlane{ get; protected set; }
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
private int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна
|
||||
/// </summary>
|
||||
private int _pictureHeight;
|
||||
/// <summary>
|
||||
/// Левая координата начала прорисовки
|
||||
/// </summary>
|
||||
private int _startPosX;
|
||||
/// <summary>
|
||||
/// Верхняя координата начала прорисовки
|
||||
/// </summary>
|
||||
private int _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина прорисовки
|
||||
/// </summary>
|
||||
private readonly int _planeWidth = 110;
|
||||
/// <summary>
|
||||
/// Высота прорисовки
|
||||
/// </summary>
|
||||
private readonly int _planeHeight = 110;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="width">Ширина картинки</param>
|
||||
/// <param name="height">Высота картинки</param>
|
||||
public DrawingPlane(int speed, double weight, Color bodyColor, int width, int height)
|
||||
{
|
||||
if (width < _planeWidth && height < _planeHeight)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
EntityPlane = new EntityPlane(speed, weight, bodyColor);
|
||||
}
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="width">Ширина окна</param>
|
||||
/// <param name="height">Высота окна</param>
|
||||
/// <param name="planeWidth">Ширина объекта</param>
|
||||
/// <param name="planeHeight">Высота объекта</param>
|
||||
protected DrawingPlane(int speed, double weight, Color bodyColor,
|
||||
int width, int height, int planeWidth, int planeHeight)
|
||||
{
|
||||
if (width < planeWidth && height < planeHeight)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
_planeWidth = planeWidth;
|
||||
_planeHeight = planeHeight;
|
||||
EntityPlane = new EntityPlane(speed, weight, bodyColor);
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка позиции
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (x < 0)
|
||||
{
|
||||
x = 0;
|
||||
}
|
||||
else if (x > _pictureWidth - _planeWidth)
|
||||
{
|
||||
x = _pictureWidth - _planeWidth;
|
||||
}
|
||||
_startPosX = x;
|
||||
|
||||
if (y < 0)
|
||||
{
|
||||
y = 0;
|
||||
}
|
||||
else if (y > _pictureHeight - _planeHeight)
|
||||
{
|
||||
y = _pictureHeight - _planeHeight;
|
||||
}
|
||||
_startPosY = y;
|
||||
}
|
||||
/// <summary>
|
||||
/// Перемещение объекта
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление перемещения</param>
|
||||
public void MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityPlane == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
// Вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY - EntityPlane.Step >= 0)
|
||||
{
|
||||
_startPosY -= (int)EntityPlane.Step;
|
||||
}
|
||||
break;
|
||||
// Вниз
|
||||
case DirectionType.Down:
|
||||
if (_startPosY + _planeHeight + EntityPlane.Step <= _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityPlane.Step;
|
||||
}
|
||||
break;
|
||||
// Влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX - EntityPlane.Step >= 0)
|
||||
{
|
||||
_startPosX -= (int)EntityPlane.Step;
|
||||
}
|
||||
break;
|
||||
// Вправо
|
||||
case DirectionType.Right:
|
||||
if (_startPosX + _planeWidth + EntityPlane.Step <= _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntityPlane.Step;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityPlane == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen penBlack = new Pen(Color.Black);
|
||||
Brush brushBlack = new SolidBrush(Color.Black);
|
||||
Brush brushBodyColor = new SolidBrush(EntityPlane.BodyColor);
|
||||
|
||||
// Высота фюзеляжа
|
||||
int bodyHeight = _planeHeight / 9;
|
||||
|
||||
// Рисуем нос
|
||||
|
||||
Point[] pointsCockPit = {
|
||||
new Point(_startPosX, _startPosY + _planeHeight / 2),
|
||||
new Point(_startPosX + _planeWidth / 8, _startPosY + _planeHeight / 2 - bodyHeight / 2),
|
||||
new Point(_startPosX + _planeWidth / 8, _startPosY + _planeHeight / 2 + bodyHeight / 2)
|
||||
};
|
||||
|
||||
g.FillPolygon(brushBlack, pointsCockPit);
|
||||
|
||||
// Рисуем крылья
|
||||
|
||||
Point[] pointsWings = {
|
||||
new Point(_startPosX + _planeWidth / 2, _startPosY),
|
||||
new Point(_startPosX + _planeWidth / 2 + _planeWidth / 15, _startPosY),
|
||||
new Point(_startPosX + _planeWidth / 2 + _planeWidth / 6, _startPosY + _planeHeight / 2),
|
||||
new Point(_startPosX + _planeWidth / 2 + _planeWidth / 15, _startPosY + _planeHeight),
|
||||
new Point(_startPosX + _planeWidth / 2 , _startPosY + _planeHeight)
|
||||
};
|
||||
|
||||
g.FillPolygon(brushBodyColor, pointsWings);
|
||||
g.DrawPolygon(penBlack, pointsWings);
|
||||
|
||||
// Рисуем хвостовое оперение
|
||||
|
||||
Point[] pointsTail = {
|
||||
new Point(_startPosX + _planeWidth, _startPosY + _planeHeight / 2 - _planeHeight / 3),
|
||||
new Point(_startPosX + _planeWidth - _planeWidth / 8, _startPosY + _planeHeight / 2 - _planeHeight / 8),
|
||||
new Point(_startPosX + _planeWidth - _planeWidth / 8, _startPosY + _planeHeight / 2 + _planeHeight / 8),
|
||||
new Point(_startPosX + _planeWidth, _startPosY + _planeHeight / 2 + _planeHeight / 3)
|
||||
|
||||
};
|
||||
|
||||
g.FillPolygon(brushBodyColor, pointsTail);
|
||||
g.DrawPolygon(penBlack, pointsTail);
|
||||
|
||||
// Рисуем фюзеляж
|
||||
|
||||
g.FillRectangle(brushBodyColor, _startPosX + _planeWidth / 8, _startPosY + _planeHeight / 2 - bodyHeight / 2, _planeWidth - _planeWidth / 8, bodyHeight);
|
||||
g.DrawRectangle(penBlack, _startPosX + _planeWidth / 8, _startPosY + _planeHeight / 2 - bodyHeight / 2, _planeWidth - _planeWidth / 8, bodyHeight);
|
||||
}
|
||||
}
|
||||
}
|
@ -29,6 +29,12 @@ namespace ProjectStormtrooper
|
||||
/// Шаг перемещения
|
||||
/// </summary>
|
||||
public double Step => (double)Speed * 250 / Weight;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed"></param>
|
||||
/// <param name="weight"></param>
|
||||
/// <param name="bodyColor"></param>
|
||||
public EntityPlane(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
|
Loading…
Reference in New Issue
Block a user