How to make PC games

Started by
41 comments, last by Oluseyi 15 years, 10 months ago
It's pretty hard to find a C only compiler, especially for a beginner (name two without doing a search). Most likely you'll either get Microsoft Visual C++ express, MinGW/DevC++, Cygwin/gcc, or maybe Open Watcom. All of these are C++ compilers that will compile C code.

Personally, I would rather teach a person to code with C++ in mind, since that should probably be the ultimate goal. Compiling in C 'mode' will allow you to do things that will cause an error in C++ 'mode' (function calls without a declaration), or force them to do stuff they really don't need to do (define a struct variable with the 'struct' keyword, without a typedef). Why not make it easy to move to C++, by making the code C++ compliant?


PS: The only two C only compilers I could think of were Pelles C and lcc-win32. And, doing a search, they are both based on lcc, so probably should count as one.

Check out Super Play, the SNES inspired Game Engine: http://www.superplay.info

Advertisement
Another vote for using C++ instead of C. I rewrote the file along with some suggestions for improvement, some related to C++ and some not. I tried not to change the structure too much, so maybe it can be improved even further.

I hope you'll take my suggestions into consideration.

#include <iostream>#include <string>#include <cstdlib>	// rand()#include <ctime>using namespace std;// In my opinion the defines don't add much, but if you// really want them, declare them as const std::strings.// The globals you had here don't need to be global. In// fact, some of them are not needed at all./* GuessNumber(int number, int n)   Compare the number n with the number computer "thought" of and return a comparative answer   Return value:   ( -1 ) if the number is too low,    ( 1 ) if the number is too high or    ( 0 ) if the numbers match */int GuessNumber(int number, int n){  if (n > number)	  return 1;  else if (n < number)	  return -1;  return 0;  // Note that because of the way the return value is used later  // on, it doesn't matter if the function returns 1 or -1, it  // can be any number that's larger or smaller than 0, so you  // can just do this:  // return n - number;}/* InitGame()    Let the computer pick a random number */void InitGame(){  cout << "InitGame()..." << endl;    // The cast to unsigned removes a compiler warning  srand((unsigned)time(NULL));  // Moving the rand() call to Play() allows us  // to get rid of a global ('number' in your code)  // so it's worth doing}/* Play()    This is where gameplay takes place */void Play(){	cout << "Play(): " << endl;	cout << "Computer: I have thought of a number between 0 and 100. Can you guess it?" << endl;        cout << "Please enter the number below." << endl;	// This is only needed here so it doesn't need to be	// declared globaly.	// Prefer const to #define, it's type-safe and it's scoped -	// if we #defined this in here, it would still be visible in	// the entire file, but with const it's only visible in this	// function.        const int NUMBER_OF_TRIES  = 5;	// You should only declare variables when you are about	// to use them and can initialize them to a valid value		// Also, rand() % 100 return a number in [0, 99] inclusive.	// If you want [0, 100], you need to write:	int number = rand() % 101;	// A for loop is more convinient here	for (int i = NUMBER_OF_TRIES; i > 0; --i) {                cout << "You have " << i << " tries left" << endl;		int guess;		cin >> guess;                // In your code, this variable was called 'answer', but		// the return value is not the answer the user entered,		// it's a classification of the answer, therefore you		// should pick a different name (thogh mine isn't much better :)		int c = GuessNumber(number, guess);				if (c == 0) {			cout << "CONGRATULATIONS, You won, the number " << guess << " is correct!" << endl;			return;		}		// We are returning from the if, so an else clause is not needed		if (c > 0)			cout << "Computer: The number you entered is too high" << endl;		else			cout << "Computer: The number you entered is too low" << endl;	}	cout << "SORRY YOU LOST, The number I thought of was " << number << endl;}/* Destroy()    This is where we would destroy allocated memory, etc.   Because Guess is a very simple game, we have nothing to do here,   But this would be an important step in an advanced computer game */void Destroy(){  cout << "DestroyGame()" << endl;}/* int main()   Program entry point */// You're not using argc and argv, so there's no need to// introduce them.int main(){  InitGame();    Play();    Destroy();	  // In C++, if main() doesn't return a value, 0 is returned  // automatically.}
The beginner is not going to understand anything from this tutorial. He will even be confused and have a lot of unanswered questions.
For example, he will wonder why the program gets crazy when he enters something else than a number. A good tutorial would explain this and show howto solve this... A good tutorial would explain things step by step... A good tutorial explains the motivation behind each line of code...

And more importantly : A tutorial should be written by experts only.
The "for beginners" forum is the good place for that thread, but not because the tutorial is for beginners.

99% of the turorials on the internet do suck1.
The good side of this fact, is you can quickly see if someone is a real good programmer or just a "tutorial code copy/paster", because most tutorials don't explain anything so the bad programmer will just copy/paste without understanding everything. Just ask why he wrote a given line, and wait for the "it has to be done like that" answer.

1 For example (I know a lot of people won't agree), I think the NeHe tutorials are pretty bad. It lacks the "why do I have to do this that way" explanation for every code snippet, so you loose a lot of time to understand most of the function calls. What's really annoying is the illusion on the Internet that it's a damn good tutorials, hence a lot of so-called "NeHe-style" ones. "NeHe-style" ? Poor-style...

[Edited by - rolkA on June 18, 2008 2:08:49 PM]
English is not my native language.Sam.
As a general rule, before releasing something to the public, you should compile with warnings cranked to the highest level. Then you find errors like this:
printf( "Computer: I have thought of a number between 0 and 100. Can you guess it?\n", number);guess.cpp:50: warning: too many arguments for format


BTW should I convert my Guess The Number into a turorial? Just kidding ;)
Quote:The beginner is not going to understand anything from this tutorial. He will even be confused and have a lot of unanswered questions.
For example, he will wonder why the program gets crazy when he enters something else than a number. A good tutorial would explain this and show howto solve this... A good tutorial would explain things step by step... A good tutorial explains the motivation behind each line of code...


This is a sketch, the tutorial is incomplete.

Quote:And more importantly : A tutorial should be written by experts only.
The "for beginners" forum is the good place for that thread, but not because the tutorial is for beginners.

Ideally a tutorial "should" be written by the person who has experience with the subjects written on. He must also have the passion for education. But you will never change the fact that all [computer] tutorials have always been and always will be written by mediocre writers and programmers, with only a few exceptions.

Quote:1 For example (I know a lot of people won't agree), I think the NeHe tutorials are pretty bad. It lacks the "why do I have to do this that way" explanation for every code snippet, so you loose a lot of time to understand most of the function calls. What's really annoying is the illusion on the Internet that it's a damn good tutorials, hence a lot of so-called "NeHe-style" ones. "NeHe-style" ? Poor-style...

Nehe tutorials were excellent for the audience they targeted. They were getting a lot of positive response and friends would tell others about them. They were targeted at beginners, teenagers and high-schoolers who needed their hand held through the process.

It's easy to talk shit about other people's work, whether its tutorials or not. Have you tried writing one? It takes a tremendous amount of effort and research.

Discord GameDev Chat 38+ members | Skype GameDev chat group 235+ members

You asked for a review of your work. Please stop taking offense at the constructive criticism that you are receiving. People are responding because you asked for their comments.

Instead of lashing out at every commenter and defending yourself, simply take their suggestions and make changes as you see fit.
I also just read your tutorial and noticed that the 'About the Author' section is the longest one on there...

As your tutorial is now, it seems more like an introduction to game concepts (the paradigm as you call it). I was a little confused when after reading about the Game Destruction process, I was presented with a large cpp file and told to compile it. How do I compile it? Where is some more detailed code analysis? The comments are good, but by no means a replacement for an in-depth explanation.

Good luck on your page!
Quote:Original post by rolkA
And more importantly : A tutorial should be written by experts only.


I agree and disagree at the same time. I wrote a slew of XNA tutorials that many beginners and more advance programmers welcomed warmly and seemed to enjoy and I had only been working in XNA a few months before writing. Then again, I had been programming for 3 1/2 years prior to that (at least) and had already gotten my Associates in programming. But, then I mentioned to some XNA guru's one of the things I've added to my tutorials and was hit with some severe backlash (I included an empty destructor in each class because I was used to seeing a destructor, which apparently makes your program run longer by basically stalling the garbage collector).

So really, I think you can write tutorials as a new guy to whatever you want, but I'd say the newer you are to it, you're more prone to mistakes and being heavily criticized on them. There are tons of books out there written by professionals and published by professional technology book companies that are junk. I think it partially depends on the writer/programmer.

Also, I realized when writing tutorials like this and receiving feedback, the best thing to do is a prompt answer. I got numerous people with errors because of their own programming problems and numerous others with suggestions for my tutorials (and I didn't even ask for suggestions!). The best thing to do is address these problems right away and talk to the community (the people viewing your tutorials).

=============================RhinoXNA - Easily start building 2D games in XNA!Projects

Quote:Original post by rolkA
And more importantly : A tutorial should be written by experts only.


I disagree with this. I think that someone who's not an expert can write a good tutorial, so long as he submits it for review (preferably on this site [smile]) and carefully considers the criticism given to him. Unfortunately, that doesn't seem to be the case here.
Quote:Original post by gregsometimes
It's easy to talk shit about other people's work, whether its tutorials or not. Have you tried writing one?


I've considered it a few times, as I'm sure many of us have. I've never bothered though, for the following reasons:

1) For any given subject I feel sufficiently qualified to write about, there are already a wealth of probably better tutorials available on the internet.

2) As a regular poster in this forum I have seen, first hand and over several years, the damage that poorly written tutorials can do to beginning programmers and have no wish to add to said damage.

3) When ever I have seriously considered any given topic to write about, I have realised that there are so many holes and gaps in my own understanding that I could not really do the topic justice.

You may, of course, feel that none of the above applies to you. I defend to the death your right to that opinion.


Quote:Original post by gregsometimes
It takes a tremendous amount of effort and research.


Unfortunately, old sport, tremendous amounts of effort and research do not necessarily equal a tremendously good result. I'm sure you put a lot of work into your website. This does not, of itself, make it any good for the purposes you intend.

If it is any consolation, I thought your web design was quite good.

This topic is closed to new replies.

Advertisement