Like in Title I want to get position from List<Vector2> positions = new List<Vector2>{/*here i got 9 vectors*/} and I want to get only some of them.
for example in 1-st level i want random check only 1 position from this list in 2-nd level 2 positions and so on…
//making that in switch statement where i check which level user actually is
Random rnd = new Random();
List<Vector2> list = new List<Vector2>();
byte i = 0;
byte level; // number from 0 to 9 changing where level complited;
while(i < level){
list.Add(positions[rnd.Next(0,10)]);
i++;
}
problem which i have is how to random this position only ones per level now i got randomize this but it changing all the time. I making it in draw Method.
where should i draw lots this positions? in update method or somewhere else?
Edit:
random check means that i want get only 1 Vector2 from my list but with using random class to randomize each level is that clear now? I don’t know how simplier i can explain this:(
Edit1:
and how to prevent from getting same position from list I mean how to check if this Vector2 from my list are drawn or not(are unique).
thanks for advance:)
Do it in the method where you load your level. Add an
i++in the while loop.Edit
Okay, I see what you mean now: one for level 1, two for level 2 etc..
Your code is okay and is going to do what you want, however putting it in the draw method (or the update) is wrong, as those methods execute often.
What you should do is have a special method that loads a new level. You could call this method when you detect that a level is finished and what it would do is clean up the resources from the previous level (like reset player positions, lives, ammo and such). Then you would construct the new level – placing enemies and such, and this includes the code you specified.
I hope I’ve made this somewhat clear.
Here is a prototype:
Then in your update:
Edit2
To get another item from the list that you didn’t have earlier you could create a temporary list, then remove items from it instead of just selecting them.
I haven’t tested this code, but it would go something like so: