236 lines
6.9 KiB
Java
236 lines
6.9 KiB
Java
package Classes;
|
|
|
|
import java.awt.*;
|
|
import java.util.Random;
|
|
|
|
public class DrawingAircraft
|
|
{
|
|
public EntityAircraft Plane;
|
|
private IDrawingEngines _engines;
|
|
|
|
|
|
protected int _startPosX;
|
|
protected int _startPosY;
|
|
|
|
private Integer _pictureWidth = null;
|
|
private Integer _pictureHeight = null;
|
|
|
|
protected final int _aircraftWidth = 100;
|
|
protected final int _aircraftHeight = 120;
|
|
|
|
public DrawingAircraft(int speed,float weight, Color bodyColor)
|
|
{
|
|
Random rnd = new Random();
|
|
int enginesType = rnd.nextInt(1,4);
|
|
if(enginesType == 1)
|
|
{
|
|
_engines = new DrawingArcEngines();
|
|
}
|
|
else if(enginesType == 2)
|
|
{
|
|
_engines = new DrawingRectangleEngines();
|
|
}
|
|
else if(enginesType == 3)
|
|
{
|
|
_engines = new DrawingOvalEngines();
|
|
}
|
|
|
|
_engines.setEngines(rnd.nextInt(2,7));
|
|
Plane = new EntityAircraft(speed,weight,bodyColor);
|
|
}
|
|
|
|
public void SetPosition(int x,int y,int width,int height)
|
|
{
|
|
if (x + _aircraftWidth > width || x < 0 || y + _aircraftHeight > height || y < 0)
|
|
{
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
_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 + _aircraftWidth + Plane.getStep() < _pictureWidth)
|
|
{
|
|
_startPosX += Plane.getStep();
|
|
}
|
|
}
|
|
break;
|
|
case Left:
|
|
{
|
|
if (_startPosX - Plane.getStep() > 0)
|
|
{
|
|
_startPosX -= Plane.getStep();
|
|
}
|
|
}
|
|
break;
|
|
case Up:
|
|
{
|
|
if (_startPosY - Plane.getStep() > 0)
|
|
{
|
|
_startPosY -= Plane.getStep();
|
|
}
|
|
}
|
|
break;
|
|
case Down:
|
|
{
|
|
if (_startPosY + _aircraftHeight + Plane.getStep() < _pictureHeight)
|
|
{
|
|
_startPosY += Plane.getStep();
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
public void DrawTransport(Graphics g)
|
|
{
|
|
if (_startPosX < 0 || _startPosY < 0 || _pictureHeight == null || _pictureWidth == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
//Aircraft Body
|
|
g.setColor(Plane.BodyColor);
|
|
g.fillRect((int)(_startPosX + 20), (int)(_startPosY + 45), 80, 14);
|
|
|
|
g.setColor(Color.BLACK);
|
|
g.drawRect((int)(_startPosX + 20), (int)(_startPosY + 45), 80, 14);
|
|
|
|
//Wings
|
|
Polygon pathWing1 = new Polygon();
|
|
|
|
Point point1B = new Point((int)(_startPosX + 50), (int)(_startPosY + 45));
|
|
Point point2B = new Point(point1B.x, point1B.y - 40);
|
|
Point point3B = new Point(point2B.x + 6, point2B.y);
|
|
Point point4B = new Point(point3B.x + 27, point1B.y);
|
|
|
|
pathWing1.addPoint(point1B.x,point1B.y);
|
|
pathWing1.addPoint(point2B.x,point2B.y);
|
|
pathWing1.addPoint(point3B.x,point3B.y);
|
|
pathWing1.addPoint(point4B.x,point4B.y);
|
|
|
|
g.setColor(Color.BLACK);
|
|
g.drawPolygon(pathWing1);
|
|
|
|
g.setColor(Plane.BodyColor);
|
|
g.fillPolygon(pathWing1);
|
|
|
|
Polygon pathWing2 = new Polygon();
|
|
|
|
Point point1B2 = new Point((int)(_startPosX + 50), (int)(_startPosY + 60));
|
|
Point point2B2 = new Point(point1B2.x, point1B2.y + 40);
|
|
Point point3B2 = new Point(point2B2.x + 6, point2B2.y);
|
|
Point point4B2 = new Point(point3B2.x + 27, point1B2.y);
|
|
|
|
pathWing2.addPoint(point1B2.x,point1B2.y);
|
|
pathWing2.addPoint(point2B2.x,point2B2.y);
|
|
pathWing2.addPoint(point3B2.x,point3B2.y);
|
|
pathWing2.addPoint(point4B2.x,point4B2.y);
|
|
|
|
g.setColor(Color.BLACK);
|
|
g.drawPolygon(pathWing2);
|
|
|
|
g.setColor(Plane.BodyColor);
|
|
g.fillPolygon(pathWing2);
|
|
|
|
//BackWings
|
|
Polygon pathBackWing1 = new Polygon();
|
|
|
|
Point point1W = new Point((int)(_startPosX + 85), (int)(_startPosY + 45));
|
|
Point point2W = new Point(point1W.x, point1W.y - 7);
|
|
Point point3W = new Point(point2W.x + 15, point2W.y - 16);
|
|
Point point4W = new Point(point3W.x, point1W.y);
|
|
|
|
pathBackWing1.addPoint(point1W.x, point1W.y);
|
|
pathBackWing1.addPoint(point2W.x, point2W.y);
|
|
pathBackWing1.addPoint(point3W.x, point3W.y);
|
|
pathBackWing1.addPoint(point4W.x, point4W.y);
|
|
|
|
g.setColor(Color.BLACK);
|
|
g.drawPolygon(pathBackWing1);
|
|
|
|
g.setColor(Plane.BodyColor);
|
|
g.fillPolygon(pathBackWing1);
|
|
|
|
Polygon pathBackWing2 = new Polygon();
|
|
|
|
Point point1W2 = new Point((int)(_startPosX + 85), (int)(_startPosY + 60));
|
|
Point point2W2 = new Point(point1W2.x, point1W2.y + 7);
|
|
Point point3W2 = new Point(point2W2.x + 15, point2W2.y +16);
|
|
Point point4W2 = new Point(point3W2.x, point1W2.y);
|
|
|
|
pathBackWing2.addPoint(point1W2.x, point1W2.y);
|
|
pathBackWing2.addPoint(point2W2.x, point2W2.y);
|
|
pathBackWing2.addPoint(point3W2.x, point3W2.y);
|
|
pathBackWing2.addPoint(point4W2.x, point4W2.y);
|
|
|
|
g.setColor(Color.BLACK);
|
|
g.drawPolygon(pathBackWing2);
|
|
|
|
g.setColor(Plane.BodyColor);
|
|
g.fillPolygon(pathBackWing2);
|
|
|
|
//Nose
|
|
Polygon pathBoseBody = new Polygon();
|
|
|
|
Point point1N = new Point((int)(_startPosX + 20), (int)(_startPosY + 45));
|
|
Point point2N = new Point(point1N.x - 15 ,point1N.y + 7);
|
|
Point point3N = new Point(point1N.x, point1N.y + 15);
|
|
|
|
pathBoseBody.addPoint(point1N.x, point1N.y);
|
|
pathBoseBody.addPoint(point2N.x, point2N.y);
|
|
pathBoseBody.addPoint(point3N.x, point3N.y);
|
|
|
|
g.setColor(Color.BLACK);
|
|
g.drawPolygon(pathBoseBody);
|
|
|
|
g.setColor(Plane.BodyColor);
|
|
g.fillPolygon(pathBoseBody);
|
|
|
|
//Engines
|
|
_engines.drawEngines(g,_startPosX,_startPosY, Plane.BodyColor);
|
|
}
|
|
|
|
public void ChangeBorders(int width, int height)
|
|
{
|
|
_pictureWidth = width;
|
|
_pictureHeight = height;
|
|
|
|
if (_pictureWidth <= _aircraftWidth || _pictureHeight <= _aircraftHeight)
|
|
{
|
|
_pictureHeight = null;
|
|
_pictureWidth = null;
|
|
return;
|
|
}
|
|
if (_startPosX + _aircraftWidth > _pictureWidth)
|
|
{
|
|
_startPosX = _pictureWidth - _aircraftWidth;
|
|
}
|
|
if (_startPosY + _aircraftHeight > _pictureHeight)
|
|
{
|
|
_startPosY = _pictureHeight - _aircraftHeight;
|
|
}
|
|
}
|
|
|
|
public ObjectData getCurrentPosition()
|
|
{
|
|
return new ObjectData(_startPosX, _startPosY, _startPosX + _aircraftWidth - 1, _startPosY + _aircraftHeight - 1);
|
|
}
|
|
}
|