196 lines
6.9 KiB
Java
196 lines
6.9 KiB
Java
import java.awt.*;
|
|
import java.util.Random;
|
|
|
|
public class DrawingAirbus {
|
|
public EntityAirbus Airbus;
|
|
protected float _startPosX;
|
|
protected float _startPosY;
|
|
private Integer _pictureWidth = null;
|
|
private Integer _pictureHeight = null;
|
|
private int _airbusWidth = 125;
|
|
private int _airbusHeight = 45;
|
|
|
|
public IDrawingIlum drawingilum;
|
|
|
|
private final Random random = new Random();
|
|
public DrawingAirbus(int speed, float weight, Color bodyColor)
|
|
{
|
|
int randExtra = random.nextInt(2);
|
|
switch (random.nextInt(3)){
|
|
case 0:
|
|
drawingilum = new DrawingPlusIlum(randExtra);
|
|
break;
|
|
case 1:
|
|
drawingilum = new DrawingSquareIlum(randExtra);
|
|
break;
|
|
case 2:
|
|
drawingilum = new DrawingIlum(randExtra, bodyColor);
|
|
break;
|
|
}
|
|
Airbus = new EntityAirbus(speed, weight, bodyColor);
|
|
}
|
|
// Новый конструктор
|
|
protected DrawingAirbus (int speed, float weight, Color bodyColor, int airbusWidth, int airbusHeight)
|
|
{
|
|
this(speed, weight, bodyColor);
|
|
_airbusWidth = airbusWidth;
|
|
_airbusHeight = airbusHeight;
|
|
}
|
|
public void SetPosition(int x, int y, int width, int height)
|
|
{
|
|
if (x < 0 || x + _airbusWidth >= width)
|
|
{
|
|
return;
|
|
}
|
|
if (y < 0 || y + _airbusHeight >= height)
|
|
{
|
|
return;
|
|
}
|
|
_startPosX = x;
|
|
_startPosY = y;
|
|
_pictureWidth = width;
|
|
_pictureHeight = height;
|
|
}
|
|
public void MoveTransport(Direction direction)
|
|
{
|
|
if (_pictureWidth == null || _pictureHeight == null)
|
|
{
|
|
return;
|
|
}
|
|
switch (direction)
|
|
{
|
|
// вправо
|
|
case Right:
|
|
if (_startPosX + _airbusWidth + Airbus.Step() < _pictureWidth)
|
|
{
|
|
_startPosX += Airbus.Step();
|
|
}
|
|
else _startPosX = _pictureWidth - _airbusWidth;
|
|
break;
|
|
//влево
|
|
case Left:
|
|
if (_startPosX - Airbus.Step() >= 0)
|
|
{
|
|
_startPosX -= Airbus.Step();
|
|
}
|
|
else _startPosX = 0;
|
|
break;
|
|
//вверх
|
|
case Up:
|
|
if (_startPosY - Airbus.Step() >= 0)
|
|
{
|
|
_startPosY -= Airbus.Step();
|
|
}
|
|
else _startPosY = 0;
|
|
break;
|
|
|
|
//вниз
|
|
case Down:
|
|
if (_startPosY + _airbusHeight + Airbus.Step() < _pictureHeight)
|
|
{
|
|
_startPosY += Airbus.Step();
|
|
}
|
|
else _startPosY = _pictureHeight - _airbusWidth;
|
|
break;
|
|
}
|
|
}
|
|
public void DrawTransport(Graphics2D g)
|
|
{
|
|
if (_startPosX < 0 || _startPosY < 0
|
|
|| _pictureHeight == null|| _pictureWidth == 0)
|
|
{
|
|
return;
|
|
}
|
|
g.setColor(Color.black);
|
|
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
|
|
);
|
|
|
|
// корпус
|
|
|
|
g.setColor(Airbus.getBodyColor());
|
|
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);
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
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);
|
|
}
|
|
|
|
public void ChangeBorders(int width, int height)
|
|
{
|
|
_pictureWidth = width;
|
|
_pictureHeight = height;
|
|
if (_pictureWidth <= _airbusWidth || _pictureHeight <= _airbusHeight)
|
|
{
|
|
_pictureWidth = null;
|
|
_pictureHeight = null;
|
|
return;
|
|
}
|
|
if (_startPosX + _airbusWidth > _pictureWidth)
|
|
{
|
|
_startPosX = _pictureWidth - _airbusWidth;
|
|
}
|
|
if (_startPosY + _airbusHeight > _pictureHeight)
|
|
{
|
|
_startPosY = _pictureHeight - _airbusHeight;
|
|
}
|
|
}
|
|
public float[] GetCurrentPosition()
|
|
{
|
|
return new float[] {/*UP*/_startPosY, /*RIGHT*/ _startPosX + _airbusWidth, /*DOWN*/ _startPosY + _airbusHeight, /*LEFT*/ _startPosX};
|
|
}
|
|
}
|