package laba1Loco;
import java.awt.*;
import java.util.*;
import javax.swing.*;
import javax.swing.Timer;
import java.awt.event.*;
public class DrawingLoco extends DrawingTrain{
///
/// Инициализация свойств
///
/// Скорость
/// Вес
/// Цвет кузова
/// Дополнительный цвет
/// Признак наличия трубы
/// Признак наличия бака
/// Признак наличия паровозной полосы
/// Ширина картинки
/// Высота картинки
public DrawingLoco(int speed, double weight, Color bodyColor, int _numWheel, Color additionalColor, boolean tube, boolean fuelTank, boolean locoLine, int width, int height)
{
super(speed, weight, bodyColor, _numWheel, width, height);
EntityTrain = new EntityLoco(speed, weight, bodyColor, _numWheel, additionalColor, tube, fuelTank, locoLine);
_locoWidth = ((EntityLoco)EntityTrain).FuelTank ? 169 : 83;
}
///
/// Установка позиции
///
/// Координата X
/// Координата Y
public void SetPosition(int x, int y)
{
_startPosX = Math.min(x, _pictureWidth-_locoWidth);
_startPosY = Math.min(y, _pictureHeight-_locoHeight);
}
///
/// Прорисовка объекта
///
///
public void DrawTransport(Graphics2D g2d)
{
if (EntityTrain == null)
{
return;
}
super.DrawTransport(g2d);
g2d.setColor(((EntityLoco)EntityTrain).AdditionalColor);
if (((EntityLoco)EntityTrain).Tube)
{
g2d.drawPolyline(new int[] {
_startPosX + 40,_startPosX + 40,_startPosX + 45,_startPosX + 41,_startPosX + 41,_startPosX + 44,_startPosX + 44,_startPosX + 45,_startPosX + 45,
},new int[] {
_startPosY+9,_startPosY+3,_startPosY+3,_startPosY+3,_startPosY,_startPosY,_startPosY+3,_startPosY+3,_startPosY+9,
},9);
}
if (((EntityLoco)EntityTrain).LocoLine)
{
g2d.drawPolyline(new int[] {
_startPosX + 60,_startPosX + 38,
},new int[] {
_startPosY+10,_startPosY+32
},2);
g2d.drawPolyline(new int[] {
_startPosX + 65,_startPosX + 43,
},new int[] {
_startPosY+10,_startPosY+32
},2);
g2d.drawPolyline(new int[] {
_startPosX + 70,_startPosX + 48,
},new int[] {
_startPosY+10,_startPosY+32
},2);
}
if (((EntityLoco)EntityTrain).FuelTank)
{
// body
g2d.setColor(EntityTrain.BodyColor);
g2d.drawPolyline(new int[]{
_startPosX + 89, _startPosX + 164, _startPosX + 164, _startPosX + 89, _startPosX + 89,
}, new int[]{
_startPosY+10, _startPosY+10, _startPosY+32, _startPosY+32, _startPosY+10
}, 5);
g2d.drawPolyline(new int[]{
_startPosX + 89, _startPosX + 164,
}, new int[]{
_startPosY+21, _startPosY+21,
}, 2);
// trucks
g2d.fillPolygon(new int[]{
_startPosX + 0+85,_startPosX + 5+85,_startPosX + 32+85,_startPosX + 36+85,
}, new int[]{
_startPosY+37,_startPosY+33,_startPosY+33,_startPosY+37
}, 4);
g2d.fillPolygon(new int[]{
_startPosX + 44+85,_startPosX + 49+85,_startPosX + 76+85,_startPosX + 80+85,
}, new int[]{
_startPosY+37,_startPosY+33,_startPosY+33,_startPosY+37
}, 4);
//back
g2d.fillPolygon(new int[]{
_startPosX + 79+85,_startPosX + 82+85,_startPosX + 82+85,_startPosX + 79+85,
}, new int[]{
_startPosY+12,_startPosY+12,_startPosY+30,_startPosY+30
}, 4);
//front
g2d.fillPolygon(new int[]{
_startPosX + 86,_startPosX + 89,_startPosX + 89,_startPosX + 86,
}, new int[]{
_startPosY+12,_startPosY+12,_startPosY+30,_startPosY+30
}, 4);
}
//wheels
wheelDrawing.Draw(_startPosX, _startPosY, ((EntityLoco)EntityTrain).FuelTank, EntityTrain.BodyColor, g2d);
}
}