开发者

overlapping objects - help

can someone help me with the following problem please:

In my game there appear scores when you shoot down enemies. That kinda works so far but they overlap when the enemies were too close to each other when shot down. Now what I'd like to do is to prevent the overlapping of the scores. The basic idea I had was to loop through the array of scores and to check the distance to each other. Problem is that it doesn't work. Can someone help please?

private function checkScoreDistance():void
{
scoreManager.scoreCount = scoreManager.scores.length;
if (scoreManager.scoreCount >= 1)
{
    scoreManager.scoreCount = scoreManager.scores.length - 1;
    scoreManager.scoreCountTwo = scoreManager.scores.length - 2;

    scoreOne: for (var scoreCtr:int = scoreManager.scoreCount; scoreCtr >= 0; scoreCtr--)
    {

        tempScore = scoreManager.scores[scoreCtr];
        tempScore.point.x = tempScore.x;
        tempScore.point.y = tempScore.y;
        oldtempScoreX = tempScore.x;
        oldtempScoreY = tempScore.y;

        var tempScoreTwo:Score;
        scoreTwo: for (var scoreCtrTwo:int = scoreManager.scoreCountTwo; scoreCtrTwo >= 0; scoreCtrTwo--)
        {
            tempScoreTwo = scoreManager.scores[scoreCtrTwo];
            tempScoreTwo.point.x = tempScoreTwo.x;
            tempScoreTwo.point.y = tempScoreTwo.y;

            oldtempScoreTwoX = tempScoreTwo.x;
            开发者_如何学编程oldtempScoreTwoY = tempScoreTwo.y; 

            var scoresX:Number; 
            scoresX = oldtempScoreTwoX - oldtempScoreX;

            var scoresY:Number;
            scoresY = oldtempScoreTwoY - oldtempScoreY;

            var dist:Number;

            dist = Math.sqrt(scoresX * scoresX + scoresY * scoresY);

            if (dist <= 25)
            {
                oldtempScoreX -= 25;
                oldtempScoreTwoX += 25;

                oldtempScoreY -= 25;
                oldtempScoreTwoY += 25;
                }

            }

        }
    }
}
}


Um, you seem to be lacking some code to do something with the values you compute in oldtempScoreX and oldtemScoreTwoX. Apparently there is nothing to actually move anything based on the calculations ...

Also, what if an object is bumped left because it has a close neighbor to the right and then afterwards is bumped right because it now has a close neighbor to the left?

Also also: You seem to be blindly bumping oldtempScore to the northwest and oldtempScoreTwo to the southeast, without actually checking that their relative position is such that this makes sense.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜