Z
Ziphold
Guest
I'm working on a rogue like dungeon explorer game where the rooms are pre-made but when the player walks through the door to enter a new room, It's randomly chosen from the variety of different rooms.
The problem was that often times, same rooms would be selected, so I had to write the following code to fix that:
This is the code: (I changed the variable names for simplicity, this code WORKS)
As you can see, what I do is select a room from the array of available rooms. I then check if I were in that room previously (All those rooms player visited are written in the array.) This list would be cleared every 5-10 rooms so there would always be a match the computer could find.
But is this really the optimal solution? What if someone's computer goes on a streak of selecting already visited rooms over and over again? The game would freeze for a second or two until the non-visited room is selected?
Any recommendations or ideas?
In advance, thank you.
The problem was that often times, same rooms would be selected, so I had to write the following code to fix that:
This is the code: (I changed the variable names for simplicity, this code WORKS)
Code:
do {
alreadyBeenInThatRoom = 0;
chosenRoom= irandom(array_length_1d(roomList)-1);
for(i=0; i<100; i++) {
if listOfVisitedRooms[i] = chosenRoom {
alreadyBeenInThatRoom= 1;
break;
}
}
} until alreadyBeenInThatRoom = 0;
room_goto(chosenRoom);
But is this really the optimal solution? What if someone's computer goes on a streak of selecting already visited rooms over and over again? The game would freeze for a second or two until the non-visited room is selected?
Any recommendations or ideas?
In advance, thank you.