安卓碰撞检测实现



我正在为Android制作一款太空射击游戏,我在敌人和玩家飞船之间的碰撞检测方面遇到了一些问题(//检测敌人与玩家的碰撞)。如果有人能帮我找到最好的方法,我将不胜感激。查看下面的我的detectCollisions():

**私有无效检测冲突(){

    // Detect enemy collision with player; to be revised
    for (int z = 0; z < SSEngine.TOTAL_INTERCEPTORS + SSEngine.TOTAL_SCOUTS + SSEngine.TOTAL_WARSHIPS - 1; z++ ){
    if(enemies[z].posX <= SSEngine.playerBankPosX 
            && enemies[z].posY <= SSEngine.playerBankPosX )
    {
        player1.applyDamage(); 
    }
    }
    //Detect Player's fire 
    for (int y = 0; y < 3; y ++)
        if (playerFire[y].shotFired){
            for (int x = 0; x < SSEngine.TOTAL_INTERCEPTORS + SSEngine.TOTAL_SCOUTS + SSEngine.TOTAL_WARSHIPS - 1; x++ ){

                if(!enemies[x].isDestroyed && enemies[x].posY < 4.25 ){

                    if ((playerFire[y].posY >= enemies[x].posY - 1 
                            && playerFire[y].posY <= enemies[x].posY ) 
                            && (playerFire[y].posX <= enemies[x].posX + 1 
                            && playerFire[y].posX >= enemies[x].posX - 1)){
                        int nextShot = 0;
                        enemies[x].applyDamage();
                        playerFire[y].shotFired = false;
                        if (y == 3){
                            nextShot = 0;
                        }else{
                            nextShot = y + 1;
                        }
                        if (playerFire[nextShot].shotFired == false){
                            playerFire[nextShot].shotFired = true;
                            playerFire[nextShot].posX = SSEngine.playerBankPosX;
                            playerFire[nextShot].posY = 1.25f;
                        }
                    }
                }
            }
        }
    }**

您在if中的检查错误-

如果,

playerFire[y].posY >= enemies[x].posY - 1为真是怎么来的

playerFire[y].posY <= enemies[x].posY是否成立?

你是ANDING true&amp;错误,所以它将永远是错误的。

相关内容

  • 没有找到相关文章

最新更新