绿脚制作乒乓球比赛的墙

时间:2014-11-26 22:35:04

标签: java if-statement

嗨,我正在绿脚打乒乓球比赛。但我不知道为什么顶墙不会反弹球。我认为if语句给出了问题。有人可以帮助我:)这是我的代码:

public class ball extends Actor
{
    int startX = 3;
    int startY = 3;


    public void act()
    {
        // Add your action code here.
        move();
        wall();
        playerBounce();
        computer();
    }
    public void move(){
        setLocation(getX()+ startX ,getY()+startY);
    }
    public void wall(){
        if(getY()> getWorld().getHeight() - getImage().getHeight()/2){
        startY = startY * -1;
    }
if(getY() <= 50) {
            startY = startY * +1;
    }
    }

    public void playerBounce(){

    Actor playt = getOneIntersectingObject(player2.class);
    if (playt != null){
        startX = startX *-1;

    }
    }
    public void computer(){
    Actor playo = getOneIntersectingObject(player1.class);
    if (playo != null){
        startX = startX *-1;

    }
    }
}

1 个答案:

答案 0 :(得分:0)

它可能与从getHeight()派生的高度有关,因为它没有反弹,那么Y * -1可能等于0 * -1,这意味着什么。