113 lines
3.4 KiB
Java
113 lines
3.4 KiB
Java
import java.awt.*;
|
|
|
|
public class DrawingArtillery {
|
|
private EntityArtillery artillery;
|
|
private DrawingRollers drawingRollers;
|
|
private float _startPosX;
|
|
private float _startPosY;
|
|
private Integer _pictureWidth = null;
|
|
private Integer _pictureHeight = null;
|
|
private final int _artilleryWidth = 80;
|
|
private final int _artilleryHeight = 50;
|
|
|
|
public EntityArtillery getArtillery() {
|
|
return artillery;
|
|
}
|
|
|
|
public void Init(int speed, float weight, Color bodyColor, int rollersCount) {
|
|
artillery = new EntityArtillery();
|
|
artillery.Init(speed, weight, bodyColor);
|
|
drawingRollers = new DrawingRollers(rollersCount, bodyColor);
|
|
}
|
|
|
|
public void SetPosition(int x, int y, int width, int height) {
|
|
if (x < 0 || x + _artilleryWidth >= width)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (y < 0 || y + _artilleryHeight >= height)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_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 + _artilleryWidth + artillery.getStep() < _pictureWidth)
|
|
{
|
|
_startPosX += artillery.getStep();
|
|
}
|
|
break;
|
|
|
|
case Left:
|
|
if (_startPosX - artillery.getStep() >= 0)
|
|
{
|
|
_startPosX -= artillery.getStep();
|
|
}
|
|
break;
|
|
|
|
case Up:
|
|
if (_startPosY - artillery.getStep() >= 0)
|
|
{
|
|
_startPosY -= artillery.getStep();
|
|
}
|
|
break;
|
|
|
|
case Down:
|
|
if (_startPosY + _artilleryHeight + artillery.getStep() < _pictureHeight)
|
|
{
|
|
_startPosY += artillery.getStep();
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
public void drawTransport(Graphics2D g) {
|
|
if (_startPosX < 0 || _startPosY < 0 || _pictureHeight == null || _pictureWidth == null)
|
|
{
|
|
return;
|
|
}
|
|
g.setColor(artillery.getBodyColor() != null ? artillery.getBodyColor() : Color.BLACK);
|
|
g.fillRect((int) (_startPosX + _artilleryWidth / 8 * 2), (int) _startPosY, _artilleryWidth / 8 * 4, _artilleryWidth / 5);
|
|
g.fillRect((int) _startPosX, (int) (_startPosY + _artilleryHeight / 5), _artilleryWidth, _artilleryHeight / 3);
|
|
|
|
|
|
g.setColor(Color.GRAY);
|
|
g.fillOval((int) _startPosX, (int) (_startPosY + _artilleryHeight * 2 / 5), _artilleryWidth, _artilleryHeight * 2 / 5);
|
|
drawingRollers.draw(g, (int) _startPosX, (int) _startPosY, _artilleryWidth, _artilleryHeight);
|
|
}
|
|
|
|
public void changeBorders(int width, int height)
|
|
{
|
|
_pictureWidth = width;
|
|
_pictureHeight = height;
|
|
if (_pictureWidth <= _artilleryWidth || _pictureHeight <= _artilleryHeight)
|
|
{
|
|
_pictureWidth = null;
|
|
_pictureHeight = null;
|
|
return;
|
|
}
|
|
if (_startPosX + _artilleryWidth > _pictureWidth)
|
|
{
|
|
_startPosX = _pictureWidth - _artilleryWidth;
|
|
}
|
|
if (_startPosY + _artilleryHeight > _pictureHeight)
|
|
{
|
|
_startPosY = _pictureHeight - _artilleryHeight;
|
|
}
|
|
}
|
|
}
|