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

Author Topic: Frustrations  (Read 2351 times)

0 Members and 1 Guest are viewing this topic.

wvtrammell

  • Jr. Member
  • **
  • Posts: 70
    • View Profile
Frustrations
« on: June 27, 2013, 05:43:32 pm »
 

   I wrote  my first program on a yellow pad just over 61 years ago.  If I remember correctly it was called Fortran 4.  A key punch operator took the sheets and returned shortly with a deck of cards with holes punched in them.  She called the deck a source deck.  I fed them into a card reader connected to an IBM mainframe.  It responded by punching me a new deck called an object deck.  I combined this deck with a bunch of other decks called library decks  and fed them into the same card reader.  This time I received a deck called an executable deck.  Using my yellow pad again I listed all the input data and received another deck called input deck.  Placing this on the front of my executable deck I once again approached the card reader.  After entering this deck, I received a printout of  rows and columns of digits representing the flight performance of the engine and airplane our company was developing for the military, 
   A couple of years ago, I decided to try my hand at programming again.  I purchased a couple of books on C++ and downloaded some stuff called Allegro.
With the list of reserved words (as they were called) and the description of what they did and the examples, I was able to get a program up and running that filled the screen with random colored pixels and then set back and watch as it did a bubble sort, bubbling the lighter colors to the left upper corner and the darker to the lower right corner.  My great grandchildren loved watching this program,  But my computer died of old age  so I replaced it.  The new one had an Intel processor and a new OS so my bubble program would no longer function.
Then I saw on the internet  Simple and Fast Multimedia Library.  The kids liked the Hanoi's Tower game so I decided to give it a shot.   
   I read the tutorials, the documentation, and the forum pages but could not find any indication of reserved words or their function.  So after many weeks of frustrated try and fail I finally arrived at the enclosed.  Not good but is appears to work.

// tower of hanoi
// June 21st, 2013
// Yours truly

#include <SFML/Graphics.hpp>


int main()
{
    // Create the main window
    sf::RenderWindow window(sf::VideoMode(2200, 1300), "SFML window");
   
    window.clear(sf::Color(128,128,128));
   
    sf::RectangleShape rect1(sf::Vector2f(300,150));
    rect1.setFillColor(sf::Color(255,0,0));
    rect1.setPosition(200,550);
    window.draw(rect1);
    sf::RectangleShape rect2(sf::Vector2f(400,150));
    rect2.setFillColor(sf::Color(255,255,255));
    rect2.setPosition(150,700);
    window.draw(rect2);
    sf::RectangleShape rect3(sf::Vector2f(500,150));
    rect3.setFillColor(sf::Color(0,0,255));
    rect3.setPosition(100,850);
    sf::RectangleShape rect4(sf::Vector2f(50,600));
    rect4.setFillColor(sf::Color(0,0,0));
    rect4.setPosition(325,400);
    sf::RectangleShape rect5(sf::Vector2f(50,600));
    rect5.setFillColor(sf::Color(0,0,0));
    rect5.setPosition(1075,400);
    sf::RectangleShape rect6(sf::Vector2f(50,600));
    rect6.setFillColor(sf::Color(0,0,0));
    rect6.setPosition(1825,400);
    sf::RectangleShape rect7(sf::Vector2f(2200,300));
    rect7.setFillColor(sf::Color(139,68,19));
    rect7.setPosition(0,1000);
   
    window.draw(rect1);
    window.draw(rect2);
    window.draw(rect3);
    window.draw(rect4);
    window.draw(rect5);
    window.draw(rect6);
    window.draw(rect7);
    window.display();
   
    // Start the game loop
    while (window.isOpen())
    {
        // Process events
        sf::Event event;
        while (window.pollEvent(event))
        {
            // Close window : exit
            if (event.type == sf::Event::Closed)
            {
                window.close();
            }
           
            // Escape pressed : exit
            if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape)
            {
                window.close();
            }
         
            if ((event.type == sf::Event::MouseMoved) &&  (sf::Mouse::isButtonPressed(sf::Mouse::Button::Left))
                && (sf::Mouse::getPosition(window).x > rect1.getPosition().x - 50)
                && (sf::Mouse::getPosition(window).x < rect1.getPosition().x + 50)
                && (sf::Mouse::getPosition(window).y > rect1.getPosition().y - 50)
                && (sf::Mouse::getPosition(window).y < rect1.getPosition().y + 50))
               
            {
                rect1.setPosition(event.mouseMove.x,event.mouseMove.y);
            }
           
            if ((event.type == sf::Event::MouseMoved) &&  (sf::Mouse::isButtonPressed(sf::Mouse::Button::Left))
                && (sf::Mouse::getPosition(window).x > rect2.getPosition().x - 50)
                && (sf::Mouse::getPosition(window).x < rect2.getPosition().x + 50)
                && (sf::Mouse::getPosition(window).y > rect2.getPosition().y - 50)
                && (sf::Mouse::getPosition(window).y < rect2.getPosition().y + 50))
               
            {
                rect2.setPosition(event.mouseMove.x,event.mouseMove.y);
            }
           
            if ((event.type == sf::Event::MouseMoved) &&  (sf::Mouse::isButtonPressed(sf::Mouse::Button::Left))
                && (sf::Mouse::getPosition(window).x > rect3.getPosition().x - 50)
                && (sf::Mouse::getPosition(window).x < rect3.getPosition().x + 50)
                && (sf::Mouse::getPosition(window).y > rect3.getPosition().y - 50)
                && (sf::Mouse::getPosition(window).y < rect3.getPosition().y + 50))
               
            {
                rect3.setPosition(event.mouseMove.x,event.mouseMove.y);
            }
           
        }
     
        window.clear(sf::Color(128,128,128));
        window.draw(rect1);
        window.draw(rect2);
        window.draw(rect3);
        window.draw(rect4);
        window.draw(rect5);
        window.draw(rect6);
        window.draw(rect7);
        window.display();
   
       
       
    }
   
    return EXIT_SUCCESS;
   
}

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Frustrations
« Reply #1 on: June 27, 2013, 06:09:19 pm »
It looks good, glad you finally understood some things. I don't see any of the common pitfalls ;)

Apparently you still don't understand the [ code=cpp ] forum tag. All you need to do is surround your code like this.

[ code=cpp ] //Code goes here//

// tower of hanoi
// June 21st, 2013
// Yours truly

#include <SFML/Graphics.hpp>


int main()
{
........[ /code ]

Put those tags around your code and then remove the spaces from inside the brackets ("[" & "]") and you should be good. Note how it looks with out spaces.

// tower of hanoi
// June 21st, 2013
// Yours truly

#include <SFML/Graphics.hpp>


int main()
{
« Last Edit: June 27, 2013, 06:14:03 pm by zsbzsb »
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor