2023-10-08 18:09:17 +04:00
|
|
|
package ProjectStormtrooper;
|
|
|
|
|
|
|
|
import java.awt.*;
|
2023-10-09 22:31:20 +04:00
|
|
|
import java.util.Random;
|
2023-10-08 18:09:17 +04:00
|
|
|
|
|
|
|
public class DrawingPlane {
|
|
|
|
public EntityPlane EntityPlane;
|
2023-10-09 22:31:20 +04:00
|
|
|
protected IDrawingEngines _drawingEngines;
|
2023-10-08 19:37:29 +04:00
|
|
|
protected int _pictureWidth;
|
|
|
|
protected int _pictureHeight;
|
2023-10-08 18:09:17 +04:00
|
|
|
protected int _startPosX;
|
|
|
|
protected int _startPosY;
|
|
|
|
protected int _planeWidth = 110;
|
|
|
|
protected int _planeHeight = 110;
|
|
|
|
|
|
|
|
public int GetPosX() {
|
|
|
|
return _startPosX;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int GetPosY() {
|
|
|
|
return _startPosY;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int GetWidth() {
|
|
|
|
return _planeWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int GetHeight() {
|
|
|
|
return _planeHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
public DrawingPlane(int speed, double weight, Color bodyColor, int width, int height) {
|
|
|
|
if (width < _planeWidth && height < _planeHeight) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_pictureWidth = width;
|
|
|
|
_pictureHeight = height;
|
|
|
|
EntityPlane = new EntityPlane(speed, weight, bodyColor);
|
2023-10-09 22:31:20 +04:00
|
|
|
Random random = new Random();
|
|
|
|
int drawingEnginesType = random.nextInt(0, 3);
|
|
|
|
if (drawingEnginesType == 0)
|
2023-10-10 12:26:20 +04:00
|
|
|
_drawingEngines = new DrawingEnginesSimple();
|
2023-10-09 22:31:20 +04:00
|
|
|
else if (drawingEnginesType == 1)
|
2023-10-10 12:26:20 +04:00
|
|
|
_drawingEngines = new DrawingEnginesPyramid();
|
2023-10-09 22:31:20 +04:00
|
|
|
else if (drawingEnginesType == 2)
|
2023-10-10 12:26:20 +04:00
|
|
|
_drawingEngines = new DrawingEnginesEllipse();
|
2023-10-08 18:09:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
protected DrawingPlane(int speed, double weight, Color bodyColor,
|
|
|
|
int width, int height, int planeWidth, int planeHeight) {
|
2023-10-09 22:31:20 +04:00
|
|
|
this(speed, weight, bodyColor, width, height);
|
2023-10-08 18:09:17 +04:00
|
|
|
_planeWidth = planeWidth;
|
|
|
|
_planeHeight = planeHeight;
|
|
|
|
}
|
2023-10-20 12:17:34 +04:00
|
|
|
|
2023-10-08 19:37:29 +04:00
|
|
|
public void SetEnginesCount(int enginesCount) {
|
|
|
|
_drawingEngines.SetEnumEnginesCount(enginesCount);
|
|
|
|
}
|
2023-10-08 18:09:17 +04:00
|
|
|
|
|
|
|
public boolean CanMove(EnumDirectionType direction) {
|
|
|
|
if (EntityPlane == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
boolean result = false;
|
|
|
|
switch (direction) {
|
|
|
|
case Up -> result = _startPosY - EntityPlane.Step() > 0;
|
|
|
|
case Down -> result = _startPosY + _planeHeight + EntityPlane.Step() < _pictureHeight;
|
|
|
|
case Left -> result = _startPosX - EntityPlane.Step() > 0;
|
|
|
|
case Right -> result = _startPosX + _planeWidth + EntityPlane.Step() < _pictureWidth;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetPosition(int x, int y) {
|
|
|
|
if (x < 0) {
|
|
|
|
x = 0;
|
|
|
|
} else if (x > _pictureWidth - _planeWidth) {
|
|
|
|
x = _pictureWidth - _planeWidth;
|
|
|
|
}
|
|
|
|
_startPosX = x;
|
|
|
|
|
|
|
|
if (y < 0) {
|
|
|
|
y = 0;
|
|
|
|
} else if (y > _pictureHeight - _planeHeight) {
|
|
|
|
y = _pictureHeight - _planeHeight;
|
|
|
|
}
|
|
|
|
_startPosY = y;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void MoveTransport(EnumDirectionType direction) {
|
|
|
|
if (EntityPlane == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
switch (direction) {
|
|
|
|
case Up -> {
|
|
|
|
if (_startPosY - EntityPlane.Step() >= 0) {
|
|
|
|
_startPosY -= (int) EntityPlane.Step();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case Down -> {
|
|
|
|
if (_startPosY + _planeHeight + EntityPlane.Step() <= _pictureHeight) {
|
|
|
|
_startPosY += (int) EntityPlane.Step();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case Left -> {
|
|
|
|
if (_startPosX - EntityPlane.Step() >= 0) {
|
|
|
|
_startPosX -= (int) EntityPlane.Step();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case Right -> {
|
|
|
|
if (_startPosX + _planeWidth + EntityPlane.Step() <= _pictureWidth) {
|
|
|
|
_startPosX += (int) EntityPlane.Step();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void DrawTransport(Graphics g) {
|
|
|
|
if (EntityPlane == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Graphics2D g2d = (Graphics2D) g;
|
|
|
|
|
2023-10-20 22:43:07 +04:00
|
|
|
g2d.setStroke(new BasicStroke(2));
|
|
|
|
|
2023-10-08 18:09:17 +04:00
|
|
|
Color bodyColor = EntityPlane.BodyColor;
|
|
|
|
Color blackColor = Color.BLACK;
|
|
|
|
|
|
|
|
// Длина фюзеляжа
|
|
|
|
int bodyHeight = _planeHeight / 9;
|
|
|
|
int bodyWidth = _planeWidth - _planeWidth / 8;
|
|
|
|
|
2023-10-08 19:37:29 +04:00
|
|
|
_drawingEngines.DrawEngines(g, bodyColor, _startPosX, _startPosY, _planeWidth, _planeHeight);
|
|
|
|
|
2023-10-08 18:09:17 +04:00
|
|
|
// Рисуем нос
|
|
|
|
Polygon cockPitPolygon = new Polygon();
|
|
|
|
cockPitPolygon.addPoint(_startPosX, _startPosY + _planeHeight / 2);
|
|
|
|
cockPitPolygon.addPoint(_startPosX + _planeWidth / 8, _startPosY + _planeHeight / 2 - bodyHeight / 2);
|
|
|
|
cockPitPolygon.addPoint(_startPosX + _planeWidth / 8, _startPosY + _planeHeight / 2 + bodyHeight / 2);
|
|
|
|
|
|
|
|
g2d.setColor(blackColor);
|
|
|
|
g2d.fillPolygon(cockPitPolygon);
|
|
|
|
|
|
|
|
// Рисуем крылья
|
|
|
|
Polygon wingsPolygon = new Polygon();
|
|
|
|
wingsPolygon.addPoint(_startPosX + _planeWidth / 2, _startPosY);
|
|
|
|
wingsPolygon.addPoint(_startPosX + _planeWidth / 2 + _planeWidth / 15, _startPosY);
|
|
|
|
wingsPolygon.addPoint(_startPosX + _planeWidth / 2 + _planeWidth / 6, _startPosY + _planeHeight / 2);
|
|
|
|
wingsPolygon.addPoint(_startPosX + _planeWidth / 2 + _planeWidth / 15, _startPosY + _planeHeight);
|
|
|
|
wingsPolygon.addPoint(_startPosX + _planeWidth / 2, _startPosY + _planeHeight);
|
|
|
|
|
|
|
|
g2d.setColor(bodyColor);
|
|
|
|
g.fillPolygon(wingsPolygon);
|
|
|
|
g2d.setColor(blackColor);
|
|
|
|
g.drawPolygon(wingsPolygon);
|
|
|
|
|
|
|
|
// Рисуем хвостовое оперение
|
|
|
|
Polygon tailPolygon = new Polygon();
|
|
|
|
tailPolygon.addPoint(_startPosX + _planeWidth, _startPosY + _planeHeight / 2 - _planeHeight / 3);
|
|
|
|
tailPolygon.addPoint(_startPosX + bodyWidth, _startPosY + _planeHeight / 2 - _planeHeight / 8);
|
|
|
|
tailPolygon.addPoint(_startPosX + bodyWidth, _startPosY + _planeHeight / 2 + _planeHeight / 8);
|
|
|
|
tailPolygon.addPoint(_startPosX + _planeWidth, _startPosY + _planeHeight / 2 + _planeHeight / 3);
|
|
|
|
|
|
|
|
g2d.setColor(bodyColor);
|
|
|
|
g.fillPolygon(tailPolygon);
|
|
|
|
g2d.setColor(blackColor);
|
|
|
|
g.drawPolygon(tailPolygon);
|
|
|
|
|
|
|
|
// Рисуем фюзеляж
|
|
|
|
g2d.setColor(bodyColor);
|
|
|
|
g2d.fillRect(
|
|
|
|
_startPosX + _planeWidth / 8,
|
|
|
|
_startPosY + _planeHeight / 2 - bodyHeight / 2,
|
|
|
|
bodyWidth,
|
|
|
|
bodyHeight
|
|
|
|
);
|
|
|
|
g2d.setColor(blackColor);
|
|
|
|
g2d.drawRect(
|
|
|
|
_startPosX + _planeWidth / 8,
|
|
|
|
_startPosY + _planeHeight / 2 - bodyHeight / 2,
|
|
|
|
bodyWidth,
|
|
|
|
bodyHeight
|
|
|
|
);
|
|
|
|
}
|
2023-10-20 12:17:34 +04:00
|
|
|
|
|
|
|
public IMoveableObject GetMoveableObject() {
|
|
|
|
return new DrawingObjectPlane(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
;
|
2023-10-08 18:09:17 +04:00
|
|
|
}
|