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

Author Topic: Some bugs or my errors...  (Read 1705 times)

0 Members and 1 Guest are viewing this topic.

AlexxanderX

  • Full Member
  • ***
  • Posts: 128
    • View Profile
    • AlexanderX
Some bugs or my errors...
« on: October 08, 2012, 03:37:20 pm »
Hello guys. I have again a problem. I created 2 rectangle shapes and one is the player who can be moved and one is the floor. When run the code in the place of player appear the floor. What is wrong?  :(
//////////////////////////////
/// Moving System 0.1      ///
/// Created by AlexxanderX ///
/// Build 0001             ///
/// Version 0.1            ///
//////////////////////////////

///////////////
/// Headers ///
///////////////
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/Audio.hpp>

///////////////

////////////
/// Code ///
////////////
int main()
{
    /////////////////////////
    // Declarare variabile //
    /////////////////////////
    sf::Vector2f playersize(50,50); // Marimea jucatorului
    sf::Vector2f floorsize(600,50); // Marimea platformei
    bool isPlaying = false; // Variabila de verificare a desfasurarii jocului
    /////////////////////////

    //////////////////////
    // Creare fereastra //
    //////////////////////
    sf::RenderWindow window(sf::VideoMode(800,600),"Moving System"); // Fereastra
    window.setVerticalSyncEnabled(true); // OpenGL VerticalSync
    //////////////////////

    /////////////
    // Fonturi //
    /////////////
        // Font general
    sf::Font font;
    if (!font.loadFromFile("resources/AGENTORANGE.ttf")) return -1;
    /////////////

    /////////////////////
    // Muzica & Sunete //
    /////////////////////
        // Muzica
            // Muzica de background
                // Background Music 1
    sf::Music bcgmsc1;
    if(!bcgmsc1.openFromFile("resources/backgroundmusic.ogg")) return -1;
    bcgmsc1.play();

        // Sunete

    /////////////////////

    // Creare jucator
    sf::RectangleShape player;
    player.setSize(playersize);
    player.setOutlineThickness(3);
    player.setOutlineColor(sf::Color::Black);
    player.setFillColor(sf::Color::Blue);
    player.setOrigin(playersize / 2.f);


    ////////////
    // Mesaje //
    ////////////
        // Mesaj general
    sf::Text message;
    message.setCharacterSize(40);
    message.setFont(font);
    message.setPosition(100, 15);
    message.setColor(sf::Color::Red);
    message.setString("Moving System");
    ////////////

    //////////////////////////////////////
    // Viteza jucator si alte variabile //
    //////////////////////////////////////
    float playerSpeed = 100.f;
    //////////////////////////////////////

    ///////////
    // Level //
    ///////////
    sf::RectangleShape floor1;
    player.setSize(floorsize);
    player.setOutlineThickness(2);
    player.setOutlineColor(sf::Color::Green);
    player.setFillColor(sf::Color::Black);
    player.setOrigin(floorsize / 1.f);
    ///////////

    /////////////
    // Actiune //
    /////////////
    sf::Clock clock; // Crearea ceasului( clock)
    while (window.isOpen())
    {
        sf::Event event;

        while (window.pollEvent(event))
        {
            // Metoda de inchidere
            if ((event.type == sf::Event::Closed) ||
               ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape)))
            {
                window.close();
                break;
            }

            if((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Space))
            {
                if(!isPlaying)
                {
                    isPlaying=true;
                    clock.restart();

                    // Resetare pozitii
                    player.setPosition(400,200);
                    floor1.setPosition(10,600);
                }
            }
        }

        if (isPlaying)
        {
            float deltaTime = clock.restart().asSeconds();

            // Miscarea jucatorului
                // Miscarea in Stanga
            if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
            {

                sf::Vector2f pos = player.getPosition();
                player.move(-playerSpeed * deltaTime,0);
            }
                // Miscarea in Dreapta
            if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
            {

                sf::Vector2f pos = player.getPosition();
                player.move(playerSpeed * deltaTime,0);
            }



            // Gravitatea
        }

        // Sterge fereastra
        window.clear(sf::Color::Yellow);

        // Afisare
        if(isPlaying)
        {
            window.draw(player);
            window.draw(floor1);
        }
        else
        {
            window.draw(message);
        }

        // Afisarea ecranul
        window.display();
    }

    return 0;
}
 
Here you can find my blog and tutorials about SFML - http://alexanderx.net/ (died...) - http://web.archive.org/web/20160110002847/http://alexanderx.net/

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Some bugs or my errors...
« Reply #1 on: October 08, 2012, 03:47:22 pm »
Copy-past error...

    ///////////
    // Level //
    ///////////
    sf::RectangleShape floor1;
    player.setSize(floorsize);
    player.setOutlineThickness(2);
    player.setOutlineColor(sf::Color::Green);
    player.setFillColor(sf::Color::Black);
    player.setOrigin(floorsize / 1.f);

You need to rename player. to floor1.. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

AlexxanderX

  • Full Member
  • ***
  • Posts: 128
    • View Profile
    • AlexanderX
Re: Some bugs or my errors...
« Reply #2 on: October 08, 2012, 05:55:24 pm »
S**t  :o. Thanks.
Here you can find my blog and tutorials about SFML - http://alexanderx.net/ (died...) - http://web.archive.org/web/20160110002847/http://alexanderx.net/

 

anything