Доработал движение

This commit is contained in:
gettterot 2024-05-15 05:36:07 +04:00
parent d886c58e2a
commit 5929ff30b4
10 changed files with 23 additions and 19 deletions

View File

@ -9,8 +9,8 @@ public class DrawningLiner extends JPanel {
private Integer picture_height;
private Integer _StartPosX;
private Integer _StartPosY;
private int drawningCarWidth = 120;
private int drawningCarHeight = 90;
private int drawningLinerWidth = 160;
private int drawningLinerHeight = 120;
public void Init(int speed, double weight, Color bodycolor, Color additionalcolor, boolean pipe, boolean anchor) {
EntityLiner = new EntityLiner();
@ -26,17 +26,17 @@ public class DrawningLiner extends JPanel {
}
public boolean SetPictureSize(int width, int height) {
if (width < drawningCarWidth || height < drawningCarHeight)
if (width < drawningLinerWidth || height < drawningLinerHeight)
return false;
picture_width = width;
picture_height = height;
if (_StartPosX != null || _StartPosY != null) {
if (_StartPosX + drawningCarWidth > picture_width) {
_StartPosX = _StartPosX - (_StartPosX + drawningCarWidth - picture_width);
if (_StartPosX + drawningLinerWidth > picture_width) {
_StartPosX = _StartPosX - (_StartPosX + drawningLinerWidth - picture_width);
} else if (_StartPosX < 0)
_StartPosX = 0;
if (_StartPosY + drawningCarHeight > picture_height) {
_StartPosY = _StartPosY - (_StartPosY + drawningCarHeight - picture_height);
if (_StartPosY + drawningLinerHeight > picture_height) {
_StartPosY = _StartPosY - (_StartPosY + drawningLinerHeight - picture_height);
} else if (_StartPosY < 0)
_StartPosY = 0;
}
@ -46,14 +46,14 @@ public class DrawningLiner extends JPanel {
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);
if (x + drawningLinerWidth > picture_width) {
_StartPosX = x - (x + drawningLinerWidth - picture_width);
} else if (x < 0)
_StartPosX = 0;
else
_StartPosX = x;
if (y + drawningCarHeight > picture_height) {
_StartPosY = y - (y + drawningCarHeight - picture_height);
if (y + drawningLinerHeight > picture_height) {
_StartPosY = y - (y + drawningLinerHeight - picture_height);
} else if (y < 0)
_StartPosY = 0;
else
@ -65,23 +65,23 @@ public class DrawningLiner extends JPanel {
return false;
switch (direction) {
case Left:
if (_StartPosX - EntityLiner.Step > 0) {
if (_StartPosX - EntityLiner.Step > -40) {
_StartPosX -= (int) EntityLiner.Step;
}
return true;
case Up:
if (_StartPosY - EntityLiner.Step > 0) {
if (_StartPosY - EntityLiner.Step > -40) {
_StartPosY -= (int) EntityLiner.Step;
}
return true;
case Right:
if (_StartPosX + drawningCarWidth + 2 * (int) EntityLiner.Step < picture_width
if (_StartPosX + drawningLinerWidth + (int) EntityLiner.Step < picture_width
- EntityLiner.Step) {
_StartPosX += (int) EntityLiner.Step;
}
return true;
case Down:
if (_StartPosY + drawningCarHeight + 2 * (int) EntityLiner.Step < picture_height
if (_StartPosY + drawningLinerHeight + (int) EntityLiner.Step < picture_height
- EntityLiner.Step) {
_StartPosY += (int) EntityLiner.Step;
}

View File

@ -30,17 +30,21 @@ public class FormLiner extends JFrame {
Height = getHeight() - 35;
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.setName("UP");
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);
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);
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);
CreateButton.addActionListener(new ActionListener() {

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 141 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 139 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 141 KiB