136 lines
5.2 KiB
Java
Raw Normal View History

2023-12-02 20:06:46 +04:00
import java.awt.*;
public class DrawingAir {
protected EntityAir entityAir;
2023-12-30 09:28:39 +04:00
protected void setEntityAir(EntityAir entityAir){this.entityAir = entityAir;}
public EntityAir getEntityAir() {
2023-12-02 20:06:46 +04:00
return entityAir;
}
private IDrawEngines drawingEngines;
private int _pictureWidth;
private int _pictureHeight;
protected int _startPosX;
2023-12-30 09:28:39 +04:00
public int getPosX(){return _startPosX;}
2023-12-02 20:06:46 +04:00
protected int _startPosY;
2023-12-30 09:28:39 +04:00
public int getPosY(){return _startPosY;}
2023-12-02 20:06:46 +04:00
private final int _PlaneWidth = 160;
2023-12-30 09:28:39 +04:00
public int getWidth(){return _PlaneWidth;}
2023-12-02 20:06:46 +04:00
private final int _PlaneHeight = 160;
2023-12-30 09:28:39 +04:00
public int getHeight(){return _PlaneHeight;}
2023-12-02 20:06:46 +04:00
public DrawingAir(int speed, double weight, Color bodyColor, int width, int height, int enginesType, int enginesNumber) {
if (width < _PlaneWidth || height < _PlaneHeight)
return;
_pictureWidth = width;
_pictureHeight = height;
entityAir = new EntityAir(speed, weight, bodyColor);
switch (enginesType){
case 1:
2023-12-30 09:28:39 +04:00
drawingEngines = new DrawingEnginesOval();
2023-12-02 20:06:46 +04:00
break;
case 2:
drawingEngines = new DrawingEnginesRound();
break;
default:
2023-12-30 09:28:39 +04:00
drawingEngines = new DrawingEnginesSquare();
2023-12-02 20:06:46 +04:00
break;
}
drawingEngines.setNumber(enginesNumber);
}
2023-12-30 09:28:39 +04:00
public IMoveableObject GetMoveableObject() {return new DrawingObjectPlane(this);}
public void setPosition(int x, int y) {
if (x < 0 || y < 0 || x + _PlaneWidth > _pictureWidth || y + _PlaneHeight > _pictureHeight)
x = y = 0;
2023-12-02 20:06:46 +04:00
_startPosX = x;
_startPosY = y;
}
public void drawTransport(Graphics2D g) {
if (entityAir == null)
return;
BasicStroke pen = new BasicStroke(2);
Color penColor = Color.BLACK;
Color bodyColor = entityAir.getBodyColor();
g.setStroke(pen);
g.setColor(bodyColor);
//фюзеляж
g.fillRect(_startPosX + 20, _startPosY + 70, 140, 20);
//кабина
int[] pointX = new int[]{_startPosX, _startPosX + 20, _startPosX + 20};
int[] pointY = new int[]{_startPosY + 80, _startPosY + 70, _startPosY + 90};
g.setColor(Color.BLACK);
g.fillPolygon(pointX, pointY, 3);
//границы самолета
g.setColor(penColor);
g.drawPolygon(pointX, pointY, 3);
g.drawRect(_startPosX + 20, _startPosY + 70, 140, 20);
//Крылья
pointX = new int[]{_startPosX + 70, _startPosX + 70, _startPosX + 90, _startPosX + 100};
pointY = new int[]{_startPosY + 70, _startPosY, _startPosY, _startPosY + 70};
g.setColor(bodyColor);
g.fillPolygon(pointX, pointY, 4);
g.setColor(penColor);
g.drawPolygon(pointX, pointY, 4);
pointX = new int[]{_startPosX + 70, _startPosX + 70, _startPosX + 90, _startPosX + 100};
pointY = new int[]{_startPosY + 90, _startPosY + 160, _startPosY + 160, _startPosY + 90};
g.setColor(bodyColor);
g.fillPolygon(pointX, pointY, 4);
g.setColor(penColor);
g.drawPolygon(pointX, pointY, 4);
pointX = new int[]{_startPosX + 130, _startPosX + 130, _startPosX + 160, _startPosX + 160};
pointY = new int[]{_startPosY + 70, _startPosY + 50, _startPosY + 30, _startPosY + 70};
g.setColor(bodyColor);
g.fillPolygon(pointX, pointY, 4);
g.setColor(penColor);
g.drawPolygon(pointX, pointY, 4);
pointX = new int[]{_startPosX + 130, _startPosX + 130, _startPosX + 160, _startPosX + 160};
pointY = new int[]{_startPosY + 90, _startPosY + 110, _startPosY + 130, _startPosY + 90};
g.setColor(bodyColor);
g.fillPolygon(pointX, pointY, 4);
g.setColor(penColor);
g.drawPolygon(pointX, pointY, 4);
drawingEngines.drawEngines(g, _startPosX, _startPosY);
}
public boolean canMove(DirectionType direction) {
if (entityAir == null) {
return false;
}
switch(direction) {
case LEFT:
return _startPosX - entityAir.step.get().intValue() > 0;
case UP:
return _startPosY - entityAir.step.get().intValue() > 0;
case RIGHT:
return _startPosX + entityAir.step.get().intValue() + _PlaneWidth < _pictureWidth;
case DOWN:
2023-12-30 09:28:39 +04:00
return _startPosY + entityAir.step.get().intValue() + _PlaneWidth < _pictureHeight;
2023-12-02 20:06:46 +04:00
default:
return false;
}
}
public void moveTransport(DirectionType direction)
{
2023-12-30 09:28:39 +04:00
if (!canMove(direction) || entityAir == null)
2023-12-02 20:06:46 +04:00
return;
switch (direction)
{
2023-12-30 09:28:39 +04:00
//влево
2023-12-02 20:06:46 +04:00
case LEFT:
2023-12-30 09:28:39 +04:00
_startPosX -= entityAir.step.get().intValue();
2023-12-02 20:06:46 +04:00
break;
2023-12-30 09:28:39 +04:00
//вверх
2023-12-02 20:06:46 +04:00
case UP:
2023-12-30 09:28:39 +04:00
_startPosY -= entityAir.step.get().intValue();
2023-12-02 20:06:46 +04:00
break;
2023-12-30 09:28:39 +04:00
// вправо
2023-12-02 20:06:46 +04:00
case RIGHT:
2023-12-30 09:28:39 +04:00
_startPosX += entityAir.step.get().intValue();
2023-12-02 20:06:46 +04:00
break;
2023-12-30 09:28:39 +04:00
//вниз
2023-12-02 20:06:46 +04:00
case DOWN:
2023-12-30 09:28:39 +04:00
_startPosY += entityAir.step.get().intValue();
2023-12-02 20:06:46 +04:00
break;
}
}
}