Tuesday, July 19, 2022
HomeGame Developmentsfml - Are they really rubbish values or simply the default values...

sfml – Are they really rubbish values or simply the default values of enumeration if I do not initialize them?


I’ve department positions that aren’t initialized to any worth of facet enumeration. Nonetheless, after I strive to attract them to the display, they’re truly on the identical facet, on the left facet of the tree. I feel these uninitialized department positions are rubbish values, a remnant from the reminiscence that the PC has been used or hasn’t been used. I am not fairly certain each time I run this system, they’re all the time on the left facet, which appears constant, which is the primary worth within the facet enumeration, which I assumed to be 0. Are they really rubbish values or simply the default values of enumeration if I do not initialize them?

// Embrace necessary libraries right here
#embody <SFML/Graphics.hpp>
// Make code simpler to kind with "utilizing namespace"
utilizing namespace sf;
// Operate declaration
void updateBranches(int seed);
const int NUM_BRANCHES = 6;
Sprite branches[NUM_BRANCHES];
// The place is the participant/department?
// Left or Proper
enum class facet { LEFT, RIGHT, NONE };
facet branchPositions[NUM_BRANCHES];
// That is the place our recreation begin from
int major()
{
    // Create a video mode object
    VideoMode vm(1920, 1080);
    // Create and open a window for the sport
    RenderWindow window(vm, "Timber!!!", Fashion::Fullscreen);
    // Observe whether or not the sport is operating
    bool paused = true;
    whereas (window.isOpen())
    {
        /*
        ****************************************
        Deal with the participant's enter
        ****************************************
        */
        if (Keyboard::isKeyPressed(Keyboard::Escape))
        {
            window.shut();
        }
        // Begin the sport
        if (Keyboard::isKeyPressed(Keyboard::Enter))
        {
            paused = false;
            // Reset the time and the rating
            rating = 0;
            timeRemaining = 6;
        }
        /*
        ****************************************
        Replace the scene
        ****************************************
        */
        if (!paused)
        {
            // replace the department sprites
            for (int i = 0; i < NUM_BRANCHES; i++)
            {
                float peak = i * 150;
                if (branchPositions[i] == facet::LEFT)
                {
                    // Transfer the sprite to the left facet
                    branches[i].setPosition(610, peak);
                    // Flip the sprite spherical the opposite approach
                    branches[i].setRotation(180);
                }
                else if (branchPositions[i] == facet::RIGHT)
                {
                    // Transfer the sprite to the suitable facet
                    branches[i].setPosition(1330, peak);
                    // Set the sprite rotation to regular
                    branches[i].setRotation(0);
                }
                else
                {
                    // conceal the department
                    branches[i].setPosition(3000, peak);
                }
            }
        } // Finish if(!paused)
        /*
        ****************************************
        Draw the scene
        ****************************************
        */
        // Clear all the things from the final body
        window.clear();
        // Draw the branches
        for (int i = 0; i < NUM_BRANCHES; i++)
        {
            window.draw(branches[i]);
        }
        // Present all the things we simply drew
        window.show();
    }
        return 0;
}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments