Bienvenue, Invité. Merci de vous connecter ou de vous inscrire. Avez-vous oublié d'activer ?

Voir les contributions

Cette section vous permet de consulter les contributions (messages, sujets et fichiers joints) d'un utilisateur. Vous ne pourrez voir que les contributions des zones auxquelles vous avez accès.


Sujets - Glân de Brylan

Pages: « Précédente 1 [2]
16
Général / [Résolu] Uint32 ?...[Code::Blocks]
« le: Octobre 02, 2014, 06:02:30 pm »
Bonjour,
J'ai voulu créer une mini-API pour faire de la GUI avec la SFML mais je me heurte avec l'argument 'style' du constructeur de sf::Window...
L'idée était de passer le paramètre à ma classe absWindow qui ensuite le transmettait à une sf::RenderWindow member. Seulement quand j'essaie de mettre un uint32 en paramètre, j'obtiens : error : 'Uint32' has not been declared.
J'ai essayé de le remplacer par un uint32_t mais là j'ai eu ça :

Arf.
Premièrement : sf::Style : une énumération anonyme ?! Pourquoi ? Je n'ai jamais compris l'intérêt de ces trucs. Quelqu'un peut me l'expliquer svp ?
Deuxièmement : comment passer ce...heu...(bah ça a pas de nom du coup) style en paramètre ?

OS : Windows 8.1 x64
IDE : Code::Blocks 13.12
Compilo : GCC 4.7.1

Le code :

absWindow.h
#ifndef ABSWINDOW_H
#define ABSWINDOW_H



#include <SFML/Graphics.hpp>

#include<functional>
#include <string>
#include <vector>
#include <stdexcept>
#include <iostream>

#include "ButtonsList.h"

namespace glan
{

class absWindow : sf::NonCopyable
{
    friend class Button;
    public:
        absWindow(bool destrDeleteButtons = true, \
                  int x = 600, int y = 800, std::string const& title = "Window", uint32_t style = sf::Style::Default, sf::ContextSettings const& settings=sf::ContextSettings());
        // Arguments :
        //
        // x : the height of the window.
        //
        // y : the width of the window.
        //
        // title : the title shown in the title bar of the window.
        //
        // destrDeleteButtons : sets deleteButtons, which defines if the destructor deletes the buttons of the 'buttons' member.

        absWindow(bool destrDeleteButtons = true, \
                  sf::VideoMode const& videoMode = sf::VideoMode(800,600), std::string const& title = "Window", uint32_t = sf::Style::Default, sf::ContextSettings const& settings=sf::ContextSettings());
        // Arguments :
        //
        // videoMode : the video mode of the window.
        //
        // title : the title shown in the title bar of the window.
        //
        // destrDeleteButtons : sets deleteButtons, which defines if the destructor deletes the buttons of the 'buttons' member.

        virtual ~absWindow() = 0;
        // Destructor. If 'resetRect' member is true, deletes all glan::Button in 'buttons' member.


        virtual void show();
        // Shows the window.

        void useBtnsVect(int i = -1);
        // Sets 'btnsVectShown' member at 'i'.

        void close();
        // Closes the window and destroys this.

        virtual void update();
        // Should call updateButtons().
    protected:
        void updateButtons();
        // Drawn all buttons contained in 'buttons' member at(btnsVectShown), excepts these which are hidden. If buttons[btnsVectShown] is out of range, no button is

        bool deleteButtons;
        int btnsVectShown;
        std::vector<ButtonsList> buttonsLists;
        sf::RenderWindow window;
        sf::Event event;
};

} // namespace glan

#endif // ABSWINDOW_H
 

absWindow.cpp :
#include "absWindow.h"

using namespace glan;

absWindow::absWindow(bool destrDeleteButtons, int x, int y, std::string const& title, uint32_t style, sf::ContextSettings const& settings) :
    deleteButtons(destrDeleteButtons), btnsVectShown(-1), buttonsLists(), \
    window(sf::VideoMode(x, y), title, style, settings)
{
    window.setVisible(false);
}

absWindow::absWindow(bool destrDeleteButtons, sf::VideoMode const& videoMode, std::string const& title, uint32_t style, sf::ContextSettings const& settings) :
    deleteButtons(destrDeleteButtons), btnsVectShown(-1), buttonsLists(), window(videoMode, title, style, settings), event()
{
    window.setVisible(false);
}

absWindow::~absWindow()
{
    if(deleteButtons)
    {
        for(int i(0) ; i < (int)buttonsLists.size() ; i++)
            buttonsLists[i].clear();
    }
}


void absWindow::show()
{
    window.setVisible(false);

    while(window.isOpen())
    {
        update();
        while(window.pollEvent(event))
        {
            update();
            if(event.type == sf::Event::Closed)
                window.close();
        }
    }
}

void absWindow::close()
{
    window.close();
    delete this;
}

void absWindow::update()
{
    window.clear();
    updateButtons();
    // Other drawings...
    window.display();
}

void absWindow::updateButtons()
{
    ButtonsList temp;
    try
    {
        temp=buttonsLists.at(btnsVectShown);
    }
    catch (std::out_of_range const& expt)
    {
        std::cerr<<expt.what()<<std::endl<<"absWindow.cpp::updateButtons()"<<std::endl;
        return;
    }

    for(int i(0) ; i < (int)temp.size() ; i++)
    {
        if(temp[i] != nullptr)
        {
            if(temp[i]->isEnabled())
                temp[i]->checkClicked(event, window);

            if(!temp[i]->isHidden())
                window.draw(*temp[i]);
        }

    }
}
 

Je n'ai pas mis les fichiers de Button et ButtonsList, ça ne me semble pas nécessaire.

Merci d'avance.

17
Système / [Résolu][Threads] Too many arguments to function
« le: Septembre 24, 2014, 09:36:01 am »
EDIT :
J'ai trouvé. Button.cpp, ligne 34 : chkClicked=new sf::Thread(newFunc, parent);
Par contre, je ne vois pas en quoi j'ai donné trop d'arguments...

Bonjour,
Je suis bloqué sur une erreur que je ne comprends pas :
SFML-2.1\include\SFML\System\Thread.inl  ||  In instantiation of 'void sf::priv::ThreadFunctorWithArg<F, A>::run() [with F = void (*)(); A = MWindow*]':
Button.cpp  |145|  required from here
SFML-2.1\include\SFML\System\Thread.inl  |48|  error: too many arguments to function

MWindow.h :
#ifndef MWINDOW_H
#define MWINDOW_H


#include <SFML/Graphics.hpp>

#include <vector>


class MWindow;

class Button : public sf::Sprite
{
    friend class MWindow;
    public:
        Button(std::string const& adress, std::string const& adressO=std::string(), std::string const& adressL=std::string(), std::string const& adressD=std::string());

        virtual ~Button();

        bool setParent(MWindow *newParent = nullptr, void (*newFunc)() = nullptr);
        // Sets 'parent' to newParent. If newParent is null, the button is disabled and ID is set to -1. Else it is enabled.
        // Returns true if the parent has been successfully changed, else false.

        MWindow* getParent();
        // Returns 'parent' member.

        virtual void setEnabled(bool yay);
        // Sets the 'enabled' value to yay and changes de texture in consequences. An hidden button cannot be enabled.

        bool getEnabled();
        // Returns the 'enabled' member value

        virtual void setHidden(bool hide);
        // Sets the 'hidden' member to hide. If true, texture is set to 'texture', else to an empty texture.
        // An hidden button is also disabled. Unhidde a button automatically re-enables it.

        bool getHidden();
        // Returns the 'hidden' member value

        void changeTexture(std::string const& adress);
        // texture.loadFromFile(adress);

        void changeTextureOver(std::string const& adress=std::string());
        // Give it an empty string and  textureOver will be set with 'texture'
        void changeTextureLeaned(std::string const& adress=std::string());
        // Give it an empty string and  textureLeaned will be set with 'texture'
        void changeTextureDisabled(std::string const& adress=std::string());
        // Give it an empty string and  textureDisabled will be set with 'texture'

    protected:
        void checkClicked();
        // Uses the sf::Event event to verify if the mouse is over the button and if the user clicks on

        MWindow *parent;
        sf::Texture texture, textureOver, textureLeaned, textureDisabled;
        sf::Thread *chkClicked;
        bool enabled, mouseOver, leaned, hidden;
        int ID;
};



/////////////////////////////////////// MWindow ///////////////////////////////////////

class MWindow
{
    friend class Button;
    public:
        MWindow(int x = 800, int y = 600, std::string const& title = "Main Window", bool deletebuttons = true, sf::ContextSettings const& settings = sf::ContextSettings());
        /* Arguments :
         * 'title' is simply the title of the window.
         * 'deletebuttons' : if true, the buttons in the vector 'buttons' will be deleted in the destructor.
         * 'x' ans 'y' are respectively the width and the height of the window
        */


        MWindow(sf::RenderWindow *windowPtr, bool deletebuttons = true);

        virtual ~MWindow();

        virtual void startEventLoop();

        bool addButton(Button *button, void (*func)());
        // Returns true if the button is successfully added, false if the button was already in the window

        bool removeButton(Button *button);
        // Returns true if the button is successfully removed from the window, false if the button was not in the window.
        // Note that this function does NOT delete the button.

        bool removeButton(int index);
        // Overload of removeButton(). Remove the Button at the 'index' position. Return true if successful, false if the 'index' position does not exist.
    protected:
        virtual void update();
        // clear-draw-display function

        virtual void checkButtons();
        // checks if

        sf::RenderWindow *window;
        sf::Thread checkBtns;
        std::vector<Button*> buttons;
        std::vector<void (*)()> functions;
        bool deleteButtons;
        sf::Event event;
};

#endif // MWINDOW_H
 

MWindow.cpp :
#include "MWindow.h"

MWindow::MWindow(int x, int y, std::string const& title, bool deletebuttons, ContextSettings const& settings) : \
    window(new sf::RenderWindow(sf::VideoMode(x,y), title, sf::Style::Titlebar | sf::Style::Close, settings)), \
    checkBtns(&MWindow::checkButtons, this), buttons(), deleteButtons(deletebuttons)
{
    checkBtns.launch();
}

MWindow::MWindow(sf::RenderWindow *windowPtr, bool deletebuttons) : window(windowPtr), checkBtns(&MWindow::checkButtons, this), buttons(), deleteButtons(deletebuttons)
{
    checkBtns.launch();
}

MWindow::~MWindow()
{
    if(deleteButtons)
    {
        for(int i(0) ; i < (int)buttons.size() ; i++)
            delete buttons[i];
    }
    else
    {
        for(int i(0) ; i < (int)buttons.size() ; i++)
            if(buttons[i] != nullptr)
                buttons[i].ID=-1;
    }
}

MWindow& MWindow::operator=(const MWindow& rhs)
{
    if (this == &rhs) return *this; // handle self assignment
    //assignment operator
    return *this;
}

void MWindow::startEventLoop()
{
    while(window->isOpen())
    {
        update();
        while(window->pollEvent(event))
        {
            if(event.type == sf::Event::MouseButtonPressed || event.type == sf::Event::MouseButtonReleased || event.type == sf::Event::MouseMoved)
            {
                for(int i(0) ; i < (int)buttons.size() ; i++)
                    if(buttons[i] != nullptr && buttons[i]->getEnabled())
                        buttons[i]->checkClicked(event);
            }
        }
    }
}


bool MWindow::addButton(Button *button, void (*func)())
{
    for(int i(0) ; i < (int)buttons.size() ; i++)
        if(buttons[i] == button)
            return false;

    if(buttons.empty())
    {
        buttons.push_back(button);
        button->ID=0;
        functions.push_back(func);
        return;
    }
    for(int i(0) ; i < (int)buttons.size() ; i++)
    {
        if(buttons[i] == nullptr)
        {
            buttons[i]=button;
            button->ID=i;
            functions[i]=func;
        }
    }
    buttons.push_back(button);
    button->ID=buttons.size()-1;
    functions.push_back(func);
    return true;
}

bool MWindow::removeButton(Button *button)
{
    for(int i(0) ; i < (int)buttons.size() ; i++)
    {
        if(buttons[i] == button)
        {
            buttons[i]->setParent(nullptr);
            buttons[i] = nullptr;
            return true;
        }
    }
    return false;
}

bool MWindow::removeButton(int index)
{
    try
    {
        buttons.at(index)->setParent(nullptr);
        buttons.at(index) = nullptr;
    }
    catch (std::out_of_range const& exc) // My compiler (GCC 4.7.1) does not want of std::out_of_range or std::logic_error...why ?
    {
        return false;
    }
    return true;
}

void MWindow::update()
{
    window->clear();

    for(int i(0) ; i < (int)buttons.size(); i++)
        if(buttons[i]!=nullptr)
            window->draw(*buttons[i]);

    window->display();
}
 

Button.cpp :
#include "MWindow.h"

Button::Button(std::string const& adress, std::string const& adressO, std::string const& adressL, std::string const& adressD) : \
    parent(nullptr), texture(), textureOver(), textureLeaned(), textureDisabled(), chkClicked(new sf::Thread(&Button::checkClicked, this)), \
    enabled(false), mouseOver(false), leaned(false), hidden(false), ID(-1)
{
    changeTexture(adress);
    changeTextureOver(adressO);
    changeTextureLeaned(adressL);
    changeTextureDisabled(adressD);
}

Button::~Button()
{
    delete chkClicked;
}

bool Button::setParent(MWindow *newParent, void (*newFunc)())
{
    if(!newParent->addButton(this, newFunc))
        return false;

    delete chkClicked;
    parent=newParent;
    if(parent == nullptr || newFunc == nullptr)
    {
        setEnabled(false);
        ID=-1;
        return false;
    }
    else
    {
        setEnabled(true);
        chkClicked=new sf::Thread(newFunc, parent);
    }

    return true;
}

MWindow* Button::getParent()
{
    return parent;
}

void Button::setEnabled(bool yay)
{
    if((enabled && yay) || hidden)
    {
        return;
    }
    else if(yay)
    {
        enabled=true;
        chkClicked->launch();
    }
    else
    {
        enabled=false;
        setTexture(textureDisabled);
    }
}

bool Button::getEnabled()
{
    return enabled;
}

void Button::setHidden(bool hide)
{
    if(hide)
    {
        setEnabled(false);
        setTexture(sf::Texture());
        hidden=true;
    }
    else
    {
        hidden=false;
        setEnabled(true);
    }
}

bool Button::getHidden()
{
    return hidden;
}

void Button::changeTexture(std::string const& adress)
{
    texture.loadFromFile(adress);
}

void Button::changeTextureOver(std::string const& adress)
{
    textureOver.loadFromFile(adress);
}

void Button::changeTextureLeaned(std::string const& adress)
{
    textureLeaned.loadFromFile(adress);
}

void Button::changeTextureDisabled(std::string const& adress)
{
    textureDisabled.loadFromFile(adress);
}

void Button::checkClicked()
{
    while(enabled)
    {
        if(parent->event.type == sf::Event::MouseMoved)
        {
            if(getGlobalBounds().contains(sf::Vector2<float>(parent->event.mouseMove.x, parent->event.mouseMove.y)))
            {//if the mouse is in the button...
                mouseOver=true;
                setTexture(textureOver);
            }
            else
            {
                mouseOver=false;
                setTexture(texture);
            }
        }
        else if(parent->event.type == sf::Event::MouseButtonPressed && parent->event.mouseButton.button == sf::Mouse::Right && mouseOver)
        {
            leaned=true;
            setTexture(textureLeaned);
        }
        else if(parent->event.type == sf::Event::MouseButtonReleased && parent->event.mouseButton.button == sf::Mouse::Right && leaned)
        {
            if(getGlobalBounds().contains(sf::Vector2<float>(parent->event.mouseButton.x, parent->event.mouseButton.y)))
            {
                setTexture(textureOver);
                parent->functions[ID]();
            }
            else
            {
                setTexture(texture);
                mouseOver=false;
            }
            leaned=false;
        }
    }
} // In instantiation of 'void sf::priv::ThreadFunctorWithArg<F, A>::run() [with F = void (*)(); A = MWindow*]': required from here
 

Merci d'avance pour vos éclaircissements.

18
Système / [Résolu]Étrange erreur, le retour
« le: Septembre 21, 2014, 12:36:50 pm »
Excusez-moi, mais je ne comprends pas cette erreur :

Citer
\SFML\System\Thread.inl||In instantiation of 'void sf::priv::ThreadFunctorWithArg<F, A>::run() [with F = void (Button::*)(sf::Event); A = Button*]':|
\Button.cpp|94|required from here|
\SFML\System\Thread.inl|48|error: must use '.*' or '->*' to call pointer-to-member function in '((sf::priv::ThreadFunctorWithArg<void (Button::*)(sf::Event), Button*>*)this)->sf::priv::ThreadFunctorWithArg<void (Button::*)(sf::Event), Button*>::m_function (...)', e.g. '(... ->* ((sf::priv::ThreadFunctorWithArg<void (Button::*)(sf::Event), Button*>*)this)->sf::priv::ThreadFunctorWithArg<void (Button::*)(sf::Event), Button*>::m_function) (...)'|
Button.h
#ifndef BUTTON_H
#define BUTTON_H

class Button : public sf::Sprite
{
    public:
        Button(absWindow *wparent, void(absWindow::*function)(), std::string const& adress, std::string const& adressO=std::string(), std::string const& adressL=std::string());

        void setParent(absWindow *wparent, void(absWindow::*function)());
        absWindow* getParent();
        void setActive(bool yay);
        void changeTextures(std::string const& adress, std::string const& adressO=std::string(), std::string const& adressL=std::string());
        void checkClicked(sf::Event event);
    private:
        absWindow *parent;
        sf::Texture texture, textureOver, textureLeaned;
        sf::Thread *triggered, *ccd;
        bool mouseOver, active;
};

#endif //BUTTON_H

Button.cpp
#include "Button.h"

Button::Button(absWindow *wparent, void(absWindow::*function)(), std::string const& adress, std::string const& adressO, std::string const& adressL) : \
    parent(wparent), texture(), textureOver(), textureLeaned(), \
    triggered(new sf::Thread(function, wparent)), ccd(new sf::Thread(&Button::checkClicked, this)), mouseOver(false), active(true)
{
    changeTextures(adress, adressO, adressL);

    ccd->launch();
}

void Button::setActive(bool yay)
{
    if(active && yay)
    {
        return;
    }
    else if(yay)
    {
        active=true;
        ccd->launch();
    }
    else
    {
        active=false;
        setTexture(sf::Texture());
    }
}

void Button::setParent(absWindow *wparent, void(absWindow::*function)())
{
    active=false;
    parent=wparent;
    delete triggered;
    triggered=new sf::Thread(function, parent);
    active=true;
    ccd->launch();
}

absWindow* Button::getParent()
{
    return parent;
}

void Button::changeTextures(std::string const& adress, std::string const& adressO, std::string const& adressL)
{
    texture.loadFromFile(adress);
    if(adressO == std::string())
        textureOver.loadFromFile(adress);
    else
        textureOver.loadFromFile(adressO);

    if(adressL == std::string())
        textureLeaned.loadFromFile(adress);
    else
        textureLeaned.loadFromFile(adressL);
}

void Button::checkClicked(sf::Event event)
{
    if(active && event.type==sf::Event::MouseMoved)
    {
        if(getGlobalBounds().contains(sf::Vector2<float>(event.mouseMove.x, event.mouseMove.y)))
        {//if the mouse is in the button...
            mouseOver=true;
            setTexture(textureOver);
        }
        else
        {

        }
    }
}//required frop here
 

19
Système / [Résolu] Étrange erreur
« le: Septembre 18, 2014, 01:06:18 pm »
Bonjour,

En codant un petit jeu pour me familiariser avec la SFML, je me suis heurté à une étrange erreur concernant les threads, à la ligne 39 de 'Thread.inl' :
error: must use '.*' or '->*' to call pointer-to-member function in '((sf::priv::ThreadFunctor<void (Fenetre::*)()>*)this)->sf::priv::ThreadFunctor<void (Fenetre::*)()>::m_functor (...)', e.g. '(... ->* ((sf::priv::ThreadFunctor<void (Fenetre::*)()>*)this)->sf::priv::ThreadFunctor<void (Fenetre::*)()>::m_functor) (...)'|
(tellement long que je ne suis même pas sûr de l'avoir en entier...)

Voici le code :
main.cpp
#include "Fenetre"

#include <ctime>


int main()
{
    srand(time(0));

    Fenetre fenetre;


    return 0;
}

Piece.h
#ifndef PIECE_H
#define PIECE_H

#include <SFML/Graphics.hpp>
#include <cstdlib>


class Piece : public sf::Sprite
{
    public:
        Piece(int type=0);
        int getValue();
    private:
        int value;
        sf::Texture texture;
};

#endif // PIECE_H

Piece.cpp
#include "Piece.h"

Piece::Piece(int type) : value(0), Sprite()
{

    /*
    0 = pas de pièce
    1 = pièce de bronze (+1)
    2 = pièce d'argent (+3)
    3 = pièce d'or (+5)
    4 = pièce pif (résultat d'une pièce maudite ou bénie à 50/50)
    5 = pièce maudite (-3)
    6 = pièce bénie (+10)
    */
    switch(type)
    {
    case 1:
        texture.loadFromFile("pieceDbronze.png");
        value=1;
        break;
    case 2:
        texture.loadFromFile("peceDargent.png");
        value=3;
        break;
    case 3:
        texture.loadFromFile("pieceDor.png");
        value=5;
        break;
    case 4:
        texture.loadFromFile("piecepif.png");
        type=rand()%3; type+=4;
    case 5:
        texture.loadFromFile("piecemaudite.png");
        value=-3;
        break;
    case 6:
        texture.loadFromFile("piecebenie.png");
        value=10;
        break;
    default:
        return;
        break;
    }
    setTexture(texture);
}

int Piece::getValue()
{
    return value;
}

Fenetre.h
#ifndef FENETRE_H
#define FENETRE_H


#include "GTexture.h"
#include "Piece.h"


class Fenetre
{
    public:
        Fenetre();
        virtual ~Fenetre();
    protected:
        void update();
        void deplacements();
        int typePiece();
        void jump();
        void pieces();
    private:
        GTexture lapin, fond, pieceDbronze, pieceDargent, pieceDor, piecepif, piecemaudite, piecebenie;
        sf::Sprite spLapin, spFond;

        sf::Thread dpl, pcs, jmp;

        bool jeuEnCours;
        bool jumping, droite, gauche;
        sf::RenderWindow window;
        std::vector<sf::Drawable*> entities;
};

#endif // FENETRE_H

Fenetre.cpp
#include "Fenetre.h"



Fenetre::Fenetre() :lapin("resources/pain.png"), fond("resources/fond.png"), pieceDbronze("resources/pieceDbronze.png"), pieceDargent("resources/pieceDargent.png"), \
                    pieceDor("resources/pieceDor.png"), piecepif("resources/piecepif.png"), piecemaudite("resources/piecemaudite.png"), piecebenie("resources/piecebenie.png"),\
                    spLapin(lapin), spFond(fond), \
                    dpl(&Fenetre::deplacements), pcs(&Fenetre::pieces), jmp(&Fenetre::jump), \
                    jeuEnCours(false), jumping(false), droite(false), gauche(false), \
                    window(sf::VideoMode(800, 600), "Rabbits like coins", sf::Style::Titlebar | sf::Style::Close)

{
    entities.push_back(&spFond);
    entities.push_back(&spLapin);
    spLapin.setPosition(400,545);
    spLapin.setOrigin(25, 25);
    update();

    dpl.launch();

    sf::Event event;

    while (window.isOpen())
    {
        if(gauche && droite)
            {}
        else if(gauche)
            spLapin.setScale(-1, 1);
        else if(droite)
            spLapin.setScale(1, 1);

        update();
        // on inspecte tous les évènements de la fenêtre qui ont été émis depuis la précédente itération
        while (window.pollEvent(event))
        {
            // évènement "fermeture demandée" : on ferme la fenêtre
            if (event.type == sf::Event::Closed)
            {
                jeuEnCours=false;
                window.close();
            }
            else if (event.type == sf::Event::KeyPressed)
            {
                switch(event.key.code)
                {
                case sf::Keyboard::Left:
                    gauche=true;
                    break;
                case sf::Keyboard::Right:
                    droite=true;
                    break;
                case sf::Keyboard::Up:
                    if(jumping)
                        jumping=false;
                    jmp.launch();
                default:
                    update();
                    break;
                }
            }
            else if (event.type == sf::Event::KeyReleased)
            {
                if(event.key.code == sf::Keyboard::Left)
                    gauche=false;
                if(event.key.code == sf::Keyboard::Right)
                    droite=false;
                break;
            }
        }
    }
}

Fenetre::~Fenetre()
{
    //dtor
}

void Fenetre::deplacements()
{
    while(jeuEnCours)
    {
        //std::this_thread::sleep_for(std::chrono::milliseconds(5));
        if(droite && gauche)
        return;

        if(droite && spLapin.getPosition().x < 825)
        {
            spLapin.move(1,0);
            if(spLapin.getPosition().x >= 824)
                spLapin.setPosition(-25, spLapin.getPosition().y);
        }

        if(gauche && spLapin.getPosition().x > -25)
        {
            spLapin.move(-1,0);
            if(spLapin.getPosition().x <= -24)
                spLapin.setPosition(825, spLapin.getPosition().y);
        }
    }
}

void Fenetre::update()
{
    window.clear();
    for(int i=0;i<(int)entities.size();i++)
        if(entities[i] != nullptr)
            window.draw(*entities[i]);
    window.display();
}

int Fenetre::typePiece()
{
    /*
    0 = pas de pièce (5%)
    1 = pièce de bronze (40%)
    2 = pièce d'argent (20%)
    3 = pièce d'or (10%)
    4 = pièce pif (27%)
    5 = pièce maudite (18%)
    6 = pièce bénie (10%)
    */
    int nb(rand() % 100);
    if(nb<70)
    {
        if(nb<40)
            return 1;
        else if(nb<20)
            return 2;
        else
            return 3;
    }
    else if(nb<95)
    {
        if(nb<67)
            return 4;
        else if(nb<85)
            return 5;
        else
            return 6;
    }
    else
        return 0;
}


//threads
void Fenetre::jump()
{
    jumping=true;
    int i(0);
    for(i=1;i<100;i++)
    {
        if(spLapin.getPosition().y>0)
        {
            if(!jumping)
                return;
            spLapin.move(0,-1);
            sf::sleep(sf::milliseconds(i/10));;
        }
    }

    i=1;
    while(spLapin.getPosition().y<545)
    {
        if(i<100)
            i++;
        if(!jumping)
            return;
        spLapin.move(0,1);
        sf::sleep(sf::milliseconds(100/i));
    }

    jumping=false;
}

void Fenetre::pieces()
{
    int intervalle(50),type(0);
    while(jeuEnCours)
    {
        sf::sleep(sf::milliseconds(intervalle*10));
        type=typePiece();

        if(type!=0)
        {
            Piece *piece(new Piece(type));
            piece->setPosition((rand() % 800), (rand() % 600));
            entities.push_back(piece);
        }
        if (intervalle > 1)
            intervalle--;
    }
}


Toutes les infos potentiellement utiles :
OS : Windows 8.1
IDE : Code::Blocks 13.12
Compilateur : GCC 4.7.1

20
Général / [Résolu] Erreur insensée
« le: Septembre 17, 2014, 09:30:36 am »
Bonjour,

Sur ce fichier, j'ai une "fatal error : no such file or directory" à la ligne 5 (#include <SFML/Graphics.hpp>) alors que cette ligne  ne pose aucun problème dans les autres fichiers...
#ifndef GLOBAL_H_INCLUDED
#define GLOBAL_H_INCLUDED

#include <vector>
#include <SFML/Graphics.hpp> //ici, ça veut pas.


sf::Sprite spLapin, spFond;
bool jeuEnCours(false);
bool gameGo(true),jumping(false);
bool droite(false), gauche(false);

std::vector<sf::Drawable*> entities;

sf::RenderWindow window(sf::VideoMode(800, 600), "Rabbits like coins", sf::Style::Titlebar | sf::Style::Close);


#endif // GLOBAL_H_INCLUDED

Quelqu'un aurait une explication ? Est-ce que c'est parce que j'essaie de déclarer des variables globales dans un header ? Merci d'avance.

(la question n'est d'ailleurs pas de savoir si les variable globales sont une bonne idée ou non mais bien de "pourquoi j'ai une erreur", merci)

Compilo : GCC 4.7.1
IDE : Code::Blocks 13.12

21
Bonjour,

J'ai récemment installé SFML et configuré Code::Blocks pour l'utiliser. Oh, tout fonctionne parfaitement bien. Seulement, je reçois à chaque compilation toute une flopée d'avertissements (warnings) qui viennent des fichiers de la SFML.



C'est plutôt gênant pour voir les problèmes qui viennent de mon code...et on est d'accord que je ne vais pas juste désactiver ces messages pour être tranquille ! (en plus j'ai essayé de désactiver les message de Weffc++, ça n'a rien changé)
Alors par exemple certains messages parlent de destructeurs non virtuels. Je pourrais modifier le code de la SFML mais je préfère ne pas m'y risquer...Et puis, pour la majorité, il est question d'un problème avec des pointeurs membres ; je ne comprend même pas ce que disent ceux-ci, d'ailleurs.

Si quelqu'un a une solution...Merci d'avance de me la donner.

Pages: « Précédente 1 [2]
anything