2022-10-17 23:06:21 +04:00
|
|
|
import java.awt.*;
|
2022-11-21 23:55:09 +04:00
|
|
|
public class DrawingAirbus {
|
|
|
|
public EntityAirbus Airbus;
|
2022-10-17 23:06:21 +04:00
|
|
|
private float _startPosX;
|
|
|
|
private float _startPosY;
|
|
|
|
private Integer _pictureWidth = null;
|
|
|
|
private Integer _pictureHeight = null;
|
2022-11-21 23:55:09 +04:00
|
|
|
private final int _airbusWidth = 125;
|
|
|
|
private final int _airbusHeight = 45;
|
2022-10-17 23:06:21 +04:00
|
|
|
|
2022-11-08 14:53:44 +04:00
|
|
|
public DrawingIlum drawingilum;
|
2022-11-21 23:55:09 +04:00
|
|
|
public void Init(int speed, float weight, Color bodyColor, int ilNum, EntityAirbus entity)
|
2022-10-17 23:06:21 +04:00
|
|
|
{
|
2022-11-21 23:55:09 +04:00
|
|
|
Airbus = entity;
|
2022-11-08 14:53:44 +04:00
|
|
|
drawingilum = new DrawingIlum();
|
|
|
|
drawingilum.Init(ilNum, bodyColor);
|
2022-11-21 23:55:09 +04:00
|
|
|
Airbus.Init(speed, weight, bodyColor);
|
2022-10-17 23:06:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetPosition(int x, int y, int width, int height)
|
|
|
|
{
|
2022-11-21 23:55:09 +04:00
|
|
|
if (x < 0 || x + _airbusWidth >= width)
|
2022-10-17 23:06:21 +04:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2022-11-21 23:55:09 +04:00
|
|
|
if (y < 0 || y + _airbusHeight >= height)
|
2022-10-17 23:06:21 +04:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_startPosX = x;
|
|
|
|
_startPosY = y;
|
|
|
|
_pictureWidth = width;
|
|
|
|
_pictureHeight = height;
|
|
|
|
}
|
|
|
|
public void MoveTransport(Direction direction)
|
|
|
|
{
|
|
|
|
if (_pictureWidth == null || _pictureHeight == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
switch (direction)
|
|
|
|
{
|
|
|
|
// вправо
|
|
|
|
case Right:
|
2022-11-21 23:55:09 +04:00
|
|
|
if (_startPosX + _airbusWidth + Airbus.Step() < _pictureWidth)
|
2022-10-17 23:06:21 +04:00
|
|
|
{
|
2022-11-21 23:55:09 +04:00
|
|
|
_startPosX += Airbus.Step();
|
2022-10-17 23:06:21 +04:00
|
|
|
}
|
2022-11-21 23:55:09 +04:00
|
|
|
else _startPosX = _pictureWidth - _airbusWidth;
|
2022-10-17 23:06:21 +04:00
|
|
|
break;
|
|
|
|
//влево
|
|
|
|
case Left:
|
2022-11-21 23:55:09 +04:00
|
|
|
if (_startPosX - Airbus.Step() >= 0)
|
2022-10-17 23:06:21 +04:00
|
|
|
{
|
2022-11-21 23:55:09 +04:00
|
|
|
_startPosX -= Airbus.Step();
|
2022-10-17 23:06:21 +04:00
|
|
|
}
|
2022-11-08 14:53:44 +04:00
|
|
|
else _startPosX = 0;
|
2022-10-17 23:06:21 +04:00
|
|
|
break;
|
|
|
|
//вверх
|
|
|
|
case Up:
|
2022-11-21 23:55:09 +04:00
|
|
|
if (_startPosY - Airbus.Step() >= 0)
|
2022-10-17 23:06:21 +04:00
|
|
|
{
|
2022-11-21 23:55:09 +04:00
|
|
|
_startPosY -= Airbus.Step();
|
2022-10-17 23:06:21 +04:00
|
|
|
}
|
2022-11-08 14:53:44 +04:00
|
|
|
else _startPosY = 0;
|
2022-10-17 23:06:21 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
//вниз
|
|
|
|
case Down:
|
2022-11-21 23:55:09 +04:00
|
|
|
if (_startPosY + _airbusHeight + Airbus.Step() < _pictureHeight)
|
2022-10-17 23:06:21 +04:00
|
|
|
{
|
2022-11-21 23:55:09 +04:00
|
|
|
_startPosY += Airbus.Step();
|
2022-10-17 23:06:21 +04:00
|
|
|
}
|
2022-11-21 23:55:09 +04:00
|
|
|
else _startPosY = _pictureHeight - _airbusWidth;
|
2022-10-17 23:06:21 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-11-08 14:53:44 +04:00
|
|
|
public void DrawTransport(Graphics2D g)
|
2022-10-17 23:06:21 +04:00
|
|
|
{
|
|
|
|
if (_startPosX < 0 || _startPosY < 0
|
|
|
|
|| _pictureHeight == null|| _pictureWidth == 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2022-11-08 14:53:44 +04:00
|
|
|
g.setColor(Color.black);
|
2022-10-17 23:06:21 +04:00
|
|
|
g.drawOval((int)_startPosX, (int)_startPosY + 20, 20, 20);
|
|
|
|
|
|
|
|
g.drawRect((int)_startPosX + 8, (int)_startPosY + 20, 100, 20);
|
|
|
|
|
|
|
|
g.drawPolygon
|
|
|
|
(
|
|
|
|
new int[] {(int)_startPosX + 108, (int)_startPosX + 125, (int)_startPosX + 108},
|
|
|
|
new int[] {(int)_startPosY + 18, (int)_startPosY + 30, (int)_startPosY + 30}, 3
|
|
|
|
);
|
|
|
|
g.drawPolygon
|
|
|
|
(
|
|
|
|
new int[] {(int)_startPosX + 108, (int)_startPosX + 125, (int)_startPosX + 108},
|
|
|
|
new int[] {(int)_startPosY + 30, (int)_startPosY + 30, (int)_startPosY + 42}, 3
|
|
|
|
);
|
|
|
|
g.drawPolygon
|
|
|
|
(
|
|
|
|
new int[] {(int)_startPosX + 5, (int)_startPosX + 5, (int)_startPosX + 35},
|
|
|
|
new int[] {(int)_startPosY + 20, (int)_startPosY, (int)_startPosY + 20}, 3
|
|
|
|
);
|
|
|
|
|
|
|
|
// корпус
|
|
|
|
|
2022-11-21 23:55:09 +04:00
|
|
|
g.setColor(Airbus.getBodyColor());
|
2022-10-17 23:06:21 +04:00
|
|
|
g.fillOval((int)_startPosX, (int)_startPosY + 20, 20, 20);
|
|
|
|
|
|
|
|
g.fillRect((int)_startPosX + 8, (int)_startPosY + 20, 100, 20);
|
|
|
|
|
|
|
|
g.fillPolygon
|
|
|
|
(
|
|
|
|
new int[] {(int)_startPosX + 108, (int)_startPosX + 125, (int)_startPosX + 108},
|
|
|
|
new int[] {(int)_startPosY + 30, (int)_startPosY + 30, (int)_startPosY + 42}, 3
|
|
|
|
);
|
|
|
|
g.fillPolygon
|
|
|
|
(
|
|
|
|
new int[] {(int)_startPosX + 5, (int)_startPosX + 5, (int)_startPosX + 35},
|
|
|
|
new int[] {(int)_startPosY + 20, (int)_startPosY, (int)_startPosY + 20}, 3
|
|
|
|
);
|
|
|
|
g.setColor(Color.blue);
|
2022-11-08 14:53:44 +04:00
|
|
|
|
|
|
|
for (int tempX = 98; tempX > 38; tempX -= 6) {
|
|
|
|
g.fillOval((int) _startPosX + tempX, (int)_startPosY + 20, 4, 4);
|
|
|
|
}
|
|
|
|
drawingilum.DrawIl((int)_startPosX, (int)_startPosY, g);
|
|
|
|
|
2022-10-17 23:06:21 +04:00
|
|
|
g.fillPolygon
|
|
|
|
(
|
|
|
|
new int[] {(int)_startPosX + 108, (int)_startPosX + 125, (int)_startPosX + 108},
|
|
|
|
new int[] {(int)_startPosY + 18, (int)_startPosY + 30, (int)_startPosY + 30}, 3
|
|
|
|
);
|
|
|
|
g.setColor(Color.black);
|
|
|
|
g.drawLine((int)_startPosX + 37, (int)_startPosY + 40, (int)_startPosX + 37, (int)_startPosY + 45);
|
|
|
|
g.drawLine((int)_startPosX + 32, (int)_startPosY + 45, (int)_startPosX + 40, (int)_startPosY + 45);
|
|
|
|
g.fillRect((int)_startPosX + 32, (int)_startPosY + 45, 3, 3);
|
|
|
|
g.fillRect((int)_startPosX + 39, (int)_startPosY + 45, 3, 3);
|
|
|
|
|
|
|
|
g.drawLine((int)_startPosX + 102, (int)_startPosY + 40, (int)_startPosX + 102, (int)_startPosY + 45);
|
|
|
|
g.fillRect((int)_startPosX + 101, (int)_startPosY + 45, 3, 3);
|
|
|
|
|
|
|
|
g.fillRect((int)_startPosX + 5, (int)_startPosY + 18, 18, 7);
|
|
|
|
g.fillOval((int)_startPosX, (int)_startPosY + 18, 7, 7);
|
|
|
|
g.fillOval((int)_startPosX + 20, (int)_startPosY + 18, 7, 7);
|
|
|
|
|
2022-11-08 14:53:44 +04:00
|
|
|
g.fillRect((int)_startPosX + 41, (int)_startPosY + 34, 42, 4);
|
|
|
|
g.fillOval((int)_startPosX + 39, (int)_startPosY + 34, 4, 4);
|
|
|
|
g.fillOval((int)_startPosX + 81, (int)_startPosY + 34, 4, 4);
|
2022-10-17 23:06:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public void ChangeBorders(int width, int height)
|
|
|
|
{
|
|
|
|
_pictureWidth = width;
|
|
|
|
_pictureHeight = height;
|
2022-11-21 23:55:09 +04:00
|
|
|
if (_pictureWidth <= _airbusWidth || _pictureHeight <= _airbusHeight)
|
2022-10-17 23:06:21 +04:00
|
|
|
{
|
|
|
|
_pictureWidth = null;
|
|
|
|
_pictureHeight = null;
|
|
|
|
return;
|
|
|
|
}
|
2022-11-21 23:55:09 +04:00
|
|
|
if (_startPosX + _airbusWidth > _pictureWidth)
|
2022-10-17 23:06:21 +04:00
|
|
|
{
|
2022-11-21 23:55:09 +04:00
|
|
|
_startPosX = _pictureWidth - _airbusWidth;
|
2022-10-17 23:06:21 +04:00
|
|
|
}
|
2022-11-21 23:55:09 +04:00
|
|
|
if (_startPosY + _airbusHeight > _pictureHeight)
|
2022-10-17 23:06:21 +04:00
|
|
|
{
|
2022-11-21 23:55:09 +04:00
|
|
|
_startPosY = _pictureHeight - _airbusHeight;
|
2022-10-17 23:06:21 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|