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.


Topics - Yemeni Cpluspluser

Pages: [1]
1
Hello, I am still creating the main game window, I have done creating the click system for new game button, but It does not feels that its a nice method, stick to this method? or there is a better method?

The .exe file with the resource :
http://www.mediafire.com/?bqaskzv951c2bbx 2.6MB

this is the target :
    if( sf::Mouse::isButtonPressed(sf::Mouse::Left)
       && sf::Mouse::getPosition(mainWindow).x >= 12
       && sf::Mouse::getPosition(mainWindow).y >=150
       && sf::Mouse::getPosition(mainWindow).x <= 270
       && sf::Mouse::getPosition(mainWindow).y <= 190
       )

        std::cout << "Clicking on new game";

This is the whole code so far :
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <iostream>
#include <random>
#include <cstdlib>

int  main()
{
    srand( time(0));
    size_t R, G, B;
    std::cout << "This is the brain of the game, don't think of closing it\nPlease wait the game is loading . . . " << std::endl;
    // declare mainWindow
    sf::RenderWindow mainWindow( sf::VideoMode( 800, 600, 32) , "Hello title" , sf::Style::Close ); // Declare of mainWindow
    mainWindow.setFramerateLimit( 60 );
    std::cout << "Game resolution is : " << mainWindow.getSize().x  << " X " << mainWindow.getSize().y
              << " bits : " << mainWindow.getSettings().depthBits + mainWindow.getSettings().stencilBits << std::endl
              << "Frame per second : 60" << std::endl;
    // declared mainWidow

    // load images into ram
    sf::Image img_SpaceShip;
    if( !img_SpaceShip.loadFromFile( "Resource/img_ship.png" ) )
       std::cout << "Error LFF : Failed to load Resource/img_ship.png" << std::endl;
    else std::cout << "Resource/img_ship.png successfully loaded" << std::endl;

    sf::Texture img_button;
    if ( !img_button.loadFromFile( "Resource/img_button.png" ) )
        std::cout << "Error LFF : Failed to load  Resource/img_button.png" << std::endl;
    else std::cout << "Resource/img_button.png successfully loaded" << std::endl;

    // load sound and music into ram
    sf::Music msnd_intro;
    if( !msnd_intro.openFromFile( "Resource/msnd_intro.ogg") )
        std::cout << "Error OFF : Failed to load Resource/msnd_intro.ogg" << std::endl;
    else std::cout << "Resource/msnd_intro.ogg successfully loaded" << std::endl;
    msnd_intro.setLoop( true );
    msnd_intro.play();

    // loads fonts
    sf::Font font_English;
    if (!font_English.loadFromFile( "Resource/font_English.ttf" ) )
        std::cout << "Error LFF : Failed to load Resource/font_English.ttf" << std::endl;
    else std::cout << "Resource/font_English.ttf successfully loaded" << std::endl;

    // every thing should be loaded

    // declarations

    sf::Text text_MainWindowText ( "SpaceShips 0.01 Alfa", font_English);
    text_MainWindowText.setCharacterSize( 40 );
    text_MainWindowText.setColor( sf::Color::Blue );
    text_MainWindowText.setPosition( 200 , 30 );

    sf::Text text_MainWindowNewGame ( "New Game", font_English);
    text_MainWindowNewGame.setCharacterSize( 30 );
    text_MainWindowNewGame.setColor( sf::Color::Green );
    text_MainWindowNewGame.setPosition( 60 , 150 );

    sf::Text text_MainWindowExit ( "Exit Game", font_English );
    text_MainWindowExit.setCharacterSize( 30 );
    text_MainWindowExit.setColor( sf::Color::Red );
    text_MainWindowExit.setPosition( 60, 200 );

    sf::Sprite spr_ButtonNewGame;
    spr_ButtonNewGame.setTexture( img_button );
    spr_ButtonNewGame.setPosition( 0 , 150 );
    spr_ButtonNewGame.setScale( 1.8 , 1 );

    sf::Sprite spr_ButtonExitGame;
    spr_ButtonExitGame.setTexture( img_button );
    spr_ButtonExitGame.setPosition( 0 , 200 );
    spr_ButtonExitGame.setScale( 1.8 , 1 );

    sf::Sprite spr_SpaceShip;



    // the main game loop
    while ( mainWindow.isOpen() ) // main game loop
    {
        sf::Event mainEvents; // declare of main events checker
        while ( mainWindow.pollEvent( mainEvents ) ); // checking
        {
            switch ( mainEvents.type ) // what event type
            {
            case sf::Event::EventType::Closed: // users clicks X or press Alt-F4
                mainWindow.close(); // close the window
                break;
            }
        }
    // main loop :
    mainWindow.clear( sf::Color( 11,11,11) );
    mainWindow.draw( spr_ButtonNewGame );
    mainWindow.draw( spr_ButtonExitGame );
    mainWindow.draw( text_MainWindowText );

    if( sf::Mouse::isButtonPressed(sf::Mouse::Left)
       && sf::Mouse::getPosition(mainWindow).x >= 12
       && sf::Mouse::getPosition(mainWindow).y >=150
       && sf::Mouse::getPosition(mainWindow).x <= 270
       && sf::Mouse::getPosition(mainWindow).y <= 190
       )

        std::cout << "Clicking on new game";

    R = rand() % 255;
    G = rand() % 255;
    B = rand() % 255;

    text_MainWindowText.setColor( sf::Color ( R, G, B ) );
    mainWindow.draw( text_MainWindowNewGame );
    mainWindow.draw( text_MainWindowExit );
    mainWindow.display();
    //std::cout << sf::Mouse::getPosition(mainWindow).x << " " << sf::Mouse::getPosition(mainWindow).y << std::endl;

    }
    return EXIT_SUCCESS; // returns 0;
}
 

2
Graphics / [Solved]sf::Texture texture;
« on: July 31, 2013, 10:20:11 pm »
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <iostream>

int  main()
{
    std::cout << "This is the brain of the game, don't think of closing it\nPlease wait the game is loading . . . " << std::endl;
    // declare mainWindow
    sf::RenderWindow mainWindow( sf::VideoMode( 800, 600, 32) , "Hello title" , sf::Style::Close ); // Declare of mainWindow
    std::cout << "Game resolution is : " << mainWindow.getSize().x  << " X " << mainWindow.getSize().y
              << " bits : " << mainWindow.getSettings().depthBits + mainWindow.getSettings().stencilBits << std::endl;
    // declared mainWidow

    // load images into ram
    sf::Image img_SpaceShip;
    if( !img_SpaceShip.loadFromFile( "Resource/img_ship.png" ) )
       std::cout << "Error LFF : Failed to load Resource/img_ship.png" << std::endl;
    else std::cout << "Resource/img_ship.png successfully loaded" << std::endl;

    sf::Texture img_button;
    if ( !img_button.loadFromFile( "Resource/img_button.png" ) )
        std::cout << "Error LFF : Failed to load  Resource/img_button.png" << std::endl;
    else std::cout << "Resource/img_button.png successfully loaded" << std::endl;

    sf::Texture img_button2;
    if ( !img_button2.loadFromFile( "Resource/img_button2.png" ) )
        std::cout << "Error LFF : Failed to load  Resource/img_button2.png" << std::endl;
    else std::cout << "Resource/img_button2.png successfully loaded" << std::endl;

    // load sound and music into ram
    sf::Music msnd_intro;
    if( !msnd_intro.openFromFile( "Resource/msnd_intro.ogg") )
        std::cout << "Error OFF : Failed to load Resource/msnd_intro.ogg" << std::endl;
    else std::cout << "Resource/msnd_intro.ogg successfully loaded" << std::endl;
    msnd_intro.setLoop( true );
    msnd_intro.play();

    // loads fonts
    sf::Font font_English;
    if (!font_English.loadFromFile( "Resource/font_English.ttf" ) )
        std::cout << "Error LFF : Failed to load Resource/font_English.ttf" << std::endl;
    else std::cout << "Resource/font_English.ttf successfully loaded" << std::endl;

    // every thing should be loaded

    // declarations

    sf::Text text_MainWindowText ( "SpaceShips 0.01 Alfa", font_English);
    text_MainWindowText.setCharacterSize( 40 );
    text_MainWindowText.setColor( sf::Color::Blue );
    text_MainWindowText.setPosition( 200 , 30 );

    sf::Text text_MainWindowNewGame ( "New Game", font_English);
    text_MainWindowNewGame.setCharacterSize( 30 );
    text_MainWindowNewGame.setColor( sf::Color::Green );
    text_MainWindowNewGame.setPosition( 60 , 150 );

    sf::Text text_MainWindowExit ( "Exit Game", font_English );
    text_MainWindowExit.setCharacterSize( 30 );
    text_MainWindowExit.setColor( sf::Color::Red );
    text_MainWindowExit.setPosition( 60, 200 );

    sf::Sprite spr_ButtonNewGame;
    spr_ButtonNewGame.setTexture( img_button );
    spr_ButtonNewGame.setPosition( 0 , 150 );
    spr_ButtonNewGame.setScale( 1.8 , 1 );

    sf::Sprite spr_buttonExitGame;
    spr_ButtonNewGame.setTexture( img_button2 );
    spr_ButtonNewGame.setPosition( 0 , 200 );
    spr_ButtonNewGame.setScale( 1.8 , 1 );



    // the main game loop
    while ( mainWindow.isOpen() ) // main game loop
    {
        sf::Event mainEvents; // declare of main events checker
        while ( mainWindow.pollEvent( mainEvents ) ); // checking
        {
            switch ( mainEvents.type ) // what event type
            {
            case sf::Event::EventType::Closed: // users clicks X or press Alt-F4
                mainWindow.close(); // close the window
                break;
            }
        }
    // main loop :
    mainWindow.clear( sf::Color( 11,11,11) );
    mainWindow.draw( spr_ButtonNewGame );
    mainWindow.draw( spr_buttonExitGame );
    mainWindow.draw( text_MainWindowText );
    mainWindow.draw( text_MainWindowNewGame );
    mainWindow.draw( text_MainWindowExit );
    mainWindow.display();
    }
    return EXIT_SUCCESS; // returns 0;
}
 

I tried making one texture for 2 sprites failed
then made 2 textures for 2 sprites failed

the problem is that it can only display one sprite at a time, I don't know why.


the difference from sf::Image and sf::Texture it says that that for memory and that for graphics card
so is it because I use sf::texture instead of sf::Image?



don't be hard on me, this is my first project  :P .

3
Window / Code::Blocks window sf::style::()
« on: July 30, 2013, 06:44:33 pm »
When I type it it works, such as Fullscreen, Titlebar, and other sf::style attributes
but some time I mistake in spelling, why it won't show up as in the video tutorials I saw? it just shows unnamed
as you can see in the tutorial it shows a list of the enumeration, while in my image just unnamed

or I should post this in the code::blocks forum?

Pages: [1]