Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7185191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:21:45+00:00 2026-05-28T18:21:45+00:00

Like in Title I want to get position from List<Vector2> positions = new List<Vector2>{/*here

  • 0

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:)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T18:21:46+00:00Added an answer on May 28, 2026 at 6:21 pm

    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:

    int _lives;
    int _ammo;
    List<Vector2> _positions;
    Vector2 _playerPosition;
    int _currentLevel;    
    
    void LoadLevel(int level)
    {
        _currentLevel = level;
        _playerPosition = Vector2.Zero;
        _lives = 3;
        _ammo = 100;
        List<Vector2> list = new List<Vector2>();
        Random rnd = new Random();
        int i = 0;
        while(i < level)
        {
          list.Add(_positions[rnd.Next(0,10)]);
          i++;
        }
        ...
    }
    

    Then in your update:

    protected void Update(GameTime gameTime)
    {
        if(goToNextLevel) //here you put your condition that advances to next level;
        {
            LoadLevel(_currentLevel+1);
        }
    }
    

    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:

        List<Vector2> list = new List<Vector2>();
        List<Vector2> tempList = new List<Vector2>(_positions);
        Random rnd = new Random();
        int i = 0;
    
        while(i < level)
        {
          int index = rnd.Next(tempList.Count); //random goes up to number of items
          list.Add(tempList[index]); //add the randomed item
          tempList.RemoveAt(index); //remove the randomed item from the temporary list.
          i++;
        }
        ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to know how to get mp3 file details like artist, title, album
I want to create a box like this with title: Can any one please
I want to have my title tag look like this: My Website - Name
What I want to do is something like this: <asp:Label ID=titleLabel runat=server **Text='<%# SiteMap.CurrentNode.Title
I want to do something like this: <MyTemplate> <span><%# Container.Title %></span> <MySubTemplate> <span><%# Container.Username
Searching from google.com, like www.abc.com Search Result Rank the pages like Title..... Description... www.abc.com
From the title it might be a little unclear what I want to ask
Like the title says Where and How (i.e. if encrypted, with what method) does
Like the title says, how do you create custom code snippets in Visual Studio
Like the title says, If I place an app_offline.htm in the application root, will

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.