PIbd-22_Chernyshev_G.J._29_.../Trolleybus/DrawingTrolleybus.java
2023-11-13 21:25:33 +03:00

40 lines
1.5 KiB
Java
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package Trolleybus;
import java.awt.*;
public class DrawingTrolleybus extends DrawingBus{
// Конструктор
public DrawingTrolleybus(int speed, double weight, Color bodyColor, Color additionalColor, boolean horns, boolean batteries, int width, int height)
{
super(speed, weight, bodyColor, width, height, 150, 95);
if (EntityBus != null)
{
EntityBus = new EntityTrolleybus(speed, weight, bodyColor, additionalColor, horns, batteries);
}
}
// Прорисовка объекта
@Override
public void DrawTransport(Graphics g)
{
if (!(EntityBus instanceof EntityTrolleybus trolleybus))
{
return;
}
super.DrawTransport(g);
Graphics2D g2d = (Graphics2D)g;
//Опциональные "рога"
g2d.setColor(trolleybus.getAdditionalColor());
if (trolleybus.Horns)
{
g2d.drawLine(_startPosX + 70, _startPosY + 30, _startPosX + 40, _startPosY);
g2d.drawLine(_startPosX + 70, _startPosY + 30, _startPosX + 60, _startPosY);
}
//Опциональный отсек для батареи
if (trolleybus.Batteries)
{
int[] xOfBatteries = {_startPosX + 70, _startPosX + 70, _startPosX + 100, _startPosX + 110};
int[] yOfBatteries = {_startPosY + 30, _startPosY + 25, _startPosY + 25, _startPosY + 30};
g2d.fillPolygon(xOfBatteries, yOfBatteries, 4);
}
}
}