170 lines
6.1 KiB
Java
170 lines
6.1 KiB
Java
package ProjectElectricLocomotive;
|
|
import java.awt.*;
|
|
public class DrawingElectricLocomotive {
|
|
public EntityElectricLocomotive EntityElectricLocomotive;
|
|
|
|
private int _pictureWidth;
|
|
private int _pictureHeight;
|
|
private int _startPosX;
|
|
private int _startPosY;
|
|
private final int _locoWidth = 150;
|
|
private final int _locoHeight = 50;
|
|
|
|
public boolean Init(int speed, double weight, Color bodyColor, Color additionalColor,
|
|
boolean horns, boolean seifbatteries, int width, int height)
|
|
{
|
|
|
|
if (width < _locoWidth || height < _locoHeight)
|
|
{
|
|
return false;
|
|
}
|
|
_pictureWidth = width;
|
|
_pictureHeight = height;
|
|
EntityElectricLocomotive = new EntityElectricLocomotive();
|
|
EntityElectricLocomotive.Init(speed, weight, bodyColor, additionalColor, horns, seifbatteries);
|
|
return true;
|
|
}
|
|
|
|
public void SetPosition(int x, int y)
|
|
{
|
|
if (x < 0 || x + _locoWidth > _pictureWidth)
|
|
{
|
|
x = 20;
|
|
}
|
|
if (y < 0 || y + _locoHeight > _pictureHeight)
|
|
{
|
|
y = 20;
|
|
}
|
|
_startPosX = x;
|
|
_startPosY = y;
|
|
}
|
|
|
|
public void MoveTransport(DyrectionType direction){
|
|
if(EntityElectricLocomotive == null) return;
|
|
switch(direction)
|
|
{
|
|
case Up -> {
|
|
if(_startPosY - EntityElectricLocomotive.Step() >= 0)
|
|
_startPosY -= (int) EntityElectricLocomotive.Step();
|
|
}
|
|
case Down -> {
|
|
if(_startPosY + EntityElectricLocomotive.Step() + _locoHeight <= _pictureHeight)
|
|
_startPosY += (int) EntityElectricLocomotive.Step();
|
|
}
|
|
case Left -> {
|
|
if(_startPosX - EntityElectricLocomotive.Step() >= 0)
|
|
_startPosX -= (int) EntityElectricLocomotive.Step();
|
|
}
|
|
case Right -> {
|
|
if(_startPosX + EntityElectricLocomotive.Step() + _locoWidth <= _pictureWidth)
|
|
_startPosX += (int) EntityElectricLocomotive.Step();
|
|
}
|
|
}
|
|
}
|
|
public void DrawTransport(Graphics g) {
|
|
if (EntityElectricLocomotive == null) {
|
|
return;
|
|
}
|
|
|
|
Graphics2D g2d = (Graphics2D) g;
|
|
|
|
Color bodyColor = EntityElectricLocomotive.BodyColor;
|
|
Color additionalColor = EntityElectricLocomotive.AdditionalColor;
|
|
Color blackBrush = Color.BLACK;
|
|
Color windowsColor = Color.BLUE;
|
|
|
|
if(EntityElectricLocomotive.Horns)
|
|
{
|
|
g2d.fillRect(_startPosX + 30, _startPosY + 15, 20, 5);
|
|
g2d.drawLine(_startPosX + 40, _startPosY + 15, _startPosX + 50, _startPosY + 10);
|
|
g2d.drawLine(_startPosX + 50, _startPosY + 10, _startPosX + 45, _startPosY);
|
|
g2d.drawLine(_startPosX + 45, _startPosY + 15, _startPosX + 50, _startPosY + 10);
|
|
g2d.drawLine(_startPosX + 50, _startPosY + 10, _startPosX + 40, _startPosY);
|
|
g2d.setColor(blackBrush);
|
|
}
|
|
|
|
//locomotive
|
|
Polygon loco = new Polygon();
|
|
|
|
loco.addPoint(_startPosX, _startPosY + 40);
|
|
loco.addPoint(_startPosX, _startPosY + 30);
|
|
loco.addPoint(_startPosX + 20, _startPosY + 20);
|
|
loco.addPoint(_startPosX + 70, _startPosY + 20);
|
|
loco.addPoint(_startPosX +80, _startPosY + 30);
|
|
loco.addPoint(_startPosX +80, _startPosY + 40);
|
|
loco.addPoint(_startPosX +75, _startPosY + 45);
|
|
loco.addPoint(_startPosX +5, _startPosY + 45);
|
|
loco.addPoint(_startPosX, _startPosY + 40);
|
|
|
|
g2d.setColor(blackBrush);
|
|
g2d.drawPolygon(loco);
|
|
g2d.setColor(bodyColor);
|
|
g2d.fillPolygon(loco);
|
|
// windows
|
|
Polygon window = new Polygon();
|
|
window.addPoint(_startPosX + 10, _startPosY + 30);
|
|
window.addPoint(_startPosX +15, _startPosY + 25);
|
|
window.addPoint(_startPosX + 20, _startPosY + 25);
|
|
window.addPoint(_startPosX + 20, _startPosY + 30);
|
|
window.addPoint(_startPosX +10, _startPosY + 30);
|
|
|
|
g2d.setColor(blackBrush);
|
|
g2d.drawPolygon(window);
|
|
g2d.setColor(windowsColor);
|
|
g2d.fillPolygon(window);
|
|
|
|
g2d.fillRect(_startPosX + 25, _startPosY + 25, 10, 5);
|
|
g2d.setColor(windowsColor);
|
|
g2d.drawRect(_startPosX + 25, _startPosY + 25, 10, 5);
|
|
g2d.setColor(blackBrush);
|
|
//locomotive
|
|
|
|
if(EntityElectricLocomotive.SeifBatteries)
|
|
{
|
|
g2d.drawRect(_startPosX + 50, _startPosY + 25, 20, 10);
|
|
g2d.setColor(blackBrush);
|
|
}
|
|
|
|
|
|
//обязательные колеса
|
|
//loco
|
|
g2d.fillOval(_startPosX + 10, _startPosY + 45, 5, 5);
|
|
g2d.fillOval(_startPosX + 25, _startPosY + 45, 5, 5);
|
|
g2d.fillOval(_startPosX + 50, _startPosY + 45, 5, 5);
|
|
g2d.fillOval(_startPosX + 65, _startPosY + 45, 5, 5);
|
|
|
|
// g2d.setColor(EntityElectricLocomotive.BodyColor);
|
|
// g2d.fillRect(_startPosX, _startPosY, _locoWidth, _locoHeight);
|
|
|
|
|
|
//telega
|
|
g2d.setColor(blackBrush);
|
|
g2d.fillOval(_startPosX + 95, _startPosY + 45, 5, 5);
|
|
g2d.fillOval(_startPosX + 140, _startPosY + 45, 5, 5);
|
|
|
|
//telejka
|
|
Polygon telega = new Polygon();
|
|
|
|
telega.addPoint(_startPosX + 90, _startPosY + 25);
|
|
telega.addPoint(_startPosX + 95, _startPosY + 20);
|
|
telega.addPoint(_startPosX + 145, _startPosY + 20);
|
|
telega.addPoint(_startPosX + 150, _startPosY + 25);
|
|
telega.addPoint(_startPosX + 150, _startPosY + 45);
|
|
telega.addPoint(_startPosX + 90, _startPosY + 45);
|
|
telega.addPoint(_startPosX + 90, _startPosY + 25);
|
|
|
|
g2d.setColor(additionalColor);
|
|
g2d.fillPolygon(telega);
|
|
g2d.setColor(blackBrush);
|
|
g2d.drawPolygon(telega);
|
|
//telejka
|
|
|
|
//телега окна
|
|
g2d.setColor(blackBrush);
|
|
g.drawLine(_startPosX + 80, _startPosY + 40, _startPosX + 90, _startPosY + 40);
|
|
g2d.setColor(windowsColor); g.fillRect(_startPosX + 95, _startPosY + 30, 10, 5);
|
|
g.fillRect(_startPosX + 115, _startPosY + 30, 10, 5);
|
|
g.fillRect(_startPosX + 135, _startPosY + 30, 10, 5);
|
|
}
|
|
}
|