|
-
I am trying to create a game with a (13x15)maze which is made from an Array called board.
Here's an example:
board[0] = new Array(2,2,2,2,2,2,2,2,2,2,2,2,2,2,2);
board[1] = new Array(2,0,0,0,1,1,1,1,1,1,1,0,0,0,2);
board[2] = new Array(2,0,2,1,2,1,2,1,2,1,2,1,2,0,2);
.
.
.
board[12] = new Array(2,2,2,2,2,2,2,2,2,2,2,2,2,2,2);
// 2 means a indestructable wall, 1 means destructable wall,
// 0 means open space which player can walk on.
This works fine, no problem here. But now I am trying to add some bonusses
at random coordinates on places with a no.1 wall in the Array. I used this function:
funcion addBonus(){
bCounter=0;
i=100;
do{
brickRow = random(13)+1;
brickColumn = random(11)+1;
if(_root.board[brickRow][brickColumn]== 0){
// do nothing
}
else if(_root.board[brickRow][brickColumn]== 2){
// do nothing
}
else if(_root.board[brickRow][brickColumn]== 1){
// place a MC at the right place
root.attachMovie("bonus","bonus"+i,i);
setProperty("bonus"+i, _x, brickRow*tileLength+edge);
setProperty("bonus"+i, _y, brickColumn*tileHeight+edge);
bCounter++;
i++;
}
} while(bCounter<_root.amountOfBonusses)
}
This function "loops" until all bonusses are placed in the maze. It's works but
has ONE thing I'm not happy about.
Sometimes "brickRow"&"brickColumn" generate the same random coordinate
like the last loop. E.g. first loop :
brickRow = 5;
brickColumn = 9;
Then on the second or third loop again:
brickRow = 5;
brickColumn = 9;
Placing 2 bonusses at the same coordinate!
My question (finally!): How can I prevent 2 MC's getting the same position with random generated x and y?
it's kinda drivin' me crazy!!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|