import java.awt.*; import java.awt.geom.Line2D; import java.awt.geom.Path2D; public class DrawingSPAU { private EntitySPAU EntitySPAU; private int pictureWidth; private int pictureHeight; private int startPosX; private int startPosY; private int _numbeRollers; private final int carWidth = 135; private final int carHeight = 75; public void setEntitySPAU(EntitySPAU entitySPAU) { this.EntitySPAU = entitySPAU; } public boolean Init(int _numbeRollers, int speed, double weight, Color bodyColor, Color additionalColor, boolean bodyKit, boolean wing, boolean sportLine, int width, int height) { this._numbeRollers = _numbeRollers; this.pictureWidth = width; this.pictureHeight = height; if (this.carHeight >= height) { return false; } if (this.carWidth >= width) { return false; } EntitySPAU = new EntitySPAU(); EntitySPAU.Init(speed, weight, bodyColor, additionalColor, bodyKit, wing, sportLine); return true; } public void SetPosition(int x, int y) { if (x < 0 || x > this.pictureWidth - this.carWidth) { x = 0; } if (y < 0 || y > this.pictureHeight - this.carHeight) { y = 0; } this.startPosX = x; this.startPosY = y; } public void MoveTransport(DirectionType direction) { if (EntitySPAU == null) { return; } switch (direction) { //влево case Left: if (this.startPosX - EntitySPAU.Step > 0) { this.startPosX -= (int)EntitySPAU.Step; } break; //вверх case Up: if (this.startPosY - EntitySPAU.Step > 0) { this.startPosY -= (int)EntitySPAU.Step; } break; // вправо case Right: if (this.startPosX + EntitySPAU.Step < this.pictureWidth - this.carWidth) { this.startPosX += (int)EntitySPAU.Step; } break; //вниз case Down: if (this.startPosY + EntitySPAU.Step < this.pictureHeight - this.carHeight) { this.startPosY += (int)EntitySPAU.Step; } break; } } public void DrawTransport(Graphics g) { if (EntitySPAU == null) { return; } Graphics2D g2d = (Graphics2D) g; BasicStroke penBlack = new BasicStroke(1); Color additionalColor = EntitySPAU.AdditionalColor; Color bodyColor = EntitySPAU.BodyColor; boolean hasBodyKit = EntitySPAU.BodyKit; Path2D.Double path = new Path2D.Double(); // Обвесы if (hasBodyKit) { path.moveTo(startPosX + 15, startPosY + 20); path.lineTo(startPosX + 35, startPosY + 20); path.lineTo(startPosX + 35, startPosY + 60); path.lineTo(startPosX + 15, startPosY + 60); path.closePath(); g2d.setPaint(additionalColor); g2d.fill(path); g2d.setPaint(Color.BLACK); g2d.setStroke(penBlack); g2d.draw(path); path.reset(); Line2D line = new Line2D.Double(startPosX + 5, startPosY + 20, startPosX + 15, startPosY + 25); g2d.draw(line); } //гусеницы DrawingRollers Rollers = new DrawingRollers(g2d, startPosX, startPosY, bodyColor, _numbeRollers); Rollers.Draw(); // пушка path.moveTo(startPosX + 35, startPosY + 40); path.lineTo(startPosX + 40, startPosY + 45); path.lineTo(startPosX + 135, startPosY + 5); path.lineTo(startPosX + 130, startPosY + 0); path.closePath(); g2d.setPaint(bodyColor); g2d.fill(path); g2d.draw(path); path.reset(); // корпус path.moveTo(startPosX, startPosY + 60); path.lineTo(startPosX + 10, startPosY + 30); path.lineTo(startPosX + 130, startPosY + 30); path.lineTo(startPosX + 135, startPosY + 60); path.closePath(); g2d.setPaint(bodyColor); g2d.fill(path); g2d.draw(path); path.reset(); // башня path.moveTo(startPosX + 40, startPosY + 30); path.lineTo(startPosX + 45, startPosY + 15); path.lineTo(startPosX + 70, startPosY + 15); path.lineTo(startPosX + 75, startPosY + 30); path.closePath(); g2d.setPaint(bodyColor); g2d.fill(path); g2d.draw(path); } }