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 - guiguithebest

Pages: [1]
1
General discussions / SFML GUI
« on: July 20, 2011, 08:46:22 pm »
Hey everyone, I'm trying to make a GUI with sfml, but I have a problem. When I put the mouse on the sprite I use as button, it should turn green. But the sprite's position is only one point. So how can I get the whole sprite's position? Is there a function for this?

2
SFML projects / My 1st project xD
« on: July 04, 2011, 04:29:12 am »
Ok I will thanx ;)

3
SFML projects / My 1st project xD
« on: June 15, 2011, 09:44:26 pm »
humm how do you do that?  :lol:

4
SFML projects / My 1st project xD
« on: June 12, 2011, 03:23:33 pm »
Oh sorry I forgot  :lol:

The first image is landed.png , attere in the code;
the second image is spaceship.png, vaisseau in the code;
the third image is stars.png, background in the code.

http://www.myimages.comxa.com/

5
SFML projects / My 1st project xD
« on: June 11, 2011, 10:59:38 pm »
So here is my first "real" SFML project. Nothing really incredible  :lol: Now I need to figure out how to make the ship shoot stuff :)
PS The code is half french half english, sorry about that. And the code is probably messy  
Code: [Select]
#include <cstdlib>
#include <SFML/Graphics.hpp>
#include <iostream>
#define HAUTEURECRAN 576
#define LARGEURECRAN 776

using namespace sf;
using namespace std;

int main()
{
    RenderWindow app(VideoMode(800, 600, 32), "Jeu 2");

    Image vaisseau;
    Sprite spaceship;

    Image background;
    Sprite fond;

    Image atterre;

    if(!vaisseau.LoadFromFile("spaceship.png"))
    {
        cout<<"Error while loading image"<<endl;
        return EXIT_FAILURE;
    }
    else
    {
        vaisseau.CreateMaskFromColor(Color(168, 230, 29));
    }
    if(!atterre.LoadFromFile("landed.png"))
    {
        cout<<"Error while loading image"<<endl;
        return EXIT_FAILURE;
    }
    else
    {
        atterre.CreateMaskFromColor(Color(168, 230, 29));
    }
    if(!background.LoadFromFile("stars.png"))
    {
        cout<<"Error while loading image"<<endl;
        return EXIT_FAILURE;
    }
    else
    {
        fond.SetImage(background);
    }

    spaceship.SetPosition(400, 300);
    spaceship.SetCenter(24, 24);

//---------------------------------------------------------------------------------------------

    bool showFlying = false;

//-------------------------------------------------------------------------------------------
    // Boucle principale
     while (app.IsOpened())
    {
        Event event;
        while (app.GetEvent(event))
        {
            switch (event.Type) // Type de l'évènement en attente :
            {
                case Event::Closed : // Croix en haut à droite
                    app.Close();
                    break;

                case Event::KeyPressed : // Appui sur une touche du clavier
                {
                    switch (event.Key.Code)
                    {
                        case Key::Escape : // Appui sur la touche echap
                            app.Close();
                            break;

                        default :
                            break;
                    }
                }

                break;

                default :
                break;
            }
            // Fenêtre fermée : on quitte
            if (event.Type == Event::Closed)
                app.Close();
        }
//--------------------------------------------------------------------------------------------
        if(app.GetInput().IsKeyDown(Key::Up))
        {
            spaceship.Move(cos(spaceship.GetRotation()*3.14159265/180)*1, sin(spaceship.GetRotation()*3.14159265/180)*-1);
        }

        if(app.GetInput().IsKeyDown(Key::Down))
        {
            spaceship.Move(cos(spaceship.GetRotation()*3.14159265/180)*-1, sin(spaceship.GetRotation()*3.14159265/180)*1);
        }

        if(app.GetInput().IsKeyDown(Key::Left))
        {
            spaceship.Rotate(1);
        }

        if(app.GetInput().IsKeyDown(Key::Right))
        {
            spaceship.Rotate(-1);
        }
        if((app.GetInput().IsKeyDown(Key::Up)) || (app.GetInput().IsKeyDown(Key::Down)) || (app.GetInput().IsKeyDown(Key::Left)) || (app.GetInput().IsKeyDown(Key::Right)) )
        {
            showFlying = true;
        }
        else
        {
            showFlying = false;
        }
//---------------------------------------------------------------------------------------
         Vector2f PosPerso = spaceship.GetPosition();
        if(PosPerso.x<16)
        {
            PosPerso.x=16;
            spaceship.SetPosition(PosPerso.x, PosPerso.y);
        }

        if(PosPerso.y<16)
        {
            PosPerso.y=16;
            spaceship.SetPosition(PosPerso.x, PosPerso.y);
        }

        if(PosPerso.x>(LARGEURECRAN))
        {
            PosPerso.x=LARGEURECRAN;
            spaceship.SetPosition(PosPerso.x, PosPerso.y);
        }

        if(PosPerso.y>(HAUTEURECRAN))
        {
            PosPerso.y=HAUTEURECRAN;
            spaceship.SetPosition(PosPerso.x, PosPerso.y);
        }

//----------------------------------------------------------------------------

        if(showFlying == true)
        {
            spaceship.SetImage(vaisseau);
        }
        else
        {
            spaceship.SetImage(atterre);
        }

//----------------------------------------------------------------
        // Remplissage de l'écran (couleur noire par défaut)
        app.Clear();
        app.Draw(fond);
        app.Draw(spaceship);

        app.Display();
    }
    return EXIT_SUCCESS;
}

6
Graphics / sprite moving out of view!!
« on: May 30, 2011, 08:10:01 pm »
Hi, I had the same problem and what devlin said helped a lot, thank you. But I don't know if I have to check the coordinate while I'm pressing the key, or somewhere else, so can anyone tell me? Thank you.

Pages: [1]