Доработал движение
@ -9,8 +9,8 @@ public class DrawningLiner extends JPanel {
|
|||||||
private Integer picture_height;
|
private Integer picture_height;
|
||||||
private Integer _StartPosX;
|
private Integer _StartPosX;
|
||||||
private Integer _StartPosY;
|
private Integer _StartPosY;
|
||||||
private int drawningCarWidth = 120;
|
private int drawningLinerWidth = 160;
|
||||||
private int drawningCarHeight = 90;
|
private int drawningLinerHeight = 120;
|
||||||
|
|
||||||
public void Init(int speed, double weight, Color bodycolor, Color additionalcolor, boolean pipe, boolean anchor) {
|
public void Init(int speed, double weight, Color bodycolor, Color additionalcolor, boolean pipe, boolean anchor) {
|
||||||
EntityLiner = new EntityLiner();
|
EntityLiner = new EntityLiner();
|
||||||
@ -26,17 +26,17 @@ public class DrawningLiner extends JPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean SetPictureSize(int width, int height) {
|
public boolean SetPictureSize(int width, int height) {
|
||||||
if (width < drawningCarWidth || height < drawningCarHeight)
|
if (width < drawningLinerWidth || height < drawningLinerHeight)
|
||||||
return false;
|
return false;
|
||||||
picture_width = width;
|
picture_width = width;
|
||||||
picture_height = height;
|
picture_height = height;
|
||||||
if (_StartPosX != null || _StartPosY != null) {
|
if (_StartPosX != null || _StartPosY != null) {
|
||||||
if (_StartPosX + drawningCarWidth > picture_width) {
|
if (_StartPosX + drawningLinerWidth > picture_width) {
|
||||||
_StartPosX = _StartPosX - (_StartPosX + drawningCarWidth - picture_width);
|
_StartPosX = _StartPosX - (_StartPosX + drawningLinerWidth - picture_width);
|
||||||
} else if (_StartPosX < 0)
|
} else if (_StartPosX < 0)
|
||||||
_StartPosX = 0;
|
_StartPosX = 0;
|
||||||
if (_StartPosY + drawningCarHeight > picture_height) {
|
if (_StartPosY + drawningLinerHeight > picture_height) {
|
||||||
_StartPosY = _StartPosY - (_StartPosY + drawningCarHeight - picture_height);
|
_StartPosY = _StartPosY - (_StartPosY + drawningLinerHeight - picture_height);
|
||||||
} else if (_StartPosY < 0)
|
} else if (_StartPosY < 0)
|
||||||
_StartPosY = 0;
|
_StartPosY = 0;
|
||||||
}
|
}
|
||||||
@ -46,14 +46,14 @@ public class DrawningLiner extends JPanel {
|
|||||||
public void SetPosition(int x, int y) {
|
public void SetPosition(int x, int y) {
|
||||||
if (!(picture_width != null && picture_height != null))
|
if (!(picture_width != null && picture_height != null))
|
||||||
return;
|
return;
|
||||||
if (x + drawningCarWidth > picture_width) {
|
if (x + drawningLinerWidth > picture_width) {
|
||||||
_StartPosX = x - (x + drawningCarWidth - picture_width);
|
_StartPosX = x - (x + drawningLinerWidth - picture_width);
|
||||||
} else if (x < 0)
|
} else if (x < 0)
|
||||||
_StartPosX = 0;
|
_StartPosX = 0;
|
||||||
else
|
else
|
||||||
_StartPosX = x;
|
_StartPosX = x;
|
||||||
if (y + drawningCarHeight > picture_height) {
|
if (y + drawningLinerHeight > picture_height) {
|
||||||
_StartPosY = y - (y + drawningCarHeight - picture_height);
|
_StartPosY = y - (y + drawningLinerHeight - picture_height);
|
||||||
} else if (y < 0)
|
} else if (y < 0)
|
||||||
_StartPosY = 0;
|
_StartPosY = 0;
|
||||||
else
|
else
|
||||||
@ -65,23 +65,23 @@ public class DrawningLiner extends JPanel {
|
|||||||
return false;
|
return false;
|
||||||
switch (direction) {
|
switch (direction) {
|
||||||
case Left:
|
case Left:
|
||||||
if (_StartPosX - EntityLiner.Step > 0) {
|
if (_StartPosX - EntityLiner.Step > -40) {
|
||||||
_StartPosX -= (int) EntityLiner.Step;
|
_StartPosX -= (int) EntityLiner.Step;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
case Up:
|
case Up:
|
||||||
if (_StartPosY - EntityLiner.Step > 0) {
|
if (_StartPosY - EntityLiner.Step > -40) {
|
||||||
_StartPosY -= (int) EntityLiner.Step;
|
_StartPosY -= (int) EntityLiner.Step;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
case Right:
|
case Right:
|
||||||
if (_StartPosX + drawningCarWidth + 2 * (int) EntityLiner.Step < picture_width
|
if (_StartPosX + drawningLinerWidth + (int) EntityLiner.Step < picture_width
|
||||||
- EntityLiner.Step) {
|
- EntityLiner.Step) {
|
||||||
_StartPosX += (int) EntityLiner.Step;
|
_StartPosX += (int) EntityLiner.Step;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
case Down:
|
case Down:
|
||||||
if (_StartPosY + drawningCarHeight + 2 * (int) EntityLiner.Step < picture_height
|
if (_StartPosY + drawningLinerHeight + (int) EntityLiner.Step < picture_height
|
||||||
- EntityLiner.Step) {
|
- EntityLiner.Step) {
|
||||||
_StartPosY += (int) EntityLiner.Step;
|
_StartPosY += (int) EntityLiner.Step;
|
||||||
}
|
}
|
||||||
|
@ -30,17 +30,21 @@ public class FormLiner extends JFrame {
|
|||||||
Height = getHeight() - 35;
|
Height = getHeight() - 35;
|
||||||
|
|
||||||
CreateButton.setName("CREATE");
|
CreateButton.setName("CREATE");
|
||||||
Icon iconUp = new ImageIcon("src\\imges\\up.jpg");
|
Icon iconUp = new ImageIcon(
|
||||||
|
"E:\\Проекты\\ООП Java\\Pibd_13_Fathutdinov.A.I_Hard\\ProjectLiner\\src\\images\\top.png");
|
||||||
UpButton.setIcon(iconUp);
|
UpButton.setIcon(iconUp);
|
||||||
UpButton.setName("UP");
|
UpButton.setName("UP");
|
||||||
DownButton.setName("DOWN");
|
DownButton.setName("DOWN");
|
||||||
Icon iconDown = new ImageIcon("src\\images\\down.jpg");
|
Icon iconDown = new ImageIcon(
|
||||||
|
"E:\\Проекты\\ООП Java\\Pibd_13_Fathutdinov.A.I_Hard\\ProjectLiner\\src\\images\\bottom.png");
|
||||||
DownButton.setIcon(iconDown);
|
DownButton.setIcon(iconDown);
|
||||||
LeftButton.setName("LEFT");
|
LeftButton.setName("LEFT");
|
||||||
Icon iconLeft = new ImageIcon("src\\images\\left.jpg");
|
Icon iconLeft = new ImageIcon(
|
||||||
|
"E:\\Проекты\\ООП Java\\Pibd_13_Fathutdinov.A.I_Hard\\ProjectLiner\\src\\images\\left.png");
|
||||||
LeftButton.setIcon(iconLeft);
|
LeftButton.setIcon(iconLeft);
|
||||||
RightButton.setName("RIGHT");
|
RightButton.setName("RIGHT");
|
||||||
Icon iconRight = new ImageIcon("src\\images\\right.jpg");
|
Icon iconRight = new ImageIcon(
|
||||||
|
"E:\\Проекты\\ООП Java\\Pibd_13_Fathutdinov.A.I_Hard\\ProjectLiner\\src\\images\\right.png");
|
||||||
RightButton.setIcon(iconRight);
|
RightButton.setIcon(iconRight);
|
||||||
|
|
||||||
CreateButton.addActionListener(new ActionListener() {
|
CreateButton.addActionListener(new ActionListener() {
|
||||||
|
BIN
ProjectLiner/src/images/bottom.png
Normal file
After Width: | Height: | Size: 5.7 KiB |
Before Width: | Height: | Size: 141 KiB |
Before Width: | Height: | Size: 139 KiB |
BIN
ProjectLiner/src/images/left.png
Normal file
After Width: | Height: | Size: 5.1 KiB |
Before Width: | Height: | Size: 4.8 KiB |
BIN
ProjectLiner/src/images/right.png
Normal file
After Width: | Height: | Size: 4.9 KiB |
BIN
ProjectLiner/src/images/top.png
Normal file
After Width: | Height: | Size: 5.5 KiB |
Before Width: | Height: | Size: 141 KiB |