Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.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_Game Physics - Fatal编程技术网

Java游戏:检查十字路口和跳跃

Java游戏:检查十字路口和跳跃,java,game-physics,Java,Game Physics,我需要在我正在创建的游戏中检查交叉点的帮助:当一个角色与屏幕上的单个障碍物碰撞时,所有操作都按预期进行,但是当多个障碍物添加到屏幕上时,角色只能跳出正在检查碰撞的最后一个障碍物。角色仍然会与其他障碍物发生适当碰撞(无法穿过、无法穿过),但无法跳出障碍物。Obs是一个障碍列表。Ground是确定是否允许角色跳转的布尔值 public void checkIntersect(ArrayList<Obstacle> obs){ for(Obstacle a: obs){

我需要在我正在创建的游戏中检查交叉点的帮助:当一个角色与屏幕上的单个障碍物碰撞时,所有操作都按预期进行,但是当多个障碍物添加到屏幕上时,角色只能跳出正在检查碰撞的最后一个障碍物。角色仍然会与其他障碍物发生适当碰撞(无法穿过、无法穿过),但无法跳出障碍物。Obs是一个障碍列表。Ground是确定是否允许角色跳转的布尔值

public void checkIntersect(ArrayList<Obstacle> obs){
    for(Obstacle a: obs){


        if(a.getLeft().intersects(this.getRight())){
            if(getDx()>0){
                sidecollision=true;
                setDx(0);
                this.x-=1.5f;
            }
        } if (a.getRight().intersects(this.getLeft())){
                sidecollision = true;
                setDx(0);
                this.x+=1.5f;
        } if((a.getTop()).intersects(this.getBottom())){
            ground=true;
            setDy(0);
            this.y-=.10f;
        } else if(!(a.getTop()).intersects(this.getBottom())){ 
                ground = false;

                //return ground;        
        } if(a.getBottom().intersects(this.getTop())){
            ground=false;
            setDy(0);

            this.y+=.1f;
        }

    }
} 

导致错误的最可能原因是后续调用
checkIntersect()
覆盖
ground
的值。这导致
ground
的值仅反映上次调用
checkIntersect()
。要修复此错误,在调用
checkIntersect()
之前,应将
ground
设置为默认值
true
false
。然后,修改
checkIntersect()
方法,使其只能将
ground
设置为非默认值。当
ground
应为其默认值时,无需进行设置

像这样做。我使用的默认值是
false

public void checkIntersect(ArrayList<Obstacle> obs){
    for(Obstacle a: obs){


        if(a.getLeft().intersects(this.getRight())){
            if(getDx()>0){
                sidecollision=true;
                setDx(0);
                this.x-=1.5f;
            }
        } if (a.getRight().intersects(this.getLeft())){
                sidecollision = true;
                setDx(0);
                this.x+=1.5f;
        } if((a.getTop()).intersects(this.getBottom())){
            ground=true;
            setDy(0);
            this.y-=.10f;
        } else if(!(a.getTop()).intersects(this.getBottom())){ 
                // ground = false;

                //return ground;        
        } if(a.getBottom().intersects(this.getTop())){
            // ground=false;
            // setDy(0);

            // this.y+=.1f;
        }

    }
} 

欢迎来到堆栈溢出。请编辑您的帖子,澄清您寻求帮助的问题。您希望您的代码会发生什么,以及正在发生什么?如果有必要,您可能会考虑添加一些示例数据来解决令您担忧的情况。祝你好运1) 你已经描述了一个问题以及你怎么做不到,但到目前为止还没有提出一个问题(更不用说一个具体的、可回答的问题了)。你的问题是什么?2) 看。3) 为了更快地获得更好的帮助,请发布一个。
public void checkIntersect(ArrayList<Obstacle> obs){
    for(Obstacle a: obs){


        if(a.getLeft().intersects(this.getRight())){
            if(getDx()>0){
                sidecollision=true;
                setDx(0);
                this.x-=1.5f;
            }
        } if (a.getRight().intersects(this.getLeft())){
                sidecollision = true;
                setDx(0);
                this.x+=1.5f;
        } if((a.getTop()).intersects(this.getBottom())){
            ground=true;
            setDy(0);
            this.y-=.10f;
        } else if(!(a.getTop()).intersects(this.getBottom())){ 
                // ground = false;

                //return ground;        
        } if(a.getBottom().intersects(this.getTop())){
            // ground=false;
            // setDy(0);

            // this.y+=.1f;
        }

    }
} 
bg.update(quote);
        win.fill(clear);
        bg.drawBG(win);
        for(Obstacle o: obs){
            o.draw(win);
            o.update(bg);
        }

        // Set ground to its default value
        quote.ground = false;  

        if(quote.isVisible()){

                quote.movedrawProtag(win, keys);
                quote.checkIntersect(obs);
        }

        // If ground has not been set to true, do the default action
        if (quote.ground == false) {
            setDy(0);
            quote.y += .1f;
        }