Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Tamas35

Pages: [1]
1
Graphics / shuffling vector array with tiles
« on: January 31, 2021, 06:01:02 pm »
I am working on a school project. It is a tile moving game, I have the tiles on the screen taken out from a tiles vector array.

I am trying to shuffle the tiles and put them into another vector array called shuffledTiles and then show them on the screen but the code I wrote just works with only one tile. Can anybody help me what I have done on the wrong way. I am a beginner programmer.

This is the code I have for shuffling:

for (int i = 0; i < tiles.size(); i++)
        {
               
                // Vector2f variable for storing the position of the random selected tile
                //sf::Vector2f randTilePosXY;

                // integer for the random number between 0 and 15
                int randomNumber = rand() % 15;
               
                // console out to see which random number is selected
                std::cout << "Random Number: " << randomNumber << std::endl;

                // taking the randomly selected tile's position and saving it into the Vector2f variable
                sf::Vector2f randTilePosXY = this->tiles[randomNumber].getPosition();

                // setting the position of item in the shuffledTiles vector storage under the index number
                //this->shuffledTiles[i].setPosition(sf::Vector2f(randTilePosXY));

                // putting the randomly selected tile to the end of the new shuffledTiles vector array
                this->shuffledTiles.push_back(this->tiles[randomNumber]);

                std::cout << "shuffledTile X position : " << shuffledTiles[i].getPosition().x << " , shuffleTile Y position: " << shuffledTiles[i].getPosition().y << endl;

               
        }
 

Can anybody help me why it is showing only one tile on the screen?

On the attached files you can see what I have and what I want to achieve

And my random generator generates same numbers sometimes, I would like to change that one as well. All help appreciated I am persistent to solve this.

Thank you very much everybody

Pages: [1]
anything