我正在制作一个游戏,屏幕顶部的昆虫会掉下来。游戏的目标是杀死这些昆虫。我为这些昆虫编写了关于它们如何移动的代码,但问题似乎是它们似乎以不平滑的方式旋转。他们抽搐!这是代码:
 else // Enemy is still alive and moving across the screen
    {
        //rotate the enemy between 10-5 degrees
        tempEnemy.rotation += (Math.round(Math.random()*10-5));
        //Find the rotation and move the x position that direction
        tempEnemy.x -=  (Math.sin((Math.PI/180)*tempEnemy.rotation))*tempEnemy.speed;
        tempEnemy.y +=  (Math.cos((Math.PI/180)*tempEnemy.rotation))*tempEnemy.speed;
        if (tempEnemy.x < 0)
        {
            tempEnemy.x = 0;
        }
        if (tempEnemy.x > stage.stageWidth)
        {
            tempEnemy.x = stage.stageWidth;
        }
        if (tempEnemy.y > stage.stageHeight)
        {
            removeEnemy(i);
            lives--;
            roachLevel.lives_txt.text = String(lives);
        }
    }
}
} 我遇到的另一个问题是一些昆虫沿着屏幕边缘移动。用户几乎无法杀死他们,因为他们的身体一半在屏幕上,另一半在屏幕上。我可以让它们稍微远离边缘,比如偏移吗?谢谢!