204 lines
6.1 KiB
Java
204 lines
6.1 KiB
Java
import java.awt.*;
|
|
import java.util.Random;
|
|
|
|
public class DrawingStormtrooper {
|
|
public EntityStormtrooper Stormtrooper;
|
|
public EntityStormtrooper getStormtrooper() {
|
|
return Stormtrooper;
|
|
}
|
|
public DrawingEngines drawingEngines;
|
|
private IDrawningEngines iDrawingEngines;
|
|
public float _startPosX;
|
|
public float _startPosY;
|
|
private Integer _pictureWidth = null;
|
|
private Integer _pictureHeight = null;
|
|
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);
|
|
}
|
|
|
|
protected DrawingStormtrooper(int speed, float weight, Color bodyColor, int StormWidth, int StormHeight)
|
|
{
|
|
this (speed, weight, bodyColor);
|
|
_StormWidth = StormWidth;
|
|
_StormHeight = StormHeight;
|
|
}
|
|
|
|
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;
|
|
|
|
|
|
|
|
//фюзеляж самолёта
|
|
g.setColor(Color.BLACK);
|
|
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);
|
|
|
|
//отрисовка двигателей
|
|
iDrawingEngines.Draw(g, (int) _startPosX, (int) _startPosY, Stormtrooper.getBodyColor());
|
|
|
|
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;
|
|
}
|
|
}
|
|
public float[] GetCurrentPosition()
|
|
{
|
|
return new float[]{_startPosX, _startPosX + _StormWidth, _startPosY, _startPosY + _StormHeight};
|
|
}
|
|
}
|