172 lines
6.2 KiB
Java
172 lines
6.2 KiB
Java
|
|
import java.awt.*;
|
|
import java.util.Random;
|
|
|
|
public class DrawningCatamaran {
|
|
protected EntityCatamaran EntityCatamaran;
|
|
public int _pictureWidth;
|
|
public int _pictureHeight;
|
|
protected int _startPosX = 0;
|
|
protected int _startPosY = 0;
|
|
protected int _catamaranWidth = 120;
|
|
protected int _catamaranHeight = 80;
|
|
protected IDraw DrawningOars;
|
|
|
|
public EntityCatamaran EntityCatamaran() {
|
|
return EntityCatamaran;
|
|
}
|
|
|
|
public IMoveableObject GetMoveableObject() {
|
|
return new DrawningObjectCatamaran(this);
|
|
}
|
|
|
|
public DrawningCatamaran(int speed, double weight, Color bodyColor, Color oarColor, int width, int height,
|
|
boolean boduKit, boolean seats) {
|
|
if (width <= _catamaranWidth || height <= _catamaranHeight)
|
|
return;
|
|
Random rand = new Random();
|
|
_pictureWidth = width;
|
|
_pictureHeight = height;
|
|
EntityCatamaran = new EntityCatamaran(speed, weight, bodyColor, oarColor, boduKit, seats);
|
|
|
|
DrawningOars = new DrawningOars(_startPosX, _startPosY, oarColor);
|
|
int variant = rand.nextInt(0, 3);
|
|
if (variant == 0)
|
|
DrawningOars = new DrawningOars(_startPosX, _startPosY, oarColor);
|
|
else if (variant == 1)
|
|
DrawningOars = new DrawningOarsOrn(_startPosX, _startPosY, oarColor);
|
|
else
|
|
DrawningOars = new DrawningOarsHandle(_startPosX, _startPosY, oarColor);
|
|
DrawningOars.ChangeOarsNumb(rand.nextInt(1, 4));
|
|
}
|
|
|
|
public void SetPosition(int x, int y) {
|
|
if (EntityCatamaran == null)
|
|
return;
|
|
_startPosX = x;
|
|
_startPosY = y;
|
|
DrawningOars.ChangeX(_startPosX);
|
|
DrawningOars.ChangeY(_startPosY);
|
|
if (x + _catamaranWidth >= _pictureWidth || y + _catamaranHeight >= _pictureHeight) {
|
|
_startPosX = 0;
|
|
_startPosY = 0;
|
|
}
|
|
}
|
|
|
|
public int GetPosX() {
|
|
return _startPosX;
|
|
}
|
|
|
|
public int GetPosY() {
|
|
return _startPosY;
|
|
}
|
|
|
|
public int GetWidth() {
|
|
return _catamaranWidth;
|
|
}
|
|
|
|
public int GetHeight() {
|
|
return _catamaranHeight;
|
|
}
|
|
|
|
public boolean CanMove(DirectionType direction) {
|
|
if (EntityCatamaran == null)
|
|
return false;
|
|
boolean can = false;
|
|
switch (direction) {
|
|
case Left:
|
|
can = _startPosX - EntityCatamaran.Step() >= 0;
|
|
break;
|
|
case Right:
|
|
can = _startPosX + EntityCatamaran.Step() + _catamaranWidth < _pictureWidth;
|
|
break;
|
|
case Down:
|
|
can = _startPosY + EntityCatamaran.Step() + _catamaranHeight < _pictureHeight;
|
|
break;
|
|
case Up:
|
|
can = _startPosY - EntityCatamaran.Step() >= 0;
|
|
break;
|
|
}
|
|
;
|
|
return can;
|
|
}
|
|
|
|
public void MoveTransport(DirectionType direction) {
|
|
if (!CanMove(direction) || EntityCatamaran == null)
|
|
return;
|
|
switch (direction) {
|
|
case Left:
|
|
if (_startPosX - EntityCatamaran.Step() >= 0)
|
|
_startPosX -= (int) EntityCatamaran.Step();
|
|
else
|
|
_startPosX = 0;
|
|
break;
|
|
case Up:
|
|
if (_startPosY - EntityCatamaran.Step() >= 0)
|
|
_startPosY -= (int) EntityCatamaran.Step();
|
|
else
|
|
_startPosY = 0;
|
|
break;
|
|
case Right:
|
|
if (_startPosX + _catamaranWidth + EntityCatamaran.Step() < _pictureWidth)
|
|
_startPosX += (int) EntityCatamaran.Step();
|
|
else
|
|
_startPosX = _pictureWidth - _catamaranWidth;
|
|
break;
|
|
case Down:
|
|
if (_startPosY + _catamaranHeight + EntityCatamaran.Step() < _pictureHeight)
|
|
_startPosY += (int) EntityCatamaran.Step();
|
|
else
|
|
_startPosY = _pictureHeight - _catamaranHeight;
|
|
break;
|
|
}
|
|
DrawningOars.ChangeX(_startPosX);
|
|
DrawningOars.ChangeY(_startPosY);
|
|
}
|
|
|
|
public void DrawnCatamaran(Graphics2D g2d) {
|
|
if (EntityCatamaran == null)
|
|
return;
|
|
|
|
g2d.setColor(EntityCatamaran.BodyColor());
|
|
// korpus
|
|
g2d.fillRect(_startPosX + 10, _startPosY + 10, _catamaranWidth - 50, 60);
|
|
// nos
|
|
int[] x_triag = { _startPosX + _catamaranWidth - 40, _startPosX + _catamaranWidth,
|
|
_startPosX + _catamaranWidth - 40 };
|
|
int[] y_triag = { _startPosY + 10, _startPosY + 40, _startPosY + 70 };
|
|
g2d.fillPolygon(x_triag, y_triag, 3);
|
|
// poplav
|
|
g2d.setColor(Color.DARK_GRAY);
|
|
int[] poplav1_x = { _startPosX + _catamaranWidth - 20, _startPosX + _catamaranWidth,
|
|
_startPosX + _catamaranWidth - 20 };
|
|
int[] poplav1_y = { _startPosY, _startPosY + 5, _startPosY + 10 };
|
|
g2d.fillPolygon(poplav1_x, poplav1_y, 3);
|
|
int[] poplav2_x = { _startPosX + _catamaranWidth - 20, _startPosX + _catamaranWidth,
|
|
_startPosX + _catamaranWidth - 20 };
|
|
int[] poplav2_y = { _startPosY + 70, _startPosY + 75, _startPosY + 80 };
|
|
g2d.fillPolygon(poplav2_x, poplav2_y, 3);
|
|
g2d.fillRect(_startPosX, _startPosY, _catamaranWidth - 20, 10);
|
|
g2d.fillRect(_startPosX, _startPosY + 70, _catamaranWidth - 20, 10);
|
|
//
|
|
g2d.setColor(Color.BLACK);
|
|
g2d.drawPolygon(poplav1_x, poplav1_y, 3);
|
|
g2d.drawPolygon(poplav2_x, poplav2_y, 3);
|
|
g2d.drawPolygon(x_triag, y_triag, 3);
|
|
g2d.drawRect(_startPosX + 10, _startPosY + 10, _catamaranWidth - 50, 60);
|
|
g2d.drawRect(_startPosX, _startPosY, _catamaranWidth - 20, 10);
|
|
g2d.drawRect(_startPosX, _startPosY + 70, _catamaranWidth - 20, 10);
|
|
// sedenie
|
|
g2d.setColor(Color.CYAN);
|
|
g2d.fillOval(_startPosX + 15, _startPosY + 25, 60, 30);
|
|
|
|
if (EntityCatamaran.Seats()) {
|
|
g2d.setColor(Color.ORANGE);
|
|
g2d.fillOval(_startPosX + 20, _startPosY + 35, 10, 10);
|
|
g2d.fillOval(_startPosX + 35, _startPosY + 35, 10, 10);
|
|
g2d.fillOval(_startPosX + 50, _startPosY + 35, 10, 10);
|
|
}
|
|
DrawningOars.DrawOars(g2d);
|
|
}
|
|
}
|