154 lines
6.2 KiB
Java
Raw Normal View History

import javax.swing.*;
import java.awt.*;
import java.util.Random;
public class DrawningAntiAircraftGun extends JPanel{
public EntityAntiAircraftGun EntityAntiAircraftGun;
public DrawningRollers _rollers = null;
private Integer picture_width;
private Integer picture_height;
private Integer _StartPosX;
private Integer _StartPosY;
private int drawningCarWidth = 120;
private int drawningCarHeight = 90;
public void Init(int speed, double weight, Color bodycolor, Color additionalcolor, boolean tower, boolean radar) {
EntityAntiAircraftGun = new EntityAntiAircraftGun();
EntityAntiAircraftGun.Init(speed, weight, bodycolor, additionalcolor, tower, radar);
picture_width = null;
picture_height = null;
_StartPosX = null;
_StartPosY = null;
_rollers = new DrawningRollers();
Random rand = new Random();
int randomNum = rand.nextInt(4);
_rollers.SetCount(randomNum);
}
public boolean SetPictureSize(int width, int height) {
if (width < drawningCarWidth || height < drawningCarHeight) return false;
picture_width = width;
picture_height = height;
if (_StartPosX != null || _StartPosY != null) {
if (_StartPosX + drawningCarWidth > picture_width)
{
_StartPosX = _StartPosX - (_StartPosX + drawningCarWidth - picture_width);
}
else if (_StartPosX < 0) _StartPosX = 0;
if (_StartPosY + drawningCarHeight > picture_height)
{
_StartPosY = _StartPosY - (_StartPosY + drawningCarHeight - picture_height);
}
else if (_StartPosY < 0) _StartPosY = 0;
}
return true;
}
public void SetPosition(int x, int y) {
if (!(picture_width != null && picture_height != null)) return;
if (x + drawningCarWidth > picture_width)
{
_StartPosX = x - (x + drawningCarWidth - picture_width);
}
else if (x < 0) _StartPosX = 0;
else _StartPosX = x;
if (y + drawningCarHeight > picture_height)
{
_StartPosY = y - (y + drawningCarHeight - picture_height);
}
else if (y < 0) _StartPosY = 0;
else _StartPosY = y;
}
public boolean MoveTransport(DirectionType direction) {
if (EntityAntiAircraftGun == null || _StartPosX == null || _StartPosY == null) return false;
switch (direction) {
case Left:
if (_StartPosX - EntityAntiAircraftGun.Step > 0) {
_StartPosX -= (int)EntityAntiAircraftGun.Step;
}
return true;
case Up:
if (_StartPosY - EntityAntiAircraftGun.Step > 0)
{
_StartPosY -= (int)EntityAntiAircraftGun.Step;
}
return true;
case Right:
if (_StartPosX + drawningCarWidth + (int)EntityAntiAircraftGun.Step < picture_width - EntityAntiAircraftGun.Step)
{
_StartPosX += (int)EntityAntiAircraftGun.Step;
}
return true;
case Down:
if (_StartPosY + drawningCarHeight + (int)EntityAntiAircraftGun.Step < picture_height - EntityAntiAircraftGun.Step)
{
_StartPosY += (int)EntityAntiAircraftGun.Step;
}
return true;
default:
return false;
}
}
public void DrawTransport(Graphics2D g) {
if (EntityAntiAircraftGun == null ) {
return;
}
;
g.drawOval(_StartPosX + 10, _StartPosY + 75, 30, 30);
g.drawOval(_StartPosX + 100, _StartPosY + 75, 30, 30);
g.drawRect(_StartPosX + 25, _StartPosY + 75, 90, 30);
//границы цвет
g.setColor(EntityAntiAircraftGun.getBodyColor());
g.fillRect(_StartPosX + 35, _StartPosY + 40, 35, 30);
g.fillOval(_StartPosX + 10, _StartPosY + 75, 30, 30);
g.fillOval(_StartPosX + 100, _StartPosY+ 75, 30, 30);
g.fillRect(_StartPosX+ 25, _StartPosY + 75, 90, 30);
// границы арт. установки
g.setColor(Color.BLACK);
g.drawRect(_StartPosX+ 35, _StartPosY + 40, 35, 30);
g.drawRect(_StartPosX+ 10, _StartPosY + 65, 120, 13);
//Большие катки ЦВЕТ
g.setColor(Color.GRAY);
g.fillOval(_StartPosX + 13, _StartPosY + 78, 24, 24);
g.fillOval( _StartPosX + 103, _StartPosY + 78, 24, 24);
//Большие катки ОТРИСОВКА
g.setColor(Color.BLACK);
g.drawOval( _StartPosX + 13, _StartPosY + 78, 24, 24);
g.drawOval( _StartPosX + 103, _StartPosY + 78, 24, 24);
g.setColor(EntityAntiAircraftGun.getBodyColor());
g.fillRect(_StartPosX + 10, _StartPosY+ 65, 120, 13);
_rollers.Draw(g,_StartPosX, _StartPosY);
//отрисовки башни
if (EntityAntiAircraftGun.getIsTower())
{
g.setColor(EntityAntiAircraftGun.getAdditionalColor());
g.fillRect(_StartPosX + 35, _StartPosY+ 50, 35, 15);
g.setColor(Color.BLACK);
g.drawRect(_StartPosX + 35, _StartPosY + 50, 35, 15);
g.drawLine(_StartPosX + 45, _StartPosY + 50, _StartPosX + 90, _StartPosY + 20);
g.drawLine( _StartPosX + 60, _StartPosY + 50, _StartPosX + 95, _StartPosY + 27);
g.drawLine( _StartPosX + 45, _StartPosY + 50, _StartPosX + 60, _StartPosY + 50);
g.drawLine( _StartPosX + 90, _StartPosY + 20, _StartPosX + 95, _StartPosY + 27);
g.drawLine( _StartPosX + 90, _StartPosY + 20, _StartPosX + 100, _StartPosY + 20);
g.drawLine( _StartPosX + 100, _StartPosY + 20, _StartPosX + 95, _StartPosY + 27);
}
//отрисовка радара
if (EntityAntiAircraftGun.getIsRadar())
{;
g.drawLine(_StartPosX + 20, _StartPosY + 65, _StartPosX + 20, _StartPosY + 40);
g.drawRect( _StartPosX + 10, _StartPosY + 20, 20, 20);
g.setColor(EntityAntiAircraftGun.getAdditionalColor());
g.fillRect(_StartPosX + 10, _StartPosY + 20, 20, 20);
}
}
}