Wednesday, March 22, 2023
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 aspect enumeration. Nevertheless, once I strive to attract them to the display screen, they’re truly on the identical aspect, on the left aspect 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 at all times on the left aspect, which appears constant, which is the primary worth within the aspect 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?

// Embody vital libraries right here
#embody <SFML/Graphics.hpp>
// Make code simpler to sort with "utilizing namespace"
utilizing namespace sf;
// Perform 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 aspect { LEFT, RIGHT, NONE };
aspect branchPositions[NUM_BRANCHES];
// That is the place our recreation begin from
int most important()
{
    // Create a video mode object
    VideoMode vm(1920, 1080);
    // Create and open a window for the sport
    RenderWindow window(vm, "Timber!!!", Model::Fullscreen);
    // Observe whether or not the sport is working
    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] == aspect::LEFT)
                {
                    // Transfer the sprite to the left aspect
                    branches[i].setPosition(610, peak);
                    // Flip the sprite spherical the opposite means
                    branches[i].setRotation(180);
                }
                else if (branchPositions[i] == aspect::RIGHT)
                {
                    // Transfer the sprite to the appropriate aspect
                    branches[i].setPosition(1330, peak);
                    // Set the sprite rotation to regular
                    branches[i].setRotation(0);
                }
                else
                {
                    // cover the department
                    branches[i].setPosition(3000, peak);
                }
            }
        } // Finish if(!paused)
        /*
        ****************************************
        Draw the scene
        ****************************************
        */
        // Clear every part from the final body
        window.clear();
        // Draw the branches
        for (int i = 0; i < NUM_BRANCHES; i++)
        {
            window.draw(branches[i]);
        }
        // Present every part we simply drew
        window.show();
    }
        return 0;
}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments