192 lines
6.5 KiB
C#
192 lines
6.5 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Drawing;
|
||
using System.Drawing.Drawing2D;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using ProjectAirFighter.Entities;
|
||
using ProjectAirFighter.MovementStrategy;
|
||
|
||
namespace ProjectAirFighter.DrawningObjects
|
||
{
|
||
public class DrawningAirplane
|
||
{
|
||
public EntityAirplane? EntityAirplane { get; protected set; }
|
||
private int _pictureWidth;
|
||
private int _pictureHeight;
|
||
protected int _startPosX;
|
||
protected int _startPosY;
|
||
protected readonly int _airplaneWidth = 163;
|
||
protected readonly int _airplaneHeight = 160;
|
||
protected readonly int _airplanewingHeight = 70;
|
||
protected readonly int _airplanerwingkorpusHeight = 90;
|
||
public int GetPosX => _startPosX;
|
||
public int GetPosY => _startPosY;
|
||
public int GetWidth => _airplaneWidth;
|
||
public int GetHeight => _airplaneHeight;
|
||
public IMoveableObject GetMoveableObject => new DrawningObjectAirplane(this);
|
||
|
||
public DrawningAirplane(int speed, double weight, Color bodyColor,int width, int height)
|
||
{
|
||
if (width <= _airplaneWidth || height <= _airplanewingHeight)
|
||
return;
|
||
_pictureWidth = width;
|
||
_pictureHeight = height;
|
||
EntityAirplane = new EntityAirplane(speed, weight, bodyColor);
|
||
}
|
||
|
||
protected DrawningAirplane(int speed, double weight, Color bodyColor, int
|
||
width, int height, int airplaneWidth, int airplaneHeight)
|
||
{
|
||
if (width <= _airplaneWidth || height <= _airplanewingHeight)
|
||
return;
|
||
_pictureWidth = width;
|
||
_pictureHeight = height;
|
||
_airplaneWidth = airplaneWidth;
|
||
_airplanewingHeight = airplaneHeight;
|
||
EntityAirplane = new EntityAirplane(speed, weight, bodyColor);
|
||
}
|
||
public void ChangeColor(Color col)
|
||
{
|
||
if (EntityAirplane == null)
|
||
return;
|
||
EntityAirplane.BodyColor= col;
|
||
}
|
||
|
||
public void ChangePictureBoxSize(int pictureBoxWidth, int pictureBoxHeight)
|
||
{
|
||
_pictureHeight = pictureBoxHeight;
|
||
_pictureWidth = pictureBoxWidth;
|
||
}
|
||
public void SetPosition(int x, int y)
|
||
{
|
||
if (EntityAirplane == null)
|
||
return;
|
||
_startPosX = x;
|
||
_startPosY = y;
|
||
if (x + _airplaneWidth >= _pictureWidth || y + _airplaneHeight >= _pictureHeight)
|
||
{
|
||
_startPosX = 1;
|
||
_startPosY = (_airplanewingHeight+_airplanerwingkorpusHeight)/2;
|
||
}
|
||
}
|
||
public bool CanMove(DirectionType direction)
|
||
{
|
||
if (EntityAirplane == null)
|
||
{
|
||
return false;
|
||
}
|
||
return direction switch
|
||
{
|
||
DirectionType.Left => _startPosX - EntityAirplane.Step > 0,
|
||
|
||
DirectionType.Up => _startPosY - EntityAirplane.Step - (_airplaneHeight - _airplaneHeight * 125 / 1000) / 2 > 0,
|
||
|
||
DirectionType.Right => _startPosX+ EntityAirplane.Step + _airplaneWidth < _pictureWidth,
|
||
|
||
DirectionType.Down => _startPosY + EntityAirplane.Step + _airplanerwingkorpusHeight < _pictureHeight,
|
||
|
||
};
|
||
}
|
||
|
||
public void MoveTransport(DirectionType direction)
|
||
{
|
||
if (!CanMove(direction) || EntityAirplane == null)
|
||
|
||
{
|
||
return;
|
||
}
|
||
switch (direction)
|
||
{
|
||
case DirectionType.Left:
|
||
_startPosX -= (int)EntityAirplane.Step;
|
||
break;
|
||
|
||
case DirectionType.Up:
|
||
_startPosY -= (int)EntityAirplane.Step;
|
||
break;
|
||
|
||
case DirectionType.Right:
|
||
_startPosX += (int)EntityAirplane.Step;
|
||
break;
|
||
|
||
case DirectionType.Down:
|
||
_startPosY += (int)EntityAirplane.Step;
|
||
break;
|
||
}
|
||
}
|
||
|
||
public virtual void DrawTransport(Graphics g)
|
||
{
|
||
if (EntityAirplane == null)
|
||
{
|
||
return;
|
||
}
|
||
Pen pen = new(Color.Black);
|
||
|
||
Brush br = new SolidBrush(EntityAirplane.BodyColor);
|
||
Point[] nosePoints =
|
||
{
|
||
new Point(_startPosX + 20, _startPosY + 4),
|
||
new Point(_startPosX + 20, _startPosY + 24),
|
||
new Point(_startPosX-3,_startPosY + 12)
|
||
};
|
||
Brush brBlack = new SolidBrush(Color.Black);
|
||
g.FillPolygon(brBlack, nosePoints);
|
||
g.DrawPolygon(pen, nosePoints);
|
||
|
||
Point[] rightwingPoints =
|
||
{
|
||
new Point(_startPosX + 80, _startPosY + 4),
|
||
new Point(_startPosX+80,_startPosY - 64),
|
||
new Point(_startPosX+85,_startPosY - 64),
|
||
new Point(_startPosX + 100, _startPosY + 4)
|
||
|
||
};
|
||
|
||
g.DrawPolygon(pen, rightwingPoints);
|
||
g.FillPolygon(br, rightwingPoints);
|
||
|
||
Point[] lefttwingPoints =
|
||
{
|
||
new Point(_startPosX + 80, _startPosY + 24),
|
||
new Point(_startPosX + 100, _startPosY + 24),
|
||
new Point(_startPosX+85,_startPosY + 94),
|
||
new Point(_startPosX+80,_startPosY + 94)
|
||
|
||
};
|
||
|
||
g.DrawPolygon(pen, lefttwingPoints);
|
||
g.FillPolygon(br, lefttwingPoints);
|
||
|
||
Point[] leftenginePoints =
|
||
{
|
||
new Point(_startPosX + 140, _startPosY + 24),
|
||
new Point(_startPosX + 160, _startPosY + 24),
|
||
new Point(_startPosX+160,_startPosY + 50),
|
||
new Point(_startPosX+140,_startPosY + 32)
|
||
|
||
};
|
||
|
||
g.DrawPolygon(pen, leftenginePoints);
|
||
g.FillPolygon(br, leftenginePoints);
|
||
|
||
Point[] rightenginePoints =
|
||
{
|
||
new Point(_startPosX + 140, _startPosY + 24),
|
||
new Point(_startPosX + 160, _startPosY + 24),
|
||
new Point(_startPosX+160,_startPosY - 16),
|
||
new Point(_startPosX+140,_startPosY -4)
|
||
|
||
};
|
||
|
||
g.DrawPolygon(pen, rightenginePoints);
|
||
g.FillPolygon(br, rightenginePoints);
|
||
|
||
g.DrawRectangle(pen, _startPosX + 20, _startPosY + 4, 140, _airplaneHeight * 125 / 1000);
|
||
g.FillRectangle(br, _startPosX + 20, _startPosY + 4, 140, _airplaneHeight * 125 / 1000);
|
||
|
||
}
|
||
}
|
||
} |