Is every aspect of C++ used in..

The area of developing/designing/programming/etc. games? From what I've read of the tutorial on this site, there seem to be certain parts that make sense to be used and others that don't. For instance the I/O section makes sense and, while I haven't read it thoroughly yet, I assume the Object Oriented section makes sense.

Aside from those, and the ones that display text, I can't find an application for the other bits I've read. There probably is and I'm just overlooking it, but if anyone could point out how some of them are used in games, I'd be grateful.

(This is mainly referring to the tutorial, if that's not entirely clear. Which knowing me it probably wasn't.)
A huge chunk of the C++ language is used for game development. I/O is just the beginning. Everything from arrays and loops, to classes and functions are absolutely essential in developing the underlying game logic. I can't think of anything off the top of my head that is not relevant in some way to game mechanics.

return 0;
What "other bits" - you are very vague in your question. I would agree with Return(0) in that most of the C++ language would be used in gaming - and in most other applications.

Try reading more about the language and working through some examples until you get a real feel for C++. Then come back with a more specific question.

Alan
Since I already have a thread associated with questions..Might as well use it, right?

Anyway, I've been experimenting with the if/else stuff and input/output commands. I know a lot of games use letters to trigger stuff like movement and so I tried to do something like that. Of course, it would just be to trigger a message like, you walked forward. Unfortunately, it only slightly works.

Here's the code to help see what I was trying to do:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
using namespace std;

int main ()
{
    
    int w;
    int a;

    cout << "Please enter a command:";
    cin >> w;
    if (w == w)
    cout << "You have chosen to walk forward.\n";
    else cout << "You have chosen not to go forward.\n";
    cout << "Choose a movement direction:";
    cin >> a;
    if (a == a)
    cout << "You have chosen to walk westward.\n";
    system("Pause");
}


The problem is, whenever I hit W, it spits out the rest of the code that should only come out if I hit a different key. It works perfectly whenever I use numbers, so what's the issue with using letters?

About my initial question..I apologize for the vagueness of it. I'm not exactly great at asking questions about things that I don't grasp entirely.
You're looking for something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
using namespace std;

int main ()
{
    
    char direction;

    cout << "Movement Controls\n";
	cout << "w = north\t" << "a = west\n" << "s = south\t" << "d = east\n";
	cout << "Enter a movement direction: ";
	cin >> direction;
    
	if ( direction == 'w' )
		cout << "You have chosen to walk north.\n";
	
	else if ( direction == 'a' )
		cout << "You have chosen to walk west.\n";

	else if ( direction == 's' )
		cout << "You have chosen to walk south.\n";

	else if ( direction == 'd' )
		cout << "You have chosen to walk east.\n";
 
	else
		cout << "You have chosen to stand still!";
	
    system("Pause");
	return 0;
}


Your variable should be a char not int since you are entering one letter.
Note that w and 'w' are different. w is a variable which holds something, a container. 'w' would be what would go into the container. (if you had the right type)

When you say
if(w == w)
You are comparing variable w to variable w, which of course will always be true, not comparing your w (input) to the letter 'w'.

Don't get too ahead of yourself with this programming stuff. It only gets more and more in depth so if you don't understand something fully, you'll wound up getting lost sometime later.
Don't get too ahead of yourself with this programming stuff. It only gets more and more in depth so if you don't understand something fully, you'll wound up getting lost sometime later.


I wasn't intending on getting ahead of myself really. I just felt like taking a break from reading the tutorial and experimenting a bit. It's really just a part of how I learn things, I learn something, and then I try to see how it works with other stuff.

Thanks for explaining that Return, I just got a bit used to the general int [insert whatever] then use that for input. Well, not to mention I just skimmed over the different types.
Last edited on
I can't think of anything off the top of my head that is not relevant in some way to game mechanics.

Well, there is: the evil, evil

goto

Furthermore, you don't need

auto, register, inline

and most likely don't need

asm

And I don't think exception specifications are of any use in games (they could be a Good Thing, they just have an impact on speed which is not acceptable). So no nothrow guarantee in destructors... (on the other hand, simply writing the specification woud result in the call of terminate(), which is most likely not better than a throwing destructor)

What you perhaps don't need and should avoid is multiple inherritance, the *void-pointer and builtin-arrays (because of speed and unmaintainablilty, lost type checking and stuped errors which are unneccessary).

Which leaves us with, ... well, the about 99.9% of C++ which are left.
I wasn't saying that you were. It's good to experiment and apply things that you've been learning.

Here's how I think learning stuff works

Reading 10%
Applying 90%

Read pages xxiii - xxvii of this. It's kinda funny but true.

http://books.google.com/books?id=5VTBuvfZDyoC&printsec=frontcover&dq=head+first+java&ei=zyKQSPHXJJX4iQGszq3DCg&client=firefox-a&sig=ACfU3U2SjW-o83Y3TgOVlWRnWtBJnFcbvA#PPR24,M1

Just giving you a heads up that's all. And asking questions is good too. Don't be afraid to post a question if you're stumped.
Topic archived. No new replies allowed.