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

Author Topic: Lethn's Programming Questions Thread  (Read 61765 times)

0 Members and 1 Guest are viewing this topic.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Lethn's Programming Questions Thread
« Reply #60 on: July 21, 2013, 09:07:10 pm »
C++ Primer Plus has indeed not  a very good review. As opposed to the C++ Primer, which is among the most often recommended beginner books.

See also: The Definitive C++ Book Guide and List
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Lethn

  • Full Member
  • ***
  • Posts: 133
    • View Profile
Re: Lethn's Programming Questions Thread
« Reply #61 on: July 21, 2013, 09:11:18 pm »
I've been confused! I'll have a look at other books then and see if that helps, probably will, I already have that thread bookmarked :D

Edit 1: This certainly looks a lot better, it's explaining things that the 6th edition missed out

Edit 2: I did get a PM from hatchet about vocabulary but

Quote
A condition is an expression that yields a result
that is either true or false.

YEYYYYYYYYYYYYYYYYYYYYYYYY!!!!!! That's exactly the kind of information I need.
« Last Edit: July 21, 2013, 09:31:34 pm by Lethn »

Lethn

  • Full Member
  • ***
  • Posts: 133
    • View Profile
Re: Lethn's Programming Questions Thread
« Reply #62 on: July 24, 2013, 02:48:03 pm »
I just had an idea and I wanted to know whether it would work or not, what's stopping me from just using sf::Time and displaying my stuff that way? Are there restrictions to how it works or could I quite happily implement my C++ programs using seconds etc. as far as I can work out I don't know why not but that's why I'm asking you guys.

sf::Time etc. just seems like it would be a lot more flexible way of doing things rather than messing around trying to figure out ways to get incrementing working and I could get the same sort of effects I want.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Lethn's Programming Questions Thread
« Reply #63 on: July 24, 2013, 02:50:03 pm »
what's stopping me from just using sf::Time and displaying my stuff that way?
What are you talking about? sf::Time stores a time, nothing else. It can't replace all the C++ logic you need in your program ???
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Lethn

  • Full Member
  • ***
  • Posts: 133
    • View Profile
Re: Lethn's Programming Questions Thread
« Reply #64 on: July 24, 2013, 03:06:38 pm »
If I'm thinking of the wrong command then sorry about that, but what I mean is using seconds, milliseconds etc. instead so I can get a counter properly working because so far the only C++ I've found does all the stuff instantly and incrementing just seems to do it in 1's from what I can make out.

hmm >_< need to do m0ar reading.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Lethn's Programming Questions Thread
« Reply #65 on: July 24, 2013, 04:29:47 pm »
You need to explain what you want more precisely. Measuring time and counting in discrete steps are two completely different problems.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Lethn

  • Full Member
  • ***
  • Posts: 133
    • View Profile
Re: Lethn's Programming Questions Thread
« Reply #66 on: July 24, 2013, 05:12:19 pm »
In that case looks like I can't use that idea, what I've been trying to do is to limit or change the incrementing in some way, I thought the while loop was the way to do it but the code etc. I've seen only deal in very basic methods.

The best example I can give is through a youtube clip of a game called Startopia, take a look at the energy meter on the top left ( a bit blurry I know ), that's what I'm aiming for and I guess it's my main project at the moment.



. Updating numbers

. Limited

. Changes according to pressing a key/mousebutton etc.

. Bonus: getting a bar similar to the one in this video, but I'm focused on just getting the numbers part right for now :D

I have no problems getting these things to work immediately when it just flat out compiles the stuff I write, the problem is making it all happen while it's on the screen like in the video, I'm sure there's a proper programming word for it but the only thing I can think of is just updating integers on the screen.

This is why I thought of using the seconds and milliseconds in SFML but if that's not possible then I've got to keep reading again.

The Hatchet

  • Full Member
  • ***
  • Posts: 135
    • View Profile
    • Email
Re: Lethn's Programming Questions Thread
« Reply #67 on: July 24, 2013, 09:04:59 pm »
From what you are describing  (and i looked at the vid just to make sure), you should already have all the knowledge you need to achieve a number counter on the screen.  The basics of having a high score/energy counter/hit point/ammo counter only consists of what you've already done.  All you need is:

-Know how to draw to the screen (drawing to screen with text)
-Store the number in a variable (using integers because decimal points aren't needed for whole numbers)
-Update that stored number

I'm not quite sure what magic function you are hoping to find in your reading.  Programming is about having all these super basic building blocks and then implementing your own ideas and function with them to do what you want.

Like i said before, i usually have a bunch of free time so if you PM me I could become a sort of tutor for you.  I could write up some simple programs and examples to do whatever ideas you want and make sure are doable then give you some tips and knowledge how to do them and grade your programs against mine.

Lethn

  • Full Member
  • ***
  • Posts: 133
    • View Profile
Re: Lethn's Programming Questions Thread
« Reply #68 on: July 24, 2013, 09:47:05 pm »
Thanks Hatchet, you pretty much answered that question, I just couldn't phrase it properly, so it looks like I need to go and look at how to update the numbers I have in my code in that case, time for some reading.

I do already know how to do most of the stuff like I said, it's just getting the damn numbers to update themselves now :D

The Hatchet

  • Full Member
  • ***
  • Posts: 135
    • View Profile
    • Email
Re: Lethn's Programming Questions Thread
« Reply #69 on: July 24, 2013, 09:52:24 pm »
Well they aren't just going to magically update themselves.  You have to tell them when and how to update.  A simple way to see it happen would this:

(this is just pseudo-code but the ideas laid out)
while(sf::Event)
     -If Event is a Keypress (Spacebar for example)
     -Add however much you want to goldamount variable

That would let you hit a key and add whatever you code it to add

Lethn

  • Full Member
  • ***
  • Posts: 133
    • View Profile
Re: Lethn's Programming Questions Thread
« Reply #70 on: July 24, 2013, 10:25:30 pm »
Ahh, hang on, I think I tried this before but ran into problems, despite having put my + 5 in the braces nothing happens in the while loop, thankfully I don't get any crashes though, made me think I was looking at the wrong command but it looks like my coding is wrong.

#include <Iostream>
#include <SFML/Graphics.hpp>
#include <sstream>

int main()
{

    sf::RenderWindow window(sf::VideoMode(800, 600), " ");

    sf::Font arial;
    if ( !arial.loadFromFile ( "arial.ttf" ) )
    { }

    int goldamount = 0;

    while ( goldamount )
    {
        goldamount + 5;
    }


    std::ostringstream gld;
    gld << "You have " << goldamount << " Gold";





    sf::Text goldtext;
    goldtext.setFont ( arial );
    goldtext.setCharacterSize ( 12 );
    goldtext.setColor ( sf::Color::Yellow );
    goldtext.setPosition ( 20, 20 );

    goldtext.setString ( gld.str () );

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

        window.clear();
        window.draw ( goldtext );
        window.display();


        gld.str ( " " );
        gld << "You have " << goldamount << " gold";
        goldtext.setString ( gld.str() );

    }
    return 0;
}


 

Edit: Yep and when I change the value in the test condition ( know the vocabulary now yey! :D ) the while loop crashes the program.
« Last Edit: July 24, 2013, 10:31:22 pm by Lethn »

The Hatchet

  • Full Member
  • ***
  • Posts: 135
    • View Profile
    • Email
Re: Lethn's Programming Questions Thread
« Reply #71 on: July 24, 2013, 10:39:45 pm »
Send you a PM over this, lets start with the PM help so we don't tie up the forum space.  If we hit a problem I can't help you with then we will return to the forum (or if i'm not online for a while and you need help)

Lethn

  • Full Member
  • ***
  • Posts: 133
    • View Profile
Re: Lethn's Programming Questions Thread
« Reply #72 on: July 24, 2013, 10:50:18 pm »
lol alright, I'll post you it there, I do think it's helpful though to keep the solutions and stuff public.

Lethn

  • Full Member
  • ***
  • Posts: 133
    • View Profile
Re: Lethn's Programming Questions Thread
« Reply #73 on: August 02, 2013, 02:34:35 am »
I'm going to post updates whenever I do something significant, with the help of hatchet I managed to get some basic incrementing like I wanted, I just need to figure out how to get the numbers updating without any user input now.

#include <iostream>
#include <SFML/Graphics.hpp>
#include <sstream>

int main()
{

    sf::RenderWindow window(sf::VideoMode(800, 600), "");

    sf::Font arial;
    if ( !arial.loadFromFile ( "arial.ttf" ) )
    { }

    int goldamount = 0;


    std::ostringstream gld;
    gld << "You have " << goldamount << " Gold";





    sf::Text goldtext;
    goldtext.setFont ( arial );
    goldtext.setCharacterSize ( 12 );
    goldtext.setColor ( sf::Color::Yellow );
    goldtext.setPosition ( 20, 20 );

    goldtext.setString ( gld.str () );


while (window.isOpen())
{

sf::Event event;
while (window.pollEvent(event))
{

if (event.type == sf::Event::Closed)
window.close();
}

           if ( sf::Keyboard::isKeyPressed ( sf::Keyboard::A ) )

           {
               goldamount --;
           }
           if ( sf::Keyboard::isKeyPressed( sf::Keyboard::D ) )
               goldamount ++;

        window.clear();
        window.draw ( goldtext );
        window.display();


        gld.str ( " " );
        gld << "You have " << goldamount << " gold";
        goldtext.setString ( gld.str() );

    }
    return 0;
}


 

Lethn

  • Full Member
  • ***
  • Posts: 133
    • View Profile
Re: Lethn's Programming Questions Thread
« Reply #74 on: August 02, 2013, 02:37:10 am »
I am now working on doing the same sort of thing but with a coloured bar, I have the rectangle drawn and everything is compiling but now I need to figure out why the if statement isn't working as it should. As you might guess looking at the code I'm trying to make it so when you hit a button the rectangle changes size across the X axis, just like you'd get with a health bar or other statistic in a game.

#include <iostream>
#include <SFML/Graphics.hpp>
#include <sstream>

int main()
{

    sf::RenderWindow window(sf::VideoMode(800, 600), "");

    sf::Font arial;
    if ( !arial.loadFromFile ( "arial.ttf" ) )
    { }

    sf::RectangleShape health ( sf::Vector2f ( 120, 20 ) );
    health.setFillColor ( sf::Color::Green );
    health.setPosition ( 10, 10 );

    if ( sf::Keyboard::isKeyPressed ( sf::Keyboard::Left ) )

    {
        health.setSize ( sf::Vector2f ( 100, 20 ) );
    }


while (window.isOpen())
{

sf::Event event;
while (window.pollEvent(event))
{

if (event.type == sf::Event::Closed)
window.close();
}
        window.clear();
        window.draw ( health );
        window.display();

    }
    return 0;
}