import java.awt.*; import java.util.Random; class DrawingAircraft { public EntityAircraft AirFighter; public IDrawingEngines drawingEngines; protected float _startPosX; protected float _startPosY; private int _pictureWidth = -1; private int _pictureHeight = -1; private int _airFighterWidth = 195; private int _airFighterHeight = 166; private void peekRandomEngines(Color color) { Random rnd = new Random(); int randEngine = rnd.nextInt(1, 4); switch(randEngine) { case 1: drawingEngines = new DrawingEngines(rnd.nextInt(1, 8), color); break; case 2: drawingEngines = new DrawingTruncatedEngines(rnd.nextInt(1, 8), color); break; case 3: drawingEngines = new DrawingWavyEngines(rnd.nextInt(1, 8), color); break; } } public DrawingAircraft(int speed, float weight, Color bodyColor) { AirFighter = new EntityAircraft(speed, weight, bodyColor); peekRandomEngines(bodyColor); } public DrawingAircraft(int speed, float weight, Color bodyColor, int airFighterWidth, int airFighterHeight) { this(speed, weight, bodyColor); _airFighterWidth = airFighterWidth; _airFighterHeight = airFighterHeight; } public void SetPosition(int x, int y, int width, int height) { if (width < _airFighterWidth || height < _airFighterHeight) return; if (x + _airFighterWidth > width || x < 0) return; if (y + _airFighterHeight > height || y < 0) return; _startPosX = x; _startPosY = y; _pictureWidth = width; _pictureHeight = height; } public void MoveTransport(Direction direction) { if (_pictureWidth == -1 || _pictureHeight == -1) { return; } switch (direction) { case Right: if (_startPosX + _airFighterWidth + AirFighter.Step < _pictureWidth) { _startPosX += AirFighter.Step; } break; case Left: if (_startPosX - AirFighter.Step > 0) { _startPosX -= AirFighter.Step; } break; case Up: if (_startPosY - AirFighter.Step > 0) { _startPosY -= AirFighter.Step; } break; case Down: if (_startPosY + _airFighterHeight + AirFighter.Step < _pictureHeight) { _startPosY += AirFighter.Step; } break; } } public void DrawTransport(Graphics2D g) { if (_pictureWidth == -1 || _pictureHeight == -1) { return; } g.setPaint(AirFighter.BodyColor); Polygon front = new Polygon(); front.addPoint((int)(_startPosX + 160), (int)(_startPosY + 70)); front.addPoint((int)(_startPosX + 195), (int)(_startPosY + 83)); front.addPoint((int)(_startPosX + 160), (int)(_startPosY + 96)); Polygon tailTop = new Polygon(); tailTop.addPoint((int)(_startPosX), (int)(_startPosY + 30)); tailTop.addPoint((int)(_startPosX), (int)(_startPosY + 70)); tailTop.addPoint((int)(_startPosX + 25), (int)(_startPosY + 70)); tailTop.addPoint((int)(_startPosX + 25), (int)(_startPosY + 55)); Polygon tailBottom = new Polygon(); tailBottom.addPoint((int)(_startPosX), (int)(_startPosY + 96)); tailBottom.addPoint((int)(_startPosX), (int)(_startPosY + 136)); tailBottom.addPoint((int)(_startPosX + 25), (int)(_startPosY + 111)); tailBottom.addPoint((int)(_startPosX + 25), (int)(_startPosY + 96)); Polygon wingTop = new Polygon(); wingTop.addPoint((int)(_startPosX + 100), (int)(_startPosY)); wingTop.addPoint((int)(_startPosX + 100), (int)(_startPosY + 70)); wingTop.addPoint((int)(_startPosX + 75), (int)(_startPosY + 70)); wingTop.addPoint((int)(_startPosX + 90), (int)(_startPosY)); Polygon wingBottom = new Polygon(); wingBottom.addPoint((int)(_startPosX + 100), (int)(_startPosY + 96)); wingBottom.addPoint((int)(_startPosX + 100), (int)(_startPosY + 166)); wingBottom.addPoint((int)(_startPosX + 90), (int)(_startPosY + 166)); wingBottom.addPoint((int)(_startPosX + 75), (int)(_startPosY + 96)); g.fillPolygon(front); g.drawPolygon(tailTop); g.drawPolygon(tailBottom); g.drawPolygon(wingTop); g.drawPolygon(wingBottom); g.drawRect((int)_startPosX, (int)_startPosY + 70, 160, 26); drawingEngines.draw(g, (int)_startPosX, (int)_startPosY); } public void ChangeBorders(int width, int height) { _pictureWidth = width; _pictureHeight = height; if (_pictureWidth <= _airFighterWidth || _pictureHeight <= _airFighterHeight) { _pictureWidth = -1; _pictureHeight = -1; return; } if (_startPosX + _airFighterWidth > _pictureWidth) { _startPosX = _pictureWidth - _airFighterWidth; } if (_startPosY + _airFighterHeight > _pictureHeight) { _startPosY = _pictureHeight - _airFighterHeight; } } public Point getLeftTop() { return new Point((int)_startPosX, (int)_startPosY); } public Point getRightBottom() { return new Point((int)_startPosX + _airFighterWidth, (int)_startPosY + _airFighterHeight); } }