Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
边界代码-Java_Java_Boundary - Fatal编程技术网

边界代码-Java

边界代码-Java,java,boundary,Java,Boundary,我正在为一个游戏编写一个代码,我需要帮助的是,我将对象放在地图上,并试图使它使玩家无法穿过对象。问题是x边界有效,但y边界无效,我不确定如何处理 public Boolean checkPathClear(int x, int y){ xPPos=x; yPPos=y; int tX1=350-50-xPos,tX2=450-xPos,tY1=200,tY2=300; if ((xPPos>=tX1)&&(xPPos<=tX2

我正在为一个游戏编写一个代码,我需要帮助的是,我将对象放在地图上,并试图使它使玩家无法穿过对象。问题是x边界有效,但y边界无效,我不确定如何处理

 public Boolean checkPathClear(int x, int y){
     xPPos=x;
     yPPos=y;
     int tX1=350-50-xPos,tX2=450-xPos,tY1=200,tY2=300;
     if ((xPPos>=tX1)&&(xPPos<=tX2)&&(yPPos>=tY1)&&(yPPos<tY2))
       return(false);
     else
       return(true);
   }
   public void paintComponent(Graphics g){    
     g.drawImage(imgTurret,350-xPos,200,450-xPos,300,0,0,126,110, this);

     g.drawImage(imgPlayer,xPPos,yPPos,xPPos+50,yPPos+50,xPFace,yPFace,xPFace+50,yPFace+50, this);
       }
 }
 //xPPos is 200 at the start.
 //yPPos is 200 at the start.
 //xPos is 0 at the start.
 //xPFace, yPFace is just the direction the player is facing so it doesnt matter
我编辑了代码,因此人们不需要查看所有内容:

如果有人能帮助我,我将不胜感激

编辑:任何人谁想看到我的船上,我实施的代码。当您向右移动时,图像显示向左移动,因此看起来屏幕向右移动

您的图像具有以下尺寸:

imageX: 350-xPos,
imageY: 200,
width: 450-xPos,
height: 300
因此:


也许我现在能给你的最好建议就是写清楚、简洁的问题。基本上,这个问题正好相反。我不明白这一点,对不起,我不是java的高手。为什么“在x之前存在?”x=x+50。对不起,我完全是抽象的。它看起来有点像你们认为drawImage的宽度和高度参数是右x和右y。所以我重新制定了所有的计划。
return !(imageX <= x && x' < imageX + width
    && imageY <= y && y' < imageY + height);