Добавлен класс DrawingPlane
This commit is contained in:
parent
9db19f8397
commit
b087e5b388
173
ProjectStormtrooper/DrawingPlane.java
Normal file
173
ProjectStormtrooper/DrawingPlane.java
Normal file
@ -0,0 +1,173 @@
|
||||
package ProjectStormtrooper;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingPlane {
|
||||
public EntityPlane EntityPlane;
|
||||
private int _pictureWidth;
|
||||
private int _pictureHeight;
|
||||
protected int _startPosX;
|
||||
protected int _startPosY;
|
||||
protected int _planeWidth = 110;
|
||||
protected int _planeHeight = 110;
|
||||
|
||||
public int GetPosX() {
|
||||
return _startPosX;
|
||||
}
|
||||
|
||||
public int GetPosY() {
|
||||
return _startPosY;
|
||||
}
|
||||
|
||||
public int GetWidth() {
|
||||
return _planeWidth;
|
||||
}
|
||||
|
||||
public int GetHeight() {
|
||||
return _planeHeight;
|
||||
}
|
||||
|
||||
public DrawingPlane(int speed, double weight, Color bodyColor, int width, int height) {
|
||||
if (width < _planeWidth && height < _planeHeight) {
|
||||
return;
|
||||
}
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
EntityPlane = new EntityPlane(speed, weight, bodyColor);
|
||||
}
|
||||
|
||||
protected DrawingPlane(int speed, double weight, Color bodyColor,
|
||||
int width, int height, int planeWidth, int planeHeight) {
|
||||
if (width < planeWidth && height < planeHeight) {
|
||||
return;
|
||||
}
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
_planeWidth = planeWidth;
|
||||
_planeHeight = planeHeight;
|
||||
EntityPlane = new EntityPlane(speed, weight, bodyColor);
|
||||
}
|
||||
|
||||
public boolean CanMove(EnumDirectionType direction) {
|
||||
if (EntityPlane == null) {
|
||||
return false;
|
||||
}
|
||||
boolean result = false;
|
||||
switch (direction) {
|
||||
case Up -> result = _startPosY - EntityPlane.Step() > 0;
|
||||
case Down -> result = _startPosY + _planeHeight + EntityPlane.Step() < _pictureHeight;
|
||||
case Left -> result = _startPosX - EntityPlane.Step() > 0;
|
||||
case Right -> result = _startPosX + _planeWidth + EntityPlane.Step() < _pictureWidth;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void SetPosition(int x, int y) {
|
||||
if (x < 0) {
|
||||
x = 0;
|
||||
} else if (x > _pictureWidth - _planeWidth) {
|
||||
x = _pictureWidth - _planeWidth;
|
||||
}
|
||||
_startPosX = x;
|
||||
|
||||
if (y < 0) {
|
||||
y = 0;
|
||||
} else if (y > _pictureHeight - _planeHeight) {
|
||||
y = _pictureHeight - _planeHeight;
|
||||
}
|
||||
_startPosY = y;
|
||||
}
|
||||
|
||||
public void MoveTransport(EnumDirectionType direction) {
|
||||
if (EntityPlane == null) {
|
||||
return;
|
||||
}
|
||||
switch (direction) {
|
||||
case Up -> {
|
||||
if (_startPosY - EntityPlane.Step() >= 0) {
|
||||
_startPosY -= (int) EntityPlane.Step();
|
||||
}
|
||||
}
|
||||
case Down -> {
|
||||
if (_startPosY + _planeHeight + EntityPlane.Step() <= _pictureHeight) {
|
||||
_startPosY += (int) EntityPlane.Step();
|
||||
}
|
||||
}
|
||||
case Left -> {
|
||||
if (_startPosX - EntityPlane.Step() >= 0) {
|
||||
_startPosX -= (int) EntityPlane.Step();
|
||||
}
|
||||
}
|
||||
case Right -> {
|
||||
if (_startPosX + _planeWidth + EntityPlane.Step() <= _pictureWidth) {
|
||||
_startPosX += (int) EntityPlane.Step();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawTransport(Graphics g) {
|
||||
if (EntityPlane == null) {
|
||||
return;
|
||||
}
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
|
||||
Color bodyColor = EntityPlane.BodyColor;
|
||||
Color blackColor = Color.BLACK;
|
||||
Color redColor = Color.RED;
|
||||
|
||||
// Длина фюзеляжа
|
||||
int bodyHeight = _planeHeight / 9;
|
||||
int bodyWidth = _planeWidth - _planeWidth / 8;
|
||||
|
||||
// Рисуем нос
|
||||
Polygon cockPitPolygon = new Polygon();
|
||||
cockPitPolygon.addPoint(_startPosX, _startPosY + _planeHeight / 2);
|
||||
cockPitPolygon.addPoint(_startPosX + _planeWidth / 8, _startPosY + _planeHeight / 2 - bodyHeight / 2);
|
||||
cockPitPolygon.addPoint(_startPosX + _planeWidth / 8, _startPosY + _planeHeight / 2 + bodyHeight / 2);
|
||||
|
||||
g2d.setColor(blackColor);
|
||||
g2d.fillPolygon(cockPitPolygon);
|
||||
|
||||
// Рисуем крылья
|
||||
Polygon wingsPolygon = new Polygon();
|
||||
wingsPolygon.addPoint(_startPosX + _planeWidth / 2, _startPosY);
|
||||
wingsPolygon.addPoint(_startPosX + _planeWidth / 2 + _planeWidth / 15, _startPosY);
|
||||
wingsPolygon.addPoint(_startPosX + _planeWidth / 2 + _planeWidth / 6, _startPosY + _planeHeight / 2);
|
||||
wingsPolygon.addPoint(_startPosX + _planeWidth / 2 + _planeWidth / 15, _startPosY + _planeHeight);
|
||||
wingsPolygon.addPoint(_startPosX + _planeWidth / 2, _startPosY + _planeHeight);
|
||||
|
||||
g2d.setColor(bodyColor);
|
||||
g.fillPolygon(wingsPolygon);
|
||||
g2d.setColor(blackColor);
|
||||
g.drawPolygon(wingsPolygon);
|
||||
|
||||
// Рисуем хвостовое оперение
|
||||
Polygon tailPolygon = new Polygon();
|
||||
tailPolygon.addPoint(_startPosX + _planeWidth, _startPosY + _planeHeight / 2 - _planeHeight / 3);
|
||||
tailPolygon.addPoint(_startPosX + bodyWidth, _startPosY + _planeHeight / 2 - _planeHeight / 8);
|
||||
tailPolygon.addPoint(_startPosX + bodyWidth, _startPosY + _planeHeight / 2 + _planeHeight / 8);
|
||||
tailPolygon.addPoint(_startPosX + _planeWidth, _startPosY + _planeHeight / 2 + _planeHeight / 3);
|
||||
|
||||
g2d.setColor(bodyColor);
|
||||
g.fillPolygon(tailPolygon);
|
||||
g2d.setColor(blackColor);
|
||||
g.drawPolygon(tailPolygon);
|
||||
|
||||
// Рисуем фюзеляж
|
||||
g2d.setColor(bodyColor);
|
||||
g2d.fillRect(
|
||||
_startPosX + _planeWidth / 8,
|
||||
_startPosY + _planeHeight / 2 - bodyHeight / 2,
|
||||
bodyWidth,
|
||||
bodyHeight
|
||||
);
|
||||
g2d.setColor(blackColor);
|
||||
g2d.drawRect(
|
||||
_startPosX + _planeWidth / 8,
|
||||
_startPosY + _planeHeight / 2 - bodyHeight / 2,
|
||||
bodyWidth,
|
||||
bodyHeight
|
||||
);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user