Реализована отрисовка объекта без дополнительного класса
This commit is contained in:
parent
ba99ffcca9
commit
bf32d9a57d
@ -1,6 +1,7 @@
|
|||||||
package ProjectStormtrooper;
|
package ProjectStormtrooper;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
import java.awt.geom.Rectangle2D;
|
||||||
|
|
||||||
public class DrawingStormtrooper {
|
public class DrawingStormtrooper {
|
||||||
public EntityStormtrooper EntityStormtrooper;
|
public EntityStormtrooper EntityStormtrooper;
|
||||||
@ -72,7 +73,7 @@ public class DrawingStormtrooper {
|
|||||||
if (EntityStormtrooper == null) {
|
if (EntityStormtrooper == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// TODO: реализовать отрисовку
|
// todo: реализовать отрисовку дополнительного класса
|
||||||
Graphics2D g2d = (Graphics2D) g;
|
Graphics2D g2d = (Graphics2D) g;
|
||||||
|
|
||||||
Color bodyColor = EntityStormtrooper.BodyColor;
|
Color bodyColor = EntityStormtrooper.BodyColor;
|
||||||
@ -80,34 +81,163 @@ public class DrawingStormtrooper {
|
|||||||
Color blackColor = Color.BLACK;
|
Color blackColor = Color.BLACK;
|
||||||
Color redColor = Color.RED;
|
Color redColor = Color.RED;
|
||||||
|
|
||||||
g2d.setColor(blackColor);
|
|
||||||
g2d.drawRect(_startPosX, _startPosY, _stormtrooperWidth, _stormtrooperHeight);
|
|
||||||
|
|
||||||
// Длина фюзеляжа
|
// Длина фюзеляжа
|
||||||
int bodyHeight = _stormtrooperHeight / 9;
|
int bodyHeight = _stormtrooperHeight / 9;
|
||||||
int bodyWidth = _stormtrooperWidth - _stormtrooperWidth / 8;
|
int bodyWidth = _stormtrooperWidth - _stormtrooperWidth / 8;
|
||||||
|
|
||||||
// Рисуем бомбы
|
// Рисуем бомбы
|
||||||
if (EntityStormtrooper.Bombs) {
|
if (EntityStormtrooper.Bombs) {
|
||||||
// todo
|
Polygon bombTailPolygon = new Polygon();
|
||||||
|
bombTailPolygon.addPoint(_startPosX + _stormtrooperWidth / 2 - _stormtrooperWidth / 8 + bodyHeight * 3 - 5,
|
||||||
|
_startPosY + _stormtrooperHeight / 2 - bodyHeight / 2 - _stormtrooperHeight / 3 + bodyHeight / 2);
|
||||||
|
bombTailPolygon.addPoint(_startPosX + _stormtrooperWidth / 2 - _stormtrooperWidth / 8 + bodyHeight * 3 + 5,
|
||||||
|
_startPosY + _stormtrooperHeight / 2 - bodyHeight / 2 - _stormtrooperHeight / 3 + bodyHeight / 2 - 5);
|
||||||
|
bombTailPolygon.addPoint(_startPosX + _stormtrooperWidth / 2 - _stormtrooperWidth / 8 + bodyHeight * 3 + 5,
|
||||||
|
_startPosY + _stormtrooperHeight / 2 - bodyHeight / 2 - _stormtrooperHeight / 3 + bodyHeight / 2 + 5);
|
||||||
|
bombTailPolygon.addPoint(_startPosX + _stormtrooperWidth / 2 - _stormtrooperWidth / 8 + bodyHeight * 3 - 5,
|
||||||
|
_startPosY + _stormtrooperHeight / 2 - bodyHeight / 2 - _stormtrooperHeight / 3 + bodyHeight / 2);
|
||||||
|
|
||||||
|
g2d.setColor(additionalColor);
|
||||||
|
g2d.fillPolygon(bombTailPolygon);
|
||||||
|
g2d.setColor(blackColor);
|
||||||
|
g2d.drawPolygon(bombTailPolygon);
|
||||||
|
|
||||||
|
bombTailPolygon.translate(0, (int) (_stormtrooperHeight - 2 * (_stormtrooperHeight / 2 - bodyHeight / 2 - _stormtrooperHeight / 3 + bodyHeight / 2 - 5) - bombTailPolygon.getBounds2D().getHeight()));
|
||||||
|
|
||||||
|
g2d.setColor(additionalColor);
|
||||||
|
g2d.fillPolygon(bombTailPolygon);
|
||||||
|
g2d.setColor(blackColor);
|
||||||
|
g2d.drawPolygon(bombTailPolygon);
|
||||||
|
|
||||||
|
g2d.setColor(additionalColor);
|
||||||
|
g2d.fillOval(
|
||||||
|
_startPosX + _stormtrooperWidth / 2 - _stormtrooperWidth / 8,
|
||||||
|
_startPosY + _stormtrooperHeight / 2 - bodyHeight / 2 - _stormtrooperHeight / 3,
|
||||||
|
bodyHeight * 3,
|
||||||
|
bodyHeight);
|
||||||
|
|
||||||
|
g2d.fillOval(
|
||||||
|
_startPosX + _stormtrooperWidth / 2 - _stormtrooperWidth / 8,
|
||||||
|
_startPosY + _stormtrooperHeight / 2 - bodyHeight / 2 + _stormtrooperHeight / 3,
|
||||||
|
bodyHeight * 3,
|
||||||
|
bodyHeight);
|
||||||
|
|
||||||
|
g2d.setColor(blackColor);
|
||||||
|
g2d.drawOval(
|
||||||
|
_startPosX + _stormtrooperWidth / 2 - _stormtrooperWidth / 8,
|
||||||
|
_startPosY + _stormtrooperHeight / 2 - bodyHeight / 2 - _stormtrooperHeight / 3,
|
||||||
|
bodyHeight * 3,
|
||||||
|
bodyHeight);
|
||||||
|
g2d.drawOval(
|
||||||
|
_startPosX + _stormtrooperWidth / 2 - _stormtrooperWidth / 8,
|
||||||
|
_startPosY + _stormtrooperHeight / 2 - bodyHeight / 2 + _stormtrooperHeight / 3,
|
||||||
|
bodyHeight * 3,
|
||||||
|
bodyHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Рисуем ракеты
|
// Рисуем ракеты
|
||||||
if (EntityStormtrooper.Rockets) {
|
if (EntityStormtrooper.Rockets) {
|
||||||
// todo
|
int rocketWidth = bodyHeight * 4;
|
||||||
|
int rocketHeight = bodyHeight / 2;
|
||||||
|
|
||||||
|
Polygon rocketCockPitPolygon = new Polygon();
|
||||||
|
rocketCockPitPolygon.addPoint(_startPosX + _stormtrooperWidth / 2 - _stormtrooperWidth / 5 - rocketHeight,
|
||||||
|
_startPosY + _stormtrooperHeight / 2 - bodyHeight - bodyHeight / 2 + rocketHeight / 2);
|
||||||
|
rocketCockPitPolygon.addPoint(_startPosX + _stormtrooperWidth / 2 - _stormtrooperWidth / 5,
|
||||||
|
_startPosY + _stormtrooperHeight / 2 - bodyHeight - bodyHeight / 2);
|
||||||
|
rocketCockPitPolygon.addPoint(_startPosX + _stormtrooperWidth / 2 - _stormtrooperWidth / 5,
|
||||||
|
_startPosY + _stormtrooperHeight / 2 - bodyHeight - bodyHeight / 2 + rocketHeight);
|
||||||
|
|
||||||
|
Polygon rocketTailPolygon = new Polygon();
|
||||||
|
rocketTailPolygon.addPoint(_startPosX + _stormtrooperWidth / 2 - _stormtrooperWidth / 5 - rocketHeight + rocketWidth - 10,
|
||||||
|
_startPosY + _stormtrooperHeight / 2 - bodyHeight - bodyHeight / 2 + rocketHeight / 2);
|
||||||
|
rocketTailPolygon.addPoint(_startPosX + _stormtrooperWidth / 2 - _stormtrooperWidth / 5 + rocketWidth,
|
||||||
|
_startPosY + _stormtrooperHeight / 2 - bodyHeight * 2 + rocketHeight / 2);
|
||||||
|
rocketTailPolygon.addPoint(_startPosX + _stormtrooperWidth / 2 - _stormtrooperWidth / 5 + rocketWidth,
|
||||||
|
_startPosY + _stormtrooperHeight / 2 - bodyHeight - bodyHeight / 2 + rocketHeight + bodyHeight / 2 - rocketHeight / 2);
|
||||||
|
|
||||||
|
g2d.setColor(redColor);
|
||||||
|
g2d.fillPolygon(rocketCockPitPolygon);
|
||||||
|
g2d.setColor(blackColor);
|
||||||
|
g2d.drawPolygon(rocketCockPitPolygon);
|
||||||
|
|
||||||
|
g2d.setColor(blackColor);
|
||||||
|
g2d.fillPolygon(rocketTailPolygon);
|
||||||
|
|
||||||
|
rocketCockPitPolygon.translate(0, (int) (_stormtrooperHeight - 2 * (_stormtrooperHeight / 2 - bodyHeight - bodyHeight / 2) - rocketCockPitPolygon.getBounds2D().getHeight()));
|
||||||
|
rocketTailPolygon.translate(0, (int) (_stormtrooperHeight - 2 * (_stormtrooperHeight / 2 - bodyHeight * 2 + rocketHeight / 2) - rocketTailPolygon.getBounds2D().getHeight()));
|
||||||
|
|
||||||
|
g2d.setColor(redColor);
|
||||||
|
g2d.fillPolygon(rocketCockPitPolygon);
|
||||||
|
g2d.setColor(blackColor);
|
||||||
|
g2d.drawPolygon(rocketCockPitPolygon);
|
||||||
|
|
||||||
|
g2d.setColor(blackColor);
|
||||||
|
g2d.fillPolygon(rocketTailPolygon);
|
||||||
|
|
||||||
|
g2d.setColor(additionalColor);
|
||||||
|
g2d.fillRect(
|
||||||
|
_startPosX + _stormtrooperWidth / 2 - _stormtrooperWidth / 5,
|
||||||
|
_startPosY + _stormtrooperHeight / 2 - bodyHeight - bodyHeight / 2,
|
||||||
|
rocketWidth,
|
||||||
|
rocketHeight);
|
||||||
|
|
||||||
|
|
||||||
|
g2d.fillRect(
|
||||||
|
_startPosX + _stormtrooperWidth / 2 - _stormtrooperWidth / 5,
|
||||||
|
_startPosY + _stormtrooperHeight / 2 + bodyHeight / 2 + bodyHeight / 2,
|
||||||
|
rocketWidth,
|
||||||
|
rocketHeight);
|
||||||
|
|
||||||
|
g2d.setColor(blackColor);
|
||||||
|
g2d.drawRect(
|
||||||
|
_startPosX + _stormtrooperWidth / 2 - _stormtrooperWidth / 5,
|
||||||
|
_startPosY + _stormtrooperHeight / 2 - bodyHeight - bodyHeight / 2,
|
||||||
|
rocketWidth,
|
||||||
|
rocketHeight);
|
||||||
|
|
||||||
|
g2d.drawRect(
|
||||||
|
_startPosX + _stormtrooperWidth / 2 - _stormtrooperWidth / 5,
|
||||||
|
_startPosY + _stormtrooperHeight / 2 + bodyHeight / 2 + bodyHeight / 2,
|
||||||
|
rocketWidth,
|
||||||
|
rocketHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Рисуем нос
|
// Рисуем нос
|
||||||
// todo
|
Polygon cockPitPolygon = new Polygon();
|
||||||
|
cockPitPolygon.addPoint(_startPosX, _startPosY + _stormtrooperHeight / 2);
|
||||||
|
cockPitPolygon.addPoint(_startPosX + _stormtrooperWidth / 8, _startPosY + _stormtrooperHeight / 2 - bodyHeight / 2);
|
||||||
|
cockPitPolygon.addPoint(_startPosX + _stormtrooperWidth / 8, _startPosY + _stormtrooperHeight / 2 + bodyHeight / 2);
|
||||||
|
|
||||||
|
g2d.setColor(blackColor);
|
||||||
|
g2d.fillPolygon(cockPitPolygon);
|
||||||
|
|
||||||
// Рисуем крылья
|
// Рисуем крылья
|
||||||
// todo
|
Polygon wingsPolygon = new Polygon();
|
||||||
|
wingsPolygon.addPoint(_startPosX + _stormtrooperWidth / 2, _startPosY);
|
||||||
|
wingsPolygon.addPoint(_startPosX + _stormtrooperWidth / 2 + _stormtrooperWidth / 15, _startPosY);
|
||||||
|
wingsPolygon.addPoint(_startPosX + _stormtrooperWidth / 2 + _stormtrooperWidth / 6, _startPosY + _stormtrooperHeight / 2);
|
||||||
|
wingsPolygon.addPoint(_startPosX + _stormtrooperWidth / 2 + _stormtrooperWidth / 15, _startPosY + _stormtrooperHeight);
|
||||||
|
wingsPolygon.addPoint(_startPosX + _stormtrooperWidth / 2, _startPosY + _stormtrooperHeight);
|
||||||
|
|
||||||
|
g2d.setColor(bodyColor);
|
||||||
|
g.fillPolygon(wingsPolygon);
|
||||||
|
g2d.setColor(blackColor);
|
||||||
|
g.drawPolygon(wingsPolygon);
|
||||||
|
|
||||||
// Рисуем хвостовое оперение
|
// Рисуем хвостовое оперение
|
||||||
// todo
|
Polygon tailPolygon = new Polygon();
|
||||||
|
tailPolygon.addPoint(_startPosX + _stormtrooperWidth, _startPosY + _stormtrooperHeight / 2 - _stormtrooperHeight / 3);
|
||||||
|
tailPolygon.addPoint(_startPosX + bodyWidth, _startPosY + _stormtrooperHeight / 2 - _stormtrooperHeight / 8);
|
||||||
|
tailPolygon.addPoint(_startPosX + bodyWidth, _startPosY + _stormtrooperHeight / 2 + _stormtrooperHeight / 8);
|
||||||
|
tailPolygon.addPoint(_startPosX + _stormtrooperWidth, _startPosY + _stormtrooperHeight / 2 + _stormtrooperHeight / 3);
|
||||||
|
|
||||||
|
g2d.setColor(bodyColor);
|
||||||
|
g.fillPolygon(tailPolygon);
|
||||||
|
g2d.setColor(blackColor);
|
||||||
|
g.drawPolygon(tailPolygon);
|
||||||
|
|
||||||
// Рисуем фюзеляж
|
// Рисуем фюзеляж
|
||||||
// todo
|
|
||||||
g2d.setColor(bodyColor);
|
g2d.setColor(bodyColor);
|
||||||
g2d.fillRect(
|
g2d.fillRect(
|
||||||
_startPosX + _stormtrooperWidth / 8,
|
_startPosX + _stormtrooperWidth / 8,
|
||||||
@ -122,7 +252,5 @@ public class DrawingStormtrooper {
|
|||||||
bodyWidth,
|
bodyWidth,
|
||||||
bodyHeight
|
bodyHeight
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user