Implement engines renderer

This commit is contained in:
ShabOl 2023-11-27 20:18:42 +04:00
parent be6065021e
commit 7044b3eac3
4 changed files with 79 additions and 11 deletions

View File

@ -2,12 +2,12 @@ import java.awt.Color;
public class BomberEntity
{
public int Speed;
public double Weight;
public Color BodyColor;
public Color AdditionalColor;
public boolean Bombs;
public boolean FuelTanks;
private int Speed;
private double Weight;
private Color BodyColor;
private Color AdditionalColor;
private boolean Bombs;
private boolean FuelTanks;
public double Step;
public void Init(int Speed, double Weight, Color BodyColor, Color AdditionalColor, boolean FuelTanks, boolean Bombs)
@ -21,4 +21,16 @@ public class BomberEntity
this.Step = (double)Speed * 100 / Weight * 5 / 2;
}
public int GetSpeed() { return Speed; }
public double GetWeight() { return Weight; }
public Color GetBodyColor() { return BodyColor; }
public Color GetAdditionalColor() { return AdditionalColor; }
public boolean GetBombs() { return Bombs; }
public boolean GetFuelTanks() { return FuelTanks; }
}

View File

@ -1,8 +1,9 @@
import java.awt.*;
import java.util.Random;
public class BomberRenderer
{
public BomberEntity EntityBomber;
private BomberEntity EntityBomber;
private int _pictureWidth;
private int _pictureHeight;
@ -13,6 +14,8 @@ public class BomberRenderer
private int _bomberWidth = 200;
private int _bomberHeight = 200;
public EngineRenderer EngineRenderer;
public boolean Init(int Speed, double Weight, Color BodyColor, Color AdditionalColor, boolean FuelTanks, boolean Bombs, int Width, int Height)
{
if (Width < _bomberWidth || Height < _bomberHeight)
@ -24,9 +27,16 @@ public class BomberRenderer
EntityBomber = new BomberEntity();
EntityBomber.Init(Speed, Weight, BodyColor, AdditionalColor, FuelTanks, Bombs);
EngineRenderer = new EngineRenderer();
Random Random = new Random();
EngineRenderer.SetAmount(Random.nextInt(1, 7));
return true;
}
public BomberEntity GetEntityBomber() { return EntityBomber; }
public void SetPosition(int x, int y)
{
if (EntityBomber == null)
@ -86,7 +96,7 @@ public class BomberRenderer
return;
/** Отрисовка основной части */
g.setColor(EntityBomber.BodyColor);
g.setColor(EntityBomber.GetBodyColor());
int[] LeftWingX = {
_startPosX + 90,
@ -172,9 +182,9 @@ public class BomberRenderer
g.drawPolygon(BackRightWingX, BackRightWingY, 4);
/** Отрисовка дополнительных элементов */
g.setColor(EntityBomber.AdditionalColor);
g.setColor(EntityBomber.GetAdditionalColor());
if (EntityBomber.FuelTanks)
if (EntityBomber.GetFuelTanks())
{
int[] LeftGasTankX = {
_startPosX + 50,
@ -205,10 +215,12 @@ public class BomberRenderer
g.fillPolygon(RightGasTankX, RightGasTankY, 4);
}
if (EntityBomber.Bombs)
if (EntityBomber.GetBombs())
{
g.fillOval(_startPosX + 110, _startPosY + 115, 50, 25);
g.fillOval(_startPosX + 110, _startPosY + 60, 50, 25);
}
EngineRenderer.DrawEngines(g, EntityBomber.GetBodyColor(), _startPosX, _startPosY);
}
}

38
src/EngineRenderer.java Normal file
View File

@ -0,0 +1,38 @@
import java.awt.*;
public class EngineRenderer
{
private EnginesAmount Amount;
public void SetAmount(int Amount)
{
if (Amount <= 2)
this.Amount = EnginesAmount.Two;
else if (Amount > 2 && Amount <= 4)
this.Amount = EnginesAmount.Four;
else
this.Amount = EnginesAmount.Six;
}
public void DrawEngines(Graphics g, Color BodyColor, int _startPosX, int _startPosY)
{
g.setColor(BodyColor);
g.fillOval(_startPosX + 83, _startPosY + 50, 30, 15);
g.fillOval(_startPosX + 83, _startPosY + 135, 30, 15);
if (Amount == EnginesAmount.Two)
return;
g.fillOval(_startPosX + 83, _startPosY + 30, 30, 15);
g.fillOval(_startPosX + 83, _startPosY + 155, 30, 15);
if (Amount == EnginesAmount.Four)
return;
g.fillOval(_startPosX + 83, _startPosY + 10, 30, 15);
g.fillOval(_startPosX + 83, _startPosY + 175, 30, 15);
}
}

6
src/EnginesAmount.java Normal file
View File

@ -0,0 +1,6 @@
public enum EnginesAmount
{
Two,
Four,
Six
}