Sign in to follow this  

2 C++ books and...

This topic is 3786 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I have been programming C++ off an on for about 1 year. Over the course I have reread 2 C++ books(C++ for dummies and teach yourself C++ in 24 hours) many times. I figured by reading these books it would put me closer to my goal of game programming. If any, it seems to have dragged me away from my early years of primitive use of gamemaker. I read the books over and over again hoping to find some detail I overlooked. Towards the last half of the books when it seems to go more about classes and pointers everything seems to go haywire. I can't fully grasp why I would want to make classes called Cat and why I would want at all to overload that class's constructor when there seems simpler ways around it. I can understand what each basic program is doing but if I were to try to develop it myself I wouldn't have the slightest clue where to start. I find myself wondering why certain parts of the example code are in there and how it in the long run will relate to game programming. I have toy'd with the idea of buying a c++ game developing book but don't want to move on from the basics until I am absolutely sure why every bit of the code is doing what it does. Is this just fantasy think way of thinking that I will be able to understand everything from the basic C++ books without even trying it at game programming, should I reread the books more times, or should I give game programming a try and see if it all clicks into place. Sincerely, A very confused man

Share this post


Link to post
Share on other sites
Quote:
Original post by meab
Hi,

I have been programming C++ off an on for about 1 year. Over the course I have reread 2 C++ books(C++ for dummies and teach yourself C++ in 24 hours) many times. I figured by reading these books it would put me closer to my goal of game programming.

If any, it seems to have dragged me away from my early years of primitive use of gamemaker. I read the books over and over again hoping to find some detail I overlooked. Towards the last half of the books when it seems to go more about classes and pointers everything seems to go haywire. I can't fully grasp why I would want to make classes called Cat and why I would want at all to overload that class's constructor when there seems simpler ways around it.

I can understand what each basic program is doing but if I were to try to develop it myself I wouldn't have the slightest clue where to start. I find myself wondering why certain parts of the example code are in there and how it in the long run will relate to game programming. I have toy'd with the idea of buying a c++ game developing book but don't want to move on from the basics until I am absolutely sure why every bit of the code is doing what it does.

Is this just fantasy think way of thinking that I will be able to understand everything from the basic C++ books without even trying it at game programming, should I reread the books more times, or should I give game programming a try and see if it all clicks into place.

Sincerely,

A very confused man

Give game programming a try and see if more things click.

As for reasons to overload, and a more game oriented example think of a sprite, your player is a sprite as well as the enemies your players face, and when it comes to handling the display and animation of the sprites, would it not make sense to make both the enemies and your player sprites to share the code that's similar among them to eliminate the need to repeat code?

Share this post


Link to post
Share on other sites
C++ is hard. Especially if the last thing you used was gamemaker.

There isn't anything keeping you from learning the concepts if you're devoted, but your life could be easier if you take smaller steps. Starting with a simpler language will allow you to grasp all the basics of programming before jumping into the deep end.

IMHO even starting with C would keep you from learning about all that polymorphism and pass by reference business before you're ready. Though C# or VB would probably be recommended.

But if you're still committed to the idea of learning C++ just practice by writing lots of small programs based on all the concepts and example code in your book. Make sure to experiment with those programs and test your knowledge!

Share this post


Link to post
Share on other sites
From what I have heard from people they tell me not to learn C++ than C becuase I will get confused more. I have toyed with the idea of trying C and people tell me that it will in the end confuse things alot more. Is that not true?

Share this post


Link to post
Share on other sites
Quote:
Original post by meab
From what I have heard from people they tell me not to learn C++ than C becuase I will get confused more. I have toyed with the idea of trying C and people tell me that it will in the end confuse things alot more. Is that not true?


I honestly don't see how C can be more confusing that C++. Since C is a proper subset of C++, by definition C++ can only be as or more confusing than C.

Though as I mentioned before Visual Basic or C# would probably be a more gentle introduction to programming.

Share this post


Link to post
Share on other sites
That conclusion does not follow: Just because C is a subset of C++ (at least in the way you seem to like to think about it), does not mean, that it is least or at most as much confusing as C++. Maybe C++ introduces a few organising structures that might in the end actually make code less confusing? Just a thought.

Share this post


Link to post
Share on other sites
I would try a game book such as "Game Programming All in One".

"Why would I use a class?"
Imagine a multiplayer game. Here is a Player class:

class Player
{
int life;
float positionx, positiony, positionz;
string player_name;
};

1.Ok someone joins your game. They would send data over the internet as a player class like:

life;xpos;ypos;zpos;name;
100;40;40.4;10.4;meab;

2. Your code would be:

NewPlayerJoined()
{
Player temp;
temp.life = 100; .........etc the above code
Player[nextPlayer] = temp;
}

3. You shoot a bullet and look at all the players. You hit the newly joined player and killed him. You want to say "You killed _____". So:

print << "You killed " << Player[hit_player].name;

Share this post


Link to post
Share on other sites
As for constructors, you might say every new player starts at the same spawn point (10, 20, 40) and has 100 life. It's easier to just do this:

class Player
{
Player()
{
positionx = 10; positiony = 20; positionz = 40;
life = 100;
}

Share this post


Link to post
Share on other sites
Quote:
Original post by meab
From what I have heard from people they tell me not to learn C++ than C becuase I will get confused more. I have toyed with the idea of trying C and people tell me that it will in the end confuse things alot more. Is that not true?

Have you considered going the other way for languages to one like Java/C#/Python?

Share this post


Link to post
Share on other sites
If I were you, I would get my hands dirty coding a simple game in which you can use the concepts you learned in the books. (like a console - text based - game in which you don't have to deal with the complexities of 3D API's). You can always use the books as a reference. An easy way to start designing your classes is to grab a paper and write down objects(what you want them to do -methods- and their status -properties-). For example, for a tile-based game:

Enemy/Player
-Methods
-- Shoot(bullet)
-- MoveUp/MoveDown/...
-- HasBullets
-- Decide (for adding AI for enemy players)
- Properties
-- isDead
-- bulletCount
-- id/name
-- hp/lifeRemaining

Bullet
-Methods
-- Move
-- IsOutofRange
-Properties
-- direction
-- startCoords
-- range
-- pointer to shooter
-- position

...

Pointers provide an easy access & helps you to share your objects. For example in the context of the game above, lets say you want to see if a bullet is in the same tile with your player and who shoot your player (if any)

foreach bullet
{
if bullets position = players position
{
cout << bullet->shooter.name << " shoot you bla bla"
}
}

As you can see several bullets can have access to the same shooter so they are sharing the same object. Once you start thinking in object oriented way, you'll see that it's a lot easier than the other way.

Share this post


Link to post
Share on other sites
Quote:
Original post by HansDampf
That conclusion does not follow: Just because C is a subset of C++ (at least in the way you seem to like to think about it), does not mean, that it is least or at most as much confusing as C++. Maybe C++ introduces a few organising structures that might in the end actually make code less confusing? Just a thought.


Yes, there exist some C features that are not present or interpreted differently in C++. But none large enough to be worth mentioning in this discussion.

C++ does introduces features that can, if used correctly, make writing/reading/using code easier. But C++ also introduces features that used correctly or incorrectly make the code more confusing but also more powerful. Not to mention the fact that new comers will surely lack the knowledge of how to apply C++ features effectively.

Share this post


Link to post
Share on other sites
There are two free books in my signature. I recommend that you read chapters 4-6 from Thinking in C++, volume 1 (3rd link). After those chapters, classes might make more sense.

Share this post


Link to post
Share on other sites
Quote:

Is this just fantasy think way of thinking that I will be able to understand everything from the basic C++ books without even trying it at game programming, should I reread the books more times, or should I give game programming a try and see if it all clicks into place.

It's complete fantasy.

C++ (and C) are very difficult languages, especially for beginners. They are large, subtle, needlessly low-level, burdened with lots of baggage and legacy concepts, and so on. Another language like C# or Java would definitely be easy to pick (and easier to produce interesting results with).

That said, however, you're still not going to be able to understand everything just by reading books over and over. You have to sit down and write code, you have to practice. And you have to start doing that with "games" that don't sound that interesting -- or even difficult -- on the surface.

Can you write a simple "guess-the-number" game? Can you modify that game so that the number you have to guess is chosen randomly? Can you write tic-tac-toe (in the console, no graphics) or hangman? Can you write a program to generate a simple 2D maze?

Find one of those options that seems like something you would feel comfortable doing -- if you can't tell, do the first one. Practicing and applying the concepts you've read about will help you actually learn learn and understand them.

Share this post


Link to post
Share on other sites

This topic is 3786 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this