173 lines
5.7 KiB
Java
173 lines
5.7 KiB
Java
import java.awt.*;
|
|
import java.awt.geom.Ellipse2D;
|
|
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 final int carWidth = 135;
|
|
private final int carHeight = 75;
|
|
|
|
public void setEntitySPAU(EntitySPAU entitySPAU) {
|
|
this.EntitySPAU = entitySPAU;
|
|
}
|
|
public boolean Init(int speed, double weight, Color bodyColor, Color additionalColor, boolean bodyKit, boolean wing, boolean sportLine, int width, int height)
|
|
{
|
|
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);
|
|
}
|
|
|
|
// Гусеницы
|
|
Ellipse2D ellipse1 = new Ellipse2D.Double(startPosX + 5, startPosY + 50, 20, 20);
|
|
Ellipse2D ellipse2 = new Ellipse2D.Double(startPosX + 30, startPosY + 50, 20, 20);
|
|
Ellipse2D ellipse3 = new Ellipse2D.Double(startPosX + 55, startPosY + 50, 20, 20);
|
|
Ellipse2D ellipse4 = new Ellipse2D.Double(startPosX + 80, startPosY + 50, 20, 20);
|
|
Ellipse2D ellipse5 = new Ellipse2D.Double(startPosX + 105, startPosY + 50, 20, 20);
|
|
g2d.setPaint(Color.BLACK);
|
|
g2d.fill(ellipse1);
|
|
g2d.fill(ellipse2);
|
|
g2d.fill(ellipse3);
|
|
g2d.fill(ellipse4);
|
|
g2d.fill(ellipse5);
|
|
|
|
Ellipse2D ellipse6 = new Ellipse2D.Double(startPosX + 10, startPosY + 55, 113, 20);
|
|
g2d.draw(ellipse6);
|
|
|
|
// пушка
|
|
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);
|
|
}
|
|
}
|