2022-12-19 23:33:41 +04:00
|
|
|
import java.awt.*;
|
|
|
|
import java.util.Random;
|
|
|
|
|
|
|
|
public class DrawingStormtrooper {
|
|
|
|
public EntityStormtrooper Stormtrooper;
|
2022-12-20 17:17:11 +04:00
|
|
|
public EntityStormtrooper getStormtrooper() {
|
|
|
|
return Stormtrooper;
|
|
|
|
}
|
2022-12-19 23:33:41 +04:00
|
|
|
public DrawingEngines drawingEngines;
|
2022-12-20 17:17:11 +04:00
|
|
|
private IDrawningEngines iDrawingEngines;
|
2022-12-19 23:33:41 +04:00
|
|
|
public float _startPosX;
|
|
|
|
public float _startPosY;
|
|
|
|
private Integer _pictureWidth = null;
|
|
|
|
private Integer _pictureHeight = null;
|
2022-12-20 17:17:11 +04:00
|
|
|
private int _StormWidth = 135;
|
|
|
|
private int _StormHeight = 100;
|
|
|
|
|
|
|
|
public DrawingStormtrooper(int speed, float weight, Color bodyColor){
|
|
|
|
Random random = new Random();
|
|
|
|
int[] ArrayEngines = new int[]{2, 4, 6};
|
|
|
|
|
|
|
|
switch (random.nextInt(3)){
|
|
|
|
case 0:
|
|
|
|
iDrawingEngines = new DrawingEngines(ArrayEngines[random.nextInt(0, 3)]);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
iDrawingEngines = new DrawningOvalEngines(ArrayEngines[random.nextInt(0, 3)]);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
iDrawingEngines = new DrawningTriangleEngines(ArrayEngines[random.nextInt(0, 3)]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
Stormtrooper = new EntityStormtrooper(speed,weight, bodyColor);
|
2022-12-19 23:33:41 +04:00
|
|
|
}
|
|
|
|
|
2022-12-20 17:17:11 +04:00
|
|
|
protected DrawingStormtrooper(int speed, float weight, Color bodyColor, int StormWidth, int StormHeight)
|
|
|
|
{
|
|
|
|
this (speed, weight, bodyColor);
|
|
|
|
_StormWidth = StormWidth;
|
|
|
|
_StormHeight = StormHeight;
|
2022-12-19 23:33:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetPosition(int x, int y, int width, int height){
|
|
|
|
if ((x > 0 && y > 0) && (_StormHeight + y < height) && (_StormWidth + x < width))
|
|
|
|
{
|
|
|
|
_startPosX = x;
|
|
|
|
_startPosY = y;
|
|
|
|
_pictureWidth = width;
|
|
|
|
_pictureHeight = height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void MoveTransport(Direction direction)
|
|
|
|
{
|
|
|
|
if (_pictureWidth == null || _pictureHeight == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
switch (direction)
|
|
|
|
{
|
|
|
|
// вправо
|
|
|
|
case RIGHT:
|
|
|
|
if (_startPosX + _StormWidth + Stormtrooper.Step < _pictureWidth)
|
|
|
|
{
|
|
|
|
_startPosX += Stormtrooper.Step;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
//влево
|
|
|
|
case LEFT:
|
|
|
|
if (_startPosX - Stormtrooper.Step > 0)
|
|
|
|
{
|
|
|
|
_startPosX -= Stormtrooper.Step;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
//вверх
|
|
|
|
case UP:
|
|
|
|
if (_startPosY - Stormtrooper.Step > 0)
|
|
|
|
{
|
|
|
|
_startPosY -= Stormtrooper.Step;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
//вниз
|
|
|
|
case DOWN:
|
|
|
|
if (_startPosY + _StormHeight + Stormtrooper.Step < _pictureHeight)
|
|
|
|
{
|
|
|
|
_startPosY += Stormtrooper.Step;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void DrawTransport(Graphics2D g)
|
|
|
|
{
|
|
|
|
if (_startPosX < 0 || _startPosY < 0
|
|
|
|
|| _pictureHeight == null || _pictureWidth == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int _startPosXInt = (int)_startPosX;
|
|
|
|
int _startPosYInt = (int)_startPosY;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//фюзеляж самолёта
|
2022-12-20 17:17:11 +04:00
|
|
|
g.setColor(Color.BLACK);
|
2022-12-19 23:33:41 +04:00
|
|
|
g.fillRect(_startPosXInt + 20, _startPosYInt + 40, 100, 20);
|
|
|
|
|
|
|
|
//отрисовка крыла
|
|
|
|
int[] wingX =
|
|
|
|
{
|
|
|
|
_startPosXInt + 60 ,
|
|
|
|
_startPosXInt + 80 ,
|
|
|
|
_startPosXInt+90 ,
|
|
|
|
_startPosXInt+90 ,
|
|
|
|
_startPosXInt+80 ,
|
|
|
|
_startPosXInt + 60
|
|
|
|
};
|
|
|
|
|
|
|
|
int[] wingY =
|
|
|
|
{
|
|
|
|
_startPosYInt,
|
|
|
|
_startPosYInt,
|
|
|
|
_startPosYInt + 40,
|
|
|
|
_startPosYInt + 60,
|
|
|
|
_startPosYInt + 100,
|
|
|
|
_startPosYInt + 100
|
|
|
|
};
|
|
|
|
g.setColor(Stormtrooper.getBodyColor());
|
|
|
|
g.fillPolygon(wingX, wingY, wingY.length);
|
|
|
|
|
|
|
|
//нос самолёта
|
|
|
|
int[] noseX =
|
|
|
|
{
|
|
|
|
_startPosXInt + 20,
|
|
|
|
_startPosXInt + 20,
|
|
|
|
_startPosXInt
|
|
|
|
};
|
|
|
|
|
|
|
|
int[] noseY =
|
|
|
|
{
|
|
|
|
_startPosYInt + 60,
|
|
|
|
_startPosYInt + 40,
|
|
|
|
_startPosYInt +50
|
|
|
|
};
|
|
|
|
|
|
|
|
g.fillPolygon(noseX, noseY, noseX.length);
|
|
|
|
|
|
|
|
//стабилизатор
|
|
|
|
int[] stabX =
|
|
|
|
{
|
|
|
|
_startPosXInt + 120,
|
|
|
|
_startPosXInt + 135,
|
|
|
|
_startPosXInt + 135,
|
|
|
|
_startPosXInt + 120
|
|
|
|
};
|
|
|
|
|
|
|
|
int[] stabY =
|
|
|
|
{
|
|
|
|
_startPosYInt + 60,
|
|
|
|
_startPosYInt + 80,
|
|
|
|
_startPosYInt + 20,
|
|
|
|
_startPosYInt + 40
|
|
|
|
};
|
|
|
|
|
|
|
|
g.fillPolygon(stabX, stabY, stabX.length);
|
|
|
|
|
|
|
|
//отрисовка двигателей
|
2022-12-20 17:17:11 +04:00
|
|
|
iDrawingEngines.Draw(g, (int) _startPosX, (int) _startPosY, Stormtrooper.getBodyColor());
|
2022-12-19 23:33:41 +04:00
|
|
|
|
|
|
|
g.setColor(Color.BLACK);
|
|
|
|
|
|
|
|
g.drawRect(_startPosXInt + 20, _startPosYInt + 40, 100, 20);
|
|
|
|
g.drawPolygon(wingX, wingY, wingX.length);
|
|
|
|
g.drawPolygon(noseX, noseY, noseX.length);
|
|
|
|
g.drawPolygon(stabX, stabY, stabX.length);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void ChangeBorders(int width, int height)
|
|
|
|
{
|
|
|
|
_pictureWidth = width;
|
|
|
|
_pictureHeight = height;
|
|
|
|
if (_pictureWidth <= _StormWidth || _pictureHeight <= _StormHeight)
|
|
|
|
{
|
|
|
|
_pictureWidth = null;
|
|
|
|
_pictureHeight = null;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (_startPosX + _StormWidth > _pictureWidth)
|
|
|
|
{
|
|
|
|
_startPosX = _pictureWidth - _StormWidth;
|
|
|
|
}
|
|
|
|
if (_startPosY + _StormHeight > _pictureHeight)
|
|
|
|
{
|
|
|
|
_startPosY = _pictureHeight - _StormHeight;
|
|
|
|
}
|
|
|
|
}
|
2022-12-20 17:17:11 +04:00
|
|
|
public float[] GetCurrentPosition()
|
|
|
|
{
|
|
|
|
return new float[]{_startPosX, _startPosX + _StormWidth, _startPosY, _startPosY + _StormHeight};
|
|
|
|
}
|
2022-12-19 23:33:41 +04:00
|
|
|
}
|