未检测到android中的碰撞

时间:2015-08-30 20:25:14

标签: android collision

我正在开发一款Android游戏,其中的鸟应该能够使用加速计传感器躲避接近它的物体。

此代码应该检测到冲突,但事实并非如此。谁能说出问题是什么?

do{
            random(); //for generating random no.k//moving objects using animations.
            TranslateAnimation animation_plane = new TranslateAnimation(0.0f, 0.0f,
                    0.0f, 800.0f);
            animation_plane.setDuration(4500);
            animation_plane.setRepeatCount(i);
            TranslateAnimation animation_superman = new TranslateAnimation(0.0f, 0.0f,
                    0.0f, 800.0f);
            animation_superman.setDuration(3000);
            animation_superman.setRepeatCount(i);
            TranslateAnimation animation_space = new TranslateAnimation(0.0f, 0.0f,
                    0.0f, 800.0f);
            animation_space.setDuration(2500);
            animation_space.setRepeatCount(i); if (answer % 2 == 0)  //answer is random int being generated
                plane.startAnimation(animation_plane);
            if (answer % 3 == 0)
                superman.startAnimation(animation_superman);
            if (answer % 4 == 0 || answer % 5 == 0)
                spaceship.startAnimation(animation_space);
    bird_x = bird.getX();//for getting position of objects and bird.          
    bird_y = bird.getY();
    plane_x = plane.getX();
    plane_y = plane.getY();
    superman_x = superman.getX();
    superman_y = superman.getY();
    spaceship_x = spaceship.getX();
    spaceship_y = spaceship.getY();
         if(spaceship.getTranslationY()>660)
            {
                score+=1;
                newscore="score = "+score+"";
                text.setText(newscore);
            }
            if(superman.getTranslationY()>660)
            {
                score+=1;
                newscore="score = "+score+"";
                text.setText(newscore);
            }
            if(plane.getTranslationY()>660)
            {
                score+=1;
                newscore="score = "+score+"";
                text.setText(newscore);
            }
        }while(bird.getTranslationX()!=plane.getTranslationX()||bird.getTranslationX()!=spaceship.getTranslationX()||bird.getTranslationX()!=superman.getTranslationX());`

1 个答案:

答案 0 :(得分:0)

你的状态是否应该使用&&而不是||?

我正在努力遵循这个游戏中的逻辑,但是我假设你一旦飞机/太空飞船/超人走到屏幕的底部就得到一个点,这意味着你已经躲过了它?如果任何一个对象与鸟X位置对齐,循环结束,游戏结束?

您可能还需要检查鸟Y位置是否与物体Y位置相同。