166 lines
5.7 KiB
Java
166 lines
5.7 KiB
Java
import java.awt.*;
|
|
public class DrawingPlane {
|
|
public EntityPlane Plane;
|
|
|
|
public EntityPlane getPlane()
|
|
{
|
|
return Plane;
|
|
}
|
|
private float _startPosX;
|
|
private float _startPosY;
|
|
private Integer _pictureWidth = null;
|
|
private Integer _pictureHeight = null;
|
|
private final int _planeWidth = 125;
|
|
private final int _planeHeight = 45;
|
|
|
|
public void Init(int speed, float weight, Color bodyColor, int ilNum, EntityPlane entity)
|
|
{
|
|
Plane = new EntityPlane();
|
|
Plane.Init(speed, weight, bodyColor);
|
|
}
|
|
|
|
public void SetPosition(int x, int y, int width, int height)
|
|
{
|
|
if (x < 0 || x + _planeWidth >= width)
|
|
{
|
|
return;
|
|
}
|
|
if (y < 0 || y + _planeHeight >= 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 + _planeWidth + Plane.Step() < _pictureWidth)
|
|
{
|
|
_startPosX += Plane.Step();
|
|
}
|
|
break;
|
|
//влево
|
|
case Left:
|
|
if (_startPosX - Plane.Step() > 0)
|
|
{
|
|
_startPosX -= Plane.Step();
|
|
}
|
|
break;
|
|
//вверх
|
|
case Up:
|
|
if (_startPosY - Plane.Step() > 0)
|
|
{
|
|
_startPosY -= Plane.Step();
|
|
}
|
|
break;
|
|
|
|
//вниз
|
|
case Down:
|
|
if (_startPosY + _planeHeight + Plane.Step() < _pictureHeight)
|
|
{
|
|
_startPosY += Plane.Step();
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
public void DrawTransport(Graphics 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(Plane.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);
|
|
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 + 28, 42, 4);
|
|
g.fillOval((int)_startPosX + 39, (int)_startPosY + 28, 4, 4);
|
|
g.fillOval((int)_startPosX + 81, (int)_startPosY + 28, 4, 4);
|
|
}
|
|
|
|
public void ChangeBorders(int width, int height)
|
|
{
|
|
_pictureWidth = width;
|
|
_pictureHeight = height;
|
|
if (_pictureWidth <= _planeWidth || _pictureHeight <= _planeHeight)
|
|
{
|
|
_pictureWidth = null;
|
|
_pictureHeight = null;
|
|
return;
|
|
}
|
|
if (_startPosX + _planeWidth > _pictureWidth)
|
|
{
|
|
_startPosX = _pictureWidth - _planeWidth;
|
|
}
|
|
if (_startPosY + _planeHeight > _pictureHeight)
|
|
{
|
|
_startPosY = _pictureHeight - _planeHeight;
|
|
}
|
|
}
|
|
}
|