2 C++ books and...

Started by
11 comments, last by jpetrie 16 years, 8 months ago
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
Advertisement
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?
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!
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?
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.
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.
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;

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

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;
}

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

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?
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.

This topic is closed to new replies.

Advertisement