import java.awt.*; import java.util.Random; public class DrawingStormtrooper { public EntityStormtrooper Stormtrooper; public DrawingEngines drawingEngines; public float _startPosX; public float _startPosY; private Integer _pictureWidth = null; private Integer _pictureHeight = null; private static final int _StormWidth = 135; private static final int _StormHeight = 100; public void Init(int speed, float weight, Color bodyColor, int numberOfEngines){ Stormtrooper = new EntityStormtrooper(); drawingEngines = new DrawingEngines(); Stormtrooper.Init(speed, weight, bodyColor); System.out.println(numberOfEngines + ""); drawingEngines.SetNewEngines(numberOfEngines); } public EntityStormtrooper getStormtrooper() { return Stormtrooper; } public void SetPosition(int x, int y, int width, int height){ if ((x > 0 && y > 0) && (_StormHeight + y < height) && (_StormWidth + x < width)) { _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 + _StormWidth + Stormtrooper.Step < _pictureWidth) { _startPosX += Stormtrooper.Step; } break; //влево case LEFT: if (_startPosX - Stormtrooper.Step > 0) { _startPosX -= Stormtrooper.Step; } break; //вверх case UP: if (_startPosY - Stormtrooper.Step > 0) { _startPosY -= Stormtrooper.Step; } break; //вниз case DOWN: if (_startPosY + _StormHeight + Stormtrooper.Step < _pictureHeight) { _startPosY += Stormtrooper.Step; } break; } } public void DrawTransport(Graphics2D g) { if (_startPosX < 0 || _startPosY < 0 || _pictureHeight == null || _pictureWidth == null) { return; } int _startPosXInt = (int)_startPosX; int _startPosYInt = (int)_startPosY; //фюзеляж самолёта g.fillRect(_startPosXInt + 20, _startPosYInt + 40, 100, 20); //отрисовка крыла int[] wingX = { _startPosXInt + 60 , _startPosXInt + 80 , _startPosXInt+90 , _startPosXInt+90 , _startPosXInt+80 , _startPosXInt + 60 }; int[] wingY = { _startPosYInt, _startPosYInt, _startPosYInt + 40, _startPosYInt + 60, _startPosYInt + 100, _startPosYInt + 100 }; g.setColor(Stormtrooper.getBodyColor()); g.fillPolygon(wingX, wingY, wingY.length); //нос самолёта int[] noseX = { _startPosXInt + 20, _startPosXInt + 20, _startPosXInt }; int[] noseY = { _startPosYInt + 60, _startPosYInt + 40, _startPosYInt +50 }; g.fillPolygon(noseX, noseY, noseX.length); //стабилизатор int[] stabX = { _startPosXInt + 120, _startPosXInt + 135, _startPosXInt + 135, _startPosXInt + 120 }; int[] stabY = { _startPosYInt + 60, _startPosYInt + 80, _startPosYInt + 20, _startPosYInt + 40 }; g.fillPolygon(stabX, stabY, stabX.length); //отрисовка двигателей drawingEngines.Draw(g, (int) _startPosX, (int) _startPosY,Stormtrooper.getBodyColor()); g.setColor(Color.BLACK); g.drawRect(_startPosXInt + 20, _startPosYInt + 40, 100, 20); g.drawPolygon(wingX, wingY, wingX.length); g.drawPolygon(noseX, noseY, noseX.length); g.drawPolygon(stabX, stabY, stabX.length); } public void ChangeBorders(int width, int height) { _pictureWidth = width; _pictureHeight = height; if (_pictureWidth <= _StormWidth || _pictureHeight <= _StormHeight) { _pictureWidth = null; _pictureHeight = null; return; } if (_startPosX + _StormWidth > _pictureWidth) { _startPosX = _pictureWidth - _StormWidth; } if (_startPosY + _StormHeight > _pictureHeight) { _startPosY = _pictureHeight - _StormHeight; } } }