126 lines
5.1 KiB
Java
126 lines
5.1 KiB
Java
import javax.swing.*;
|
|
import java.awt.*;
|
|
import java.util.Random;
|
|
|
|
public class DrawningCatamaran {
|
|
JPanel CatamaranPanel;
|
|
private EntityCatamaran EntityCatamaran;
|
|
private DrawningOars drawningOars;
|
|
private int _pictureWidth;
|
|
private int _pictureHeight;
|
|
private int _startPosX = 0;
|
|
private int _startPosY = 0;
|
|
private int _catamaranWidth = 120;
|
|
private int _catamaranHeight = 120;
|
|
|
|
public EntityCatamaran EntityCatamaran(){
|
|
return EntityCatamaran;
|
|
}
|
|
|
|
public boolean Init(int speed, double weight, Color bodyColor, Color oarColor, int width, int height, boolean boduKit, boolean seats, JPanel catamaranPanel){
|
|
if(width <= _catamaranWidth || height <= _catamaranHeight)
|
|
return false;
|
|
Random rand = new Random();
|
|
catamaranPanel.setSize(width, height);
|
|
CatamaranPanel = catamaranPanel;
|
|
catamaranPanel.paint(CatamaranPanel.getGraphics());
|
|
_pictureWidth = width;
|
|
_pictureHeight = height;
|
|
EntityCatamaran = new EntityCatamaran();
|
|
EntityCatamaran.Init(speed, weight, bodyColor, oarColor, boduKit, seats);
|
|
SetPosition(rand.nextInt(50), rand.nextInt(50));
|
|
drawningOars =new DrawningOars();
|
|
drawningOars.Init(_startPosX, _startPosY, oarColor, catamaranPanel);
|
|
drawningOars.ChangeOarsNumb(rand.nextInt(3));
|
|
return true;
|
|
}
|
|
|
|
public void SetPosition(int x, int y){
|
|
if(EntityCatamaran == null)
|
|
return;
|
|
_startPosX = x;
|
|
_startPosY = y;
|
|
|
|
if(x + _catamaranWidth >= _pictureWidth || y + _catamaranHeight >= _pictureHeight){
|
|
_startPosX = 0;
|
|
_startPosY = 0;
|
|
}
|
|
}
|
|
public void MoveTransport(DirectionType direction){
|
|
if (EntityCatamaran == null)
|
|
return;
|
|
CatamaranPanel.paint(CatamaranPanel.getGraphics());
|
|
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 - 20;
|
|
break;
|
|
case Down:
|
|
if (_startPosY + _catamaranHeight + EntityCatamaran.Step() < _pictureHeight)
|
|
_startPosY += (int)EntityCatamaran.Step();
|
|
else
|
|
_startPosY = _pictureHeight - _catamaranHeight;
|
|
break;
|
|
}
|
|
drawningOars.OarPosX = _startPosX;
|
|
drawningOars.OarPosY = _startPosY;
|
|
}
|
|
public void DrawnCatamaran(){
|
|
Graphics2D g2d = (Graphics2D)CatamaranPanel.getGraphics();
|
|
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();
|
|
}
|
|
}
|