PIbd-12_Karamushko_M.K._Air.../DrawingAircraft.java

147 lines
4.4 KiB
Java
Raw Normal View History

2022-10-28 15:45:35 +04:00
import java.awt.*;
class DrawingAircraft
{
public EntityAircraft AirFighter;
private float _startPosX;
private float _startPosY;
private int _pictureWidth = -1;
private int _pictureHeight = -1;
private int _airFighterWidth = 195;
private int _airFighterHeight = 166;
public void Init(int speed, float weight, Color bodyColor)
{
AirFighter = new EntityAircraft();
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 == -1 || _pictureHeight == -1)
{
return;
}
switch (direction)
{
case Right:
if (_startPosX + _airFighterWidth + AirFighter.Step < _pictureWidth)
{
_startPosX += AirFighter.Step;
}
break;
case Left:
if (_startPosX - AirFighter.Step > 0)
{
_startPosX -= AirFighter.Step;
}
break;
case Up:
if (_startPosY - AirFighter.Step > 0)
{
_startPosY -= AirFighter.Step;
}
break;
case Down:
if (_startPosY + _airFighterHeight + AirFighter.Step < _pictureHeight)
{
_startPosY += AirFighter.Step;
}
break;
}
}
public void DrawTransport(Graphics2D g)
{
if (_pictureWidth == -1 || _pictureHeight == -1)
{
return;
}
g.setPaint(AirFighter.BodyColor);
Polygon front = new Polygon();
front.addPoint((int)(_startPosX + 160), (int)(_startPosY + 70));
front.addPoint((int)(_startPosX + 195), (int)(_startPosY + 83));
front.addPoint((int)(_startPosX + 160), (int)(_startPosY + 96));
Polygon tailTop = new Polygon();
tailTop.addPoint((int)(_startPosX), (int)(_startPosY + 30));
tailTop.addPoint((int)(_startPosX), (int)(_startPosY + 70));
tailTop.addPoint((int)(_startPosX + 25), (int)(_startPosY + 70));
tailTop.addPoint((int)(_startPosX + 25), (int)(_startPosY + 55));
Polygon tailBottom = new Polygon();
tailBottom.addPoint((int)(_startPosX), (int)(_startPosY + 96));
tailBottom.addPoint((int)(_startPosX), (int)(_startPosY + 136));
tailBottom.addPoint((int)(_startPosX + 25), (int)(_startPosY + 111));
tailBottom.addPoint((int)(_startPosX + 25), (int)(_startPosY + 96));
Polygon wingTop = new Polygon();
wingTop.addPoint((int)(_startPosX + 100), (int)(_startPosY));
wingTop.addPoint((int)(_startPosX + 100), (int)(_startPosY + 70));
wingTop.addPoint((int)(_startPosX + 75), (int)(_startPosY + 70));
wingTop.addPoint((int)(_startPosX + 90), (int)(_startPosY));
Polygon wingBottom = new Polygon();
wingBottom.addPoint((int)(_startPosX + 100), (int)(_startPosY + 96));
wingBottom.addPoint((int)(_startPosX + 100), (int)(_startPosY + 166));
wingBottom.addPoint((int)(_startPosX + 90), (int)(_startPosY + 166));
wingBottom.addPoint((int)(_startPosX + 75), (int)(_startPosY + 96));
g.fillPolygon(front);
g.drawPolygon(tailTop);
g.drawPolygon(tailBottom);
g.drawPolygon(wingTop);
g.drawPolygon(wingBottom);
g.drawRect((int)_startPosX, (int)_startPosY + 70, 160, 26);
}
public void ChangeBorders(int width, int height)
{
_pictureWidth = width;
_pictureHeight = height;
if (_pictureWidth <= _airFighterWidth || _pictureHeight <= _airFighterHeight)
{
_pictureWidth = -1;
_pictureHeight = -1;
return;
}
if (_startPosX + _airFighterWidth > _pictureWidth)
{
_startPosX = _pictureWidth - _airFighterWidth;
}
if (_startPosY + _airFighterHeight > _pictureHeight)
{
_startPosY = _pictureHeight - _airFighterHeight;
}
}
}