192 lines
8.1 KiB
C#
192 lines
8.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing.Drawing2D;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace AirBomber
|
|
{
|
|
public class DrawningAirBomber
|
|
{
|
|
public EntityAirBomber? EntityAirBomber { get; private set; }
|
|
|
|
private int _pictureWeigth;
|
|
|
|
private int _pictureHeight;
|
|
|
|
private int _startPosX;
|
|
|
|
private int _startPosY;
|
|
|
|
private int _PlaneWidth = 160;
|
|
|
|
private int _PlaneHeight = 185;
|
|
|
|
public bool Init(int speed, int weight, Color bodycolor, Color dopcolor, bool bodykit, bool toplivo, bool rocket, int width, int height)
|
|
{
|
|
//TODO: Продумать проверки
|
|
if (weight < _pictureWeigth || height < _pictureHeight)
|
|
{
|
|
return false;
|
|
}
|
|
_pictureWeigth = width;
|
|
_pictureHeight = height;
|
|
EntityAirBomber = new EntityAirBomber();
|
|
EntityAirBomber.Init(speed, weight, bodycolor, dopcolor, bodykit, toplivo, rocket);
|
|
return true;
|
|
}
|
|
|
|
public void SetPosition(int x, int y)
|
|
{
|
|
|
|
//TODO: Изменения x, y
|
|
if (x <= _pictureWeigth - _PlaneWidth && x >= 0 && y <= _pictureHeight - _PlaneHeight && y >= 0)
|
|
{
|
|
_startPosX = x;
|
|
_startPosY = y;
|
|
}
|
|
}
|
|
|
|
public void MoveTransport(Diraction diraction)
|
|
{
|
|
if (EntityAirBomber == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
int step = (int)EntityAirBomber.Step;
|
|
|
|
switch (diraction)
|
|
{
|
|
case Diraction.Left:
|
|
if (_startPosX - step >= 0)
|
|
{
|
|
_startPosX -= step;
|
|
}
|
|
else
|
|
{
|
|
_startPosX = 0;
|
|
}
|
|
break;
|
|
case Diraction.Right:
|
|
if (_startPosX + step + _PlaneWidth <= _pictureWeigth)
|
|
{
|
|
_startPosX += step;
|
|
}
|
|
else
|
|
{
|
|
_startPosX = _pictureWeigth - _PlaneWidth;
|
|
}
|
|
break;
|
|
case Diraction.Up:
|
|
if (_startPosY - step >= 0)
|
|
{
|
|
_startPosY -= step;
|
|
}
|
|
else
|
|
{
|
|
_startPosY = 0;
|
|
}
|
|
break;
|
|
case Diraction.Down:
|
|
if (_startPosY + step + _PlaneHeight <= _pictureHeight)
|
|
{
|
|
_startPosY += step;
|
|
}
|
|
else
|
|
{
|
|
_startPosY = _pictureHeight - _PlaneHeight;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
public void DrawCar(Graphics g)
|
|
{
|
|
if (EntityAirBomber == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Pen pen = new(Color.Black);
|
|
Brush dopcolor = new SolidBrush(EntityAirBomber.DopColor);
|
|
if (EntityAirBomber.BodyKit)
|
|
{
|
|
//отрисовка ракет
|
|
GraphicsPath rocket_1 = new GraphicsPath();
|
|
rocket_1.AddLine(_startPosX + 70, _startPosY + 35, _startPosX + 80, _startPosY + 25);
|
|
rocket_1.AddLine(_startPosX + 80, _startPosY + 25, _startPosX + 80, _startPosY + 45);
|
|
rocket_1.CloseFigure();
|
|
g.FillPath(dopcolor, rocket_1);
|
|
g.DrawPath(Pens.Black, rocket_1);
|
|
GraphicsPath rocket_2 = new GraphicsPath();
|
|
rocket_2.AddLine(_startPosX + 70, _startPosY + 65, _startPosX + 80, _startPosY + 55);
|
|
rocket_2.AddLine(_startPosX + 80, _startPosY + 55, _startPosX + 80, _startPosY + 75);
|
|
rocket_2.CloseFigure();
|
|
g.FillPath(dopcolor, rocket_2);
|
|
g.DrawPath(Pens.Black, rocket_2);
|
|
GraphicsPath rocket_3 = new GraphicsPath();
|
|
rocket_3.AddLine(_startPosX + 70, _startPosY + 120, _startPosX + 80, _startPosY + 110);
|
|
rocket_3.AddLine(_startPosX + 80, _startPosY + 110, _startPosX + 80, _startPosY + 130);
|
|
rocket_3.CloseFigure();
|
|
g.FillPath(dopcolor, rocket_3);
|
|
g.DrawPath(Pens.Black, rocket_3);
|
|
GraphicsPath rocket_4 = new GraphicsPath();
|
|
rocket_4.AddLine(_startPosX + 70, _startPosY + 150, _startPosX + 80, _startPosY + 140);
|
|
rocket_4.AddLine(_startPosX + 80, _startPosY + 140, _startPosX + 80, _startPosY + 160);
|
|
rocket_4.CloseFigure();
|
|
g.FillPath(dopcolor, rocket_4);
|
|
g.DrawPath(Pens.Black, rocket_4);
|
|
//отрисовка баков
|
|
g.FillRectangle(dopcolor, _startPosX + 82, _startPosY + 5, 8, 10);
|
|
g.FillRectangle(dopcolor, _startPosX + 82, _startPosY + 25, 8, 10);
|
|
g.FillRectangle(dopcolor, _startPosX + 82, _startPosY + 45, 8, 10);
|
|
g.FillRectangle(dopcolor, _startPosX + 82, _startPosY + 130, 8, 10);
|
|
g.FillRectangle(dopcolor, _startPosX + 82, _startPosY + 150, 8, 10);
|
|
g.FillRectangle(dopcolor, _startPosX + 82, _startPosY + 170, 8, 10);
|
|
}
|
|
//g.DrawEllipse(pen, _startPosX + 90, _startPosY, 20, 20);
|
|
//g.DrawRectangle(pen, _startPosX + 90, _startPosY + 10,20, 40);
|
|
//отрисовка крыла 1
|
|
GraphicsPath fly_1 = new GraphicsPath();
|
|
fly_1.AddLine(_startPosX + 80, _startPosY + 2, _startPosX + 80, _startPosY + 80);
|
|
fly_1.AddLine(_startPosX + 80, _startPosY + 2, _startPosX + 90, _startPosY + 2);
|
|
fly_1.AddLine(_startPosX + 90, _startPosY + 2, _startPosX + 100, _startPosY + 80);
|
|
fly_1.AddLine(_startPosX + 100, _startPosY + 80, _startPosX + 80, _startPosY + 80);
|
|
g.DrawPath(Pens.Black, fly_1);
|
|
//отрисовка кабины пилота
|
|
GraphicsPath treygol = new GraphicsPath();
|
|
treygol.AddLine(_startPosX + 3, _startPosY + 95, _startPosX + 30, _startPosY + 80);
|
|
treygol.AddLine(_startPosX + 30, _startPosY + 80, _startPosX + 30, _startPosY + 105);
|
|
treygol.CloseFigure();
|
|
g.FillPath(Brushes.Black, treygol);
|
|
g.DrawPath(Pens.Black, treygol);
|
|
//отрисовка корпуса
|
|
g.DrawRectangle(pen, _startPosX + 30, _startPosY + 80, 120, 25);
|
|
//отрисовка крыла 2
|
|
GraphicsPath fly_2 = new GraphicsPath();
|
|
fly_2.AddLine(_startPosX + 80, _startPosY + 105, _startPosX + 80, _startPosY + 185);
|
|
fly_2.AddLine(_startPosX + 80, _startPosY + 185, _startPosX + 90, _startPosY + 185);
|
|
fly_2.AddLine(_startPosX + 90, _startPosY + 185, _startPosX + 100, _startPosY + 105);
|
|
fly_2.CloseFigure();
|
|
g.DrawPath(Pens.Black, fly_2);
|
|
//отриосвка хвоста
|
|
GraphicsPath wing = new GraphicsPath();
|
|
//wing.AddLine(_startPosX, _startPosY, _startPosX, _startPosY);
|
|
wing.AddLine(_startPosX + 135, _startPosY + 80, _startPosX + 135, _startPosY + 70);
|
|
wing.AddLine(_startPosX + 135, _startPosY + 70, _startPosX + 150, _startPosY + 50);
|
|
wing.AddLine(_startPosX + 150, _startPosY + 50, _startPosX + 150, _startPosY + 80);
|
|
wing.CloseFigure();
|
|
g.DrawPath(Pens.Black, wing);
|
|
GraphicsPath wing_2 = new GraphicsPath();
|
|
wing_2.AddLine(_startPosX + 135, _startPosY + 105, _startPosX + 135, _startPosY + 115);
|
|
wing_2.AddLine(_startPosX + 135, _startPosY + 115, _startPosX + 150, _startPosY + 135);
|
|
wing_2.AddLine(_startPosX + 150, _startPosY + 135, _startPosX + 150, _startPosY + 105);
|
|
wing_2.CloseFigure();
|
|
g.DrawPath(Pens.Black, wing_2);
|
|
}
|
|
}
|
|
}
|