191 lines
5.6 KiB
Java
191 lines
5.6 KiB
Java
import java.awt.*;
|
|
import java.util.Random;
|
|
|
|
public class DrawningDumpTruck {
|
|
public EntityDumpTruck EntityDumpTruck;
|
|
|
|
private EntityDumpTruck get_EntityDumpTruck() { return EntityDumpTruck; }
|
|
public DrawningWeels _drawingWeels = null;
|
|
|
|
// Ширина окна
|
|
private Integer _pictureWidth;
|
|
|
|
// Высота окна
|
|
private Integer _pictureHeight;
|
|
|
|
// Левая координата прорисовки автомобиля
|
|
private Integer _startPosX;
|
|
|
|
// Верхняя кооридната прорисовки автомобиля
|
|
private Integer _startPosY;
|
|
|
|
// Ширина прорисовки самосвала
|
|
private final int _drawningDumpTruckWidth = 116;
|
|
|
|
// Высота прорисовки самосвала
|
|
private final int _drawingDumpTruckHeight = 100;
|
|
Random random = new Random();
|
|
|
|
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, Boolean body, Boolean tent)
|
|
{
|
|
EntityDumpTruck = new EntityDumpTruck();
|
|
EntityDumpTruck.Init(speed, weight, bodyColor, additionalColor, body, tent);
|
|
_pictureWidth = null;
|
|
_pictureHeight = null;
|
|
_startPosX = null;
|
|
_startPosY = null;
|
|
_drawingWeels = new DrawningWeels(random.nextInt(2, 5));
|
|
|
|
}
|
|
|
|
public Boolean SetPictureSize(int width, int height)
|
|
{
|
|
if (_drawningDumpTruckWidth > width || _drawingDumpTruckHeight > height)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (_pictureWidth != null && width != _pictureWidth || _pictureHeight != null && height != _pictureHeight)
|
|
{
|
|
if (_startPosX + _drawningDumpTruckWidth > width)
|
|
{
|
|
_startPosX -= _drawningDumpTruckWidth;
|
|
}
|
|
|
|
if (_startPosY + _drawingDumpTruckHeight > height)
|
|
{
|
|
_startPosY -= _drawingDumpTruckHeight;
|
|
}
|
|
}
|
|
|
|
_pictureWidth = width;
|
|
_pictureHeight = height;
|
|
return true;
|
|
}
|
|
|
|
public void SetPosition(int x, int y)
|
|
{
|
|
if (_pictureHeight == null|| _pictureWidth == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (x < 0)
|
|
{
|
|
x = 0;
|
|
}
|
|
if (x + _drawningDumpTruckWidth > _pictureWidth)
|
|
{
|
|
x = _pictureWidth - _drawningDumpTruckWidth;
|
|
}
|
|
if (y < 0)
|
|
{
|
|
y = 0;
|
|
}
|
|
if (y + _drawingDumpTruckHeight > _pictureHeight)
|
|
{
|
|
y = _pictureHeight - _drawingDumpTruckHeight;
|
|
|
|
}
|
|
|
|
_startPosX = x;
|
|
_startPosY = y;
|
|
|
|
}
|
|
|
|
public Boolean MoveTransport(DirectionType direction)
|
|
{
|
|
if (EntityDumpTruck == null || _startPosX == null || _startPosY == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
switch (direction)
|
|
{
|
|
//влево
|
|
case DirectionType.Left:
|
|
if (_startPosX - _drawningDumpTruckWidth > 0)
|
|
{
|
|
_startPosX -= (int)EntityDumpTruck.Step;
|
|
}
|
|
return true;
|
|
//вверх
|
|
case DirectionType.Up:
|
|
if (_startPosY - _drawingDumpTruckHeight > 0)
|
|
{
|
|
_startPosY -= (int)EntityDumpTruck.Step;
|
|
}
|
|
return true;
|
|
// вправо
|
|
case DirectionType.Right:
|
|
if (_startPosX + _drawningDumpTruckWidth + (int)EntityDumpTruck.Step < _pictureWidth)
|
|
{
|
|
_startPosX += (int)EntityDumpTruck.Step;
|
|
}
|
|
return true;
|
|
//вниз
|
|
case DirectionType.Down:
|
|
if (_startPosY + _drawingDumpTruckHeight + (int)EntityDumpTruck.Step < _pictureHeight)
|
|
{
|
|
_startPosY += (int)EntityDumpTruck.Step;
|
|
}
|
|
return true;
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public void DrawTransport(Graphics2D g)
|
|
{
|
|
if (EntityDumpTruck == null || _startPosX == null || _startPosY == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
g.setPaint(Color.BLACK);
|
|
|
|
if (EntityDumpTruck.Body)
|
|
{
|
|
int[] x_b = {_startPosX, _startPosX + 77, _startPosX + 77, _startPosX + 20};
|
|
int[] y_b = {_startPosY + 15, _startPosY + 15, _startPosY + 50, _startPosY + 50};
|
|
|
|
g.setPaint(Color.BLACK);
|
|
g.drawPolygon(x_b, y_b, 4);
|
|
g.setPaint(EntityDumpTruck.AdditionalColor);
|
|
g.fillPolygon(x_b, y_b, 4);
|
|
}
|
|
|
|
if (EntityDumpTruck.Tent && EntityDumpTruck.Body)
|
|
{
|
|
int[] x_t = {_startPosX, _startPosX + 39, _startPosX + 77};
|
|
int[] y_t = {_startPosY + 13, _startPosY, _startPosY + 13};
|
|
|
|
g.setPaint(Color.BLACK);
|
|
g.drawPolygon(x_t, y_t, 3);
|
|
g.setPaint(EntityDumpTruck.AdditionalColor);
|
|
g.fillPolygon(x_t, y_t, 3);
|
|
}
|
|
|
|
// Колёса
|
|
g.setPaint(Color.BLACK);
|
|
if (_drawingWeels != null){
|
|
_drawingWeels.DrawningWeel(g, _startPosX, _startPosY);
|
|
}
|
|
|
|
//Границы самосвала
|
|
g.drawRect( _startPosX + 10, _startPosY + 53, 100, 13);
|
|
g.drawRect( _startPosX + 80, _startPosY + 15, 30, 36);
|
|
g.drawRect(_startPosX + 85, _startPosY + 20, 20, 20);
|
|
|
|
// Кузов
|
|
g.setPaint(EntityDumpTruck.BodyColor);
|
|
g.fillRect(_startPosX + 10, _startPosY + 53, 100, 13);
|
|
g.fillRect(_startPosX + 80, _startPosY + 15, 30, 36);
|
|
|
|
//Окно
|
|
g.setPaint(Color.CYAN);
|
|
g.fillRect(_startPosX + 85, _startPosY + 20, 20, 20);
|
|
|
|
}
|
|
}
|