Learning to use Microsoft Visual C++
Hello, I'm new to coding, but I really want to start learning so I can program basic games. Can anyone recommend a book or set of projects for somebody very new to using Microsoft Visual C++ 2008 Express Edition? I know there are a lot of books that come with a compiler, but I'm thinking the code they give might work or compile differently (I've never liked CodeBlocks anyway, and it doesn't like my computer :P ). I've also been told it is better to use a mainstream program as you can get boilerplate code and game engines specificity made for it. Is this true?
I would really like to do small projects rather than read through huge chunks of dry text - I've tried that and I swear they write it in the most obtuse way possible. Just reading about something doesn't help me, I have to be doing the things they are telling me about as they are telling me. :P
Can anyone help me get started with a really simple game-making tutorial that takes you through every step (DIY noughts and crosses or something)?
Re: Learning to use Microsoft Visual C++
Quote:
Can anyone help me get started with a really simple game-making tutorial ...
If I got a euro for every time somebody asked this I could buy a new car.
Writing a game is not easy, even writing a really simple graphical game takes effort. It's nice to read that you are are new and want to learn something, but for writing a game, you first need to learn the basics of programming, and because you didn't give any background I assume that you're 'totally' new to programming.
Quote:
I would really like to do small projects
Good... Did you manage to create a window that says 'hello, world' ? If not, start there. I'm not trying to make fun of you or something, but before you start to write software that actually is useful, you first need to write useless stuff just to figure out how to write software :). So my adive is, find a good book that covers the basics, write a lot of useless stuff to train yourself and learn, and after you're done with that, start thinking about writing a very simple game.
Re: Learning to use Microsoft Visual C++
If you're into making games I think XNA is a good starting point. I've never used it myself but have seen some quite good games using it. For using XNA you need C# express but I guess that's not a problem since you've started your programming career.
Re: Learning to use Microsoft Visual C++
Quote:
Good... Did you manage to create a window that says 'hello, world' ? If not, start there. I'm not trying to make fun of you or something, but before you start to write software that actually is useful, you first need to write useless stuff just to figure out how to write software . So my adive is, find a good book that covers the basics, write a lot of useless stuff to train yourself and learn, and after you're done with that, start thinking about writing a very simple game.
I have done that! (The books have been fairly useless so far....)
The reason I want one that does games (coin flip would be a good place to start - GetRND?) is because they seem to be the only ones worth having. I've tried two 'traditional' ones so far and the only thing I came out of that with is the feeling I could teach them more about clear writing than they could teach me about programming. :P The Dummies Guide to C++ was particularly bad.
I really just want a guide that is mostly practical in nature!
Re: Learning to use Microsoft Visual C++
Sorry, that sounded flippant. :P I'm just really frustrated. I have my C++ editor ready to go and nothing to do with it.
Re: Learning to use Microsoft Visual C++
Quote:
Originally Posted by
Ion Zone
I have done that! (The books were useless!)
You still didn't say what is your programming experience at this point?
If you're just the beginner and don't want to deal with boring C++ and instead want to go straight into making games then I would reconsider your approach. There's no book in the world that can teach you a programming language while at the same time use one of the most complex development fields, i.e. game programming. Believe me if someone showed you a book with the nitty gritty on game development you'd be swamped by DirectX/OpenGL references, vertices, polygons, sprites, etc. So listen to what people tell you here and learn the basics first. But, as I often tell people that rush straight into game development and don't want to learn a language like C++, you'll play around with the concept but in the end end up simply playing those games. So think about that...
PS. The first Google search on "c++ for game developers" yielded this book. I'm not endorsing it though, it's just something you may want to look into. What amazes me is the difference between that book and a regular book for C++ beginners -- the author names all the classes and class variables with names relevant to the game design characters, i.e. class Enemies{}. That's a funny approach. But he might make some money with it :)
Re: Learning to use Microsoft Visual C++
Quote:
Originally Posted by
Ion Zone
I have done that! (The books have been fairly useless so far....)
The reason I want one that does games (coin flip would be a good place to start - GetRND?) is because they seem to be the only ones worth having.
Learning C++ means you know how to use the language properly, know when to make the correct decisions to use a certain programming concept, etc. In a game, business program, or any non-trivial program, you need to decide what structures, paradigms, design patterns, etc. to use. That is what those "boring" books are trying to teach you.
Do you use a linked list, a deque, or a vector? Do you use templates or just dynamic binding? I could go on and on with the decisions that C++ programmers, regardless of what field they're in, have to make when they are writing a program.
If you want an example, there are many posters that ask questions here, and they are writing somewhat complex MFC program. The problem is that these posters used wizards to generate the code, and have very little knowledge of real C++ to take them any further. So what winds up happening is that they're asking chapter 1 or chapter 2 C++ questions, while trying to write a complex GUI-based program. That is a recipe for disaster.
If you get a book on game design and C++, and it isn't for beginners, you will see the same constructs that the "boring" books were trying to teach you -- the problem now is that those non-beginner books assume you know the language already, and not just a cursory knowledge of the C++ language, but a very broad one. You will then be thumbing through the "boring" books to figure out what the heck that function or construct in the game programming book means.
Regards,
Paul McKenzie
Re: Learning to use Microsoft Visual C++
Quote:
If you're just the beginner and don't want to deal with boring C++
I've coded a Fahrenheit to Celsius converter in C++, and before that I coded my own sites in in boring HTML and CSS with a view to learning boring php.
Quote:
That is what those "boring" books are trying to teach you.
I didn't say the books were boring, I said that the ones I had read were written very, very, badly and didn't include basic information. All I really want to know is if there are any with a more practical, preferably games-based, approach. I know of at least one book that does, but it has its own compiler. It has a CD full of graphics sprites and it tells you how to make a game with them. It probably starts off with, for example, coin flip, which is really just an integer that can be either 1 or 2. You call random to set it and then print the result to the screen as "Heads" or "Tails". That leads on and on until, in the final project you are building a fully playable game.
I don't see what the problem is. At the very least a guide can be entirely practical. A guide to anything is useless if it isn't practical. What's the point? Will I remember three chapters of (badly-explained, if experience is anything to go by) facts? Will I remember all the variable types if you put them in a grid? No I won't. If you get me to use them, yes I will, I'll remember them the next time I need them.
Re: Learning to use Microsoft Visual C++
Quote:
Originally Posted by
Ion Zone
For example, coin flip is just an integer that can be either 1 or 2.
You see you already don't sound like you know much about programming. Most of the guys on this forum would say that a coin flip would be either 0 or 1, which by the way is the basics of the binary system that will be an integral part of those C++ books for beginners.
But I see your point, you don't like the dryness of the C++ language and you want to go straight to making games. Well, one way would be to download a simple C++ game with the source code (I'm sure you can use Google for it) and see if you can understand the concept. If you do, then you're one step closer to making your own game and you just skipped through the boring part of learning C++ basics.
As books go, I do not think that anyone can point to a perfect for everyone book and the only way for you to find out if the book is good is to buy it and read it. So why don't you start from the link I posted above and give it a try? Or browse Amazon.com for more books on the subject. They all have customer reviews by the way, so you can see if a book was well accepted by the readers.
Re: Learning to use Microsoft Visual C++
Quote:
Originally Posted by
Ion Zone
The Dummies Guide to C++ was particularly bad.
A quick google search only turns up your own post. :confused:
Quote:
I really just want a guide that is mostly practical in nature!
Have a look at Accelerated C++ by Koenig and Moo.
Quote:
Originally Posted by
Ion Zone
I didn't say the books were boring, I said that the ones I had read were written very, very, badly and didn't include basic information. All I really want to know is if there are any with a more practical, preferably games-based, approach.
So do you want a practical book or one that deals with all the basics? IMO they don't mix, at least not in the same book. If you want a book that covers the basics, have a look at C++ Primer Plus or The C++ Programming Language.
Quote:
Will I remember three chapters of (badly-explained, if experience is anything to go by) facts? Will I remember all the variable types if you put them in a grid? No I won't. If you get me to use them, yes I will, I'll remember them the next time I need them.
So what's stopping you from practicing? It's really not that difficult to write some games once you know the fundamental stuff. All you need is a bit of creativity. I've made lots of really simple console games even before I learned about classes. No book or teacher had to tell me what to do, I just did whatever I could think of.
Re: Learning to use Microsoft Visual C++
Quote:
Most of the guys on this forum would say that a coin flip would be either 0 or 1, which by the way is the basics of the binary system that will be an integral part of those C++ books for beginners.
Most guys on this forum know how to code. I don't. If you can learn from a book that has fewer examples than chapters, great. I can't do that. I need to be shown how to do things.
Quote:
A quick google search only turns up your own post.
Its this one. Don't bother though, it's pretty crap.
Quote:
Have a look at Accelerated C++ by Koenig and Moo.
Thanks, that's all I really wanted! Looks really good.
Quote:
So do you want a practical book or one that deals with all the basics? IMO they don't mix, at least not in the same book.
They do mix! You can learn more from one good demonstration than fifty pages of dry meandering. (Wait, are you saying the book you recommended isn't practical?)
Quote:
So what's stopping you from practising?
I haven't got anything to practice with. I don't know enough about C++ to do that.
Quote:
and you just skipped through the boring part of learning C++ basics
I never said it was boring. I like coding. (I made it through David\Leigh Eddings book once, so I have a high threshold.) But anyway, that method won't work, there's no real Zen moment when you are staring at half a mile of brackets.
Re: Learning to use Microsoft Visual C++
If you want to make a game, have little programmign experience, and want to do somethign useful, then you can already to some ground work.
While actual graphical games take a lot of effort and a lot of know how (and a lot of groundwork, especially if it's 3D based), you can already progress toward your game without doing anything user interface wise.
Which type of game are you planning. Have you thought about your game concept, which objects will you have in your game. If it's a first person shooter type thing, you would have a 'player' class, which has location, direction, type of weapon, health, inventory etc. You would also have stuff that needs to be killed.
Thinking about that, and translating this into classes can be done already without doing anything UI related.
If you have more simple games in mind, like a game of poker, or blackjack. then you would have cards of varying suits and values. you maybe have multiple decks you need to shuffle the deck, deal hands etc...
If you have a game that involves playing against the computer, then you can think about the method that the computer would 'think'... The artificial intelligence... for some games this can be a really simple set of rules, for some games it can involve complex/elaborate strategies...
You don't even have to write a single letter of actual code. just look at your intended game from a distance and think about how you would split up the entirety of the game into a collection of simple and fundamental problems, then handle each subproblem at a time. The typical flaw with any kind of programming of a program of more than a few hundred lines is trying to do everything at once, rather than looking at the whole as a collection of smaller problems. and tackling each smaller issue at a time.
Re: Learning to use Microsoft Visual C++
Thanks for the advice. Maybe a multi-choice text-based adventure would be a good start. Type '1' to hit the rat with the stick. Type '2' to run away. ;) Then later on, I could give it a proper background and maybe add a couple of pictures and a health bar.
What do you think?
Re: Learning to use Microsoft Visual C++
Quote:
Originally Posted by
Ion Zone
Thanks for the advice. Maybe a multi-choice text-based adventure would be a good start. Type '1' to hit the rat with the stick. Type '2' to flee like a little girl. ;) Then later on, I could give it a proper background and maybe add a couple of pictures and a health bar.
What do you think?
Good idea. So maybe in a year or two it will grow into a Fallout series :)
Start small and grow as you go. That's the only way to do it. And you can ask people on this forum for a specific advice with C++ code if you get stumped.
Re: Learning to use Microsoft Visual C++
By the way, just curious, but is it very difficult to have a program set up so that you have a 2D game reading map, monster, save, item information, etc, from external files? (I'm just thinking it would be an awful lot easier to make, say, a top-down RPG, if you had a separate editor program.)
Re: Learning to use Microsoft Visual C++
Quote:
Originally Posted by
Ion Zone
By the way, just curious, but is it very difficult to have a program set up so that you have a 2D game reading map, monster, save, item information, etc, from external files? (I'm just thinking it would be an awful lot easier to make, say, a top-down RPG, if you had a separate editor program.)
What you're referring to may be called a game engine. If you write your own, it may be a very time consuming operation and for many well established video game companies it is a closely guarded secret. But maybe there are some that can be open for public: check some here. I'm not sure though, I never looked into it.
PS. You need to start small though. Maybe create a simple console application and make a numbers game. Or a question-answer type of game using text without any complex graphics.
Re: Learning to use Microsoft Visual C++
Re: Learning to use Microsoft Visual C++
I also want to learn C++ game programming and this is my approach. I'm an intermediate Visual Basic programmer(still learning VB) and have taken C++ classes in school. The way I'm learning VB besides having worked with it for a few years and have taken classes is by writting small simple programs that I have an interest in. I figured it would be best to be comfortable with the C++ language before getting into game programming. And the best way to get proficient with Visual C++ would be to write lots of small programs. I'm reading "murach's C++ 2008" -Prentiss Knowlton which has been a good read and so far. It got me going. Before the book I had college C++ skill but didn't know how to apply my new knowledge in the Visual Studio C++ environment. But this book bridges the gap nicely. It's not a game programming book but at least now I can learn the language like the way I like to which is by writting something not so boring. I can now finally do something with Visual Studio C++. So now I have the ability to start experimenting on writting silly little programs. They may be short and somewhat useless but they will be the building block of bigger and better things like tackling a game programming book. So anyway that's my approach which I wanted to share with you guys.
Re: Learning to use Microsoft Visual C++
Quote:
Originally Posted by
viperbyte
I also want to learn C++ game programming and this is my approach...
Good point, viperbyte. Although, I would not recommend using Visual Basic for serious game development. I might open a new can of worms with my next statement, but that language is used mostly for the Microsoft-specific Office document extensions/scripts and web programming with ASP.NET. Which has nothing to do with games. It also has an altogether different or simplified syntax than C/C++, which is not always a good thing.
In case you really want to learn C/C++ from scratch using a game example you can follow these (VERY simplified) steps:
1. Learn the basic C types: int, char, bool, float, etc. Then the concept of variables and arrays.
2. Learn what pointers are and how to handle them. (Quite a daunting task for a beginner.)
3. Learn what classes, structs, enums, class members and functions/methods are.
4. Then you may want to switch to the next step, i.e. C++ concepts, that are extensions of C. They will help you deal with strings and templates.
6. When that is done, you can switch to understanding the concepts of memory management. In this case you narrow your study down to Microsoft's memory management principles.
7. Learn what files and folders are from the standpoint of the Operating System and how to manage those.
8. You may want to go into more depth and look into what threads and processes are.
When you muster all of the above you will be ready to code your simplest game. You can start with a text-based Miss Packman type game. All you need for it is this:
A. Console application that can be created in the Visual Studio C++ environment.
B. All you need are walls that you can use | and - symbols for, spaces will constitute passages. Then the Packman can be 'C' and enemies 'X' or '#'. And dots will be represented, good you guessed it, by . symbols.
C. For the sake of learning you don't need to make it run in real-time. Adapt the concept of the Fallout 1 game when objects in the game move one after another. This will help you to debug your game.
D. The most challenging part for you would be to create an Artificial Intelligence or AI in your game -- or the code that will move 'X' and '#' after your protagonist 'C'. That was the most daunting part for me. The reason being is that if you code it with a strict logic to follow 'C' at a straight line your player will most always lose and the game will not be interesting. So, you will need to put some 'human' qualities into your 'X' and '#', so that they made mistakes once in awhile and didn't always catch 'C'. That would be the beginning.
E. When that is done and you can actually play your own game and be somewhat interested in it, you'll accomplish the first major milestone an be ready to put more interactivity into it, as well as graphics and possibly, way later some 3D stuff.
Good luck!
Re: Learning to use Microsoft Visual C++
Thank you everyone!
This is basicly just a mock-up made using C++, but I intend to build on it as I learn more. Unfortunately, the code I'm using is quite clunky and I'm having some trouble. Here's a screenshot!
http://i467.photobucket.com/albums/r...one/Mockup.jpg
First and worst - I don't seem to be able to maximise the program (Quests got cut off :P ), if I press maximise it only covers about a third of the screen. :P This is a real pain as it means zero immersion. >.<
Also to turn the key letters red, I had to do this:
Code:
#include <iostream>
#include <string>
#include <windows.h>
Code:
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 4);
cout << "(I) ";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
cout << "Inventory - ";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 4);
cout << "(M) ";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
cout << "Cast Magic - ";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 4);
cout << "(A) ";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
cout << "Actions - ";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 4);
cout << "(C) ";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
cout << "Char - "; //cout << Name << -; Character's name inserted with string
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 4);
cout << "(E) ";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
cout << "Equipment - ";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 4);
cout << "(Q) ";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
cout << "Quest\n\n";
Which is a pest!
Is there any way to make this a 'standard' piece of code that I can insert like a string? It would be really handy if I could just tack it on with one line of code instead of pasting that whole chunk every time I describe something. Would make things ten times easer! ;) Though if anyone knows a way of changing text colour (can you change font size and style? Times Roman would be easier on the eye.) in the middle of a line that would be just as helpful. Also, is there an include I can do to get symbols like £, €, and (especially) ¥ (yen), to show up (I want to use it as a currency counter)?
Re: Learning to use Microsoft Visual C++
OK. You're getting a bit ahead of yourself.
The rule number one is that you plan ahead before you plunge into coding. I understand right now you may have a practice run, but in the future always plan ahead how you will implement all of the features in your code.
Quote:
Originally Posted by
Ion Zone
Unfortunately, the code I'm using is quite clunky and I'm having some trouble
I'm not going to write it all for you, but here are some corrections to what you said:
1. You need to use variables and functions or even better create a class. All that will help you minimize the efforts needed to program it. You see someone has made those things up not to annoy you in different books but to actually make your life simpler.
Quote:
I don't seem to be able to maximise the program (Quests got cut off :P )
2. You need to get used to live with what you currently have. A console window has a certain size, which you can learn by calling GetConsoleScreenBufferInfo and check the CONSOLE_SCREEN_BUFFER_INFO::dwMaximumWindowSize that will give you the boundaries of it. In your case you need to format your output in accordance with those boundaries.
3. Use preprocessor values instead of simple numbers. Otherwise the code you write will not be readable and you may run into more troubles when porting it.
For instance this:
Code:
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 4);
should've been this:
Code:
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED);
Quote:
can you change font size and style?
4. Yes you can, but I wouldn't complicate your life with it at this point. If you still want to do it, check SetCurrentConsoleFontEx
Quote:
Also, is there an include I can do to get symbols like £, €, and (especially) ¥ (yen)
5. First off, you need to build your project as Unicode (which you may be already doing by default if you're using MS VS 2008). Then you can look up your character's Unicode value here and use it like this (for the sample code you'll find below):
Code:
//Unicode value for Yen sign is U+00A5
PrintTextInPos(hCons, _T("The cost is \u00A5100"), 16, 8);
So here's how one of the versions of your code could've looked like (Note that there are many ways to do it):
Code:
#include "stdafx.h"
#include <iostream>
#include <string>
#include <windows.h>
using namespace std;
bool PrintTextInPos(HANDLE hConsole, LPCTSTR pText, int x, int y, WORD wAttributes = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED);
int _tmain(int argc, _TCHAR* argv[])
{
HANDLE hCons = GetStdHandle(STD_OUTPUT_HANDLE);
//Place "Hello"
PrintTextInPos(hCons, _T("Hello"), 6, 10);
//Place "World"
PrintTextInPos(hCons, _T("World"), 16, 10, FOREGROUND_RED | BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED);
//Wait for user input before closing the console
getchar();
return 0;
}
bool PrintTextInPos(HANDLE hConsole, LPCTSTR pText, int x, int y, WORD wAttributes)
{
//Print text from 'pText' at the 'x' and 'y' position in the 'hConsole' console with 'wAttributes' attributes
//For the reference of attributes check:
//http://msdn.microsoft.com/en-us/libr...ter_attributes
//Returns:
// - true = if success
bool bResult = false;
//Get console information
CONSOLE_SCREEN_BUFFER_INFO csbi = {0};
if(GetConsoleScreenBufferInfo(hConsole, &csbi))
{
//Set cursor position
COORD coord = {x, y};
if(SetConsoleCursorPosition(hConsole, coord))
{
//Set text & background color
if(SetConsoleTextAttribute(hConsole, wAttributes))
{
//Output text
DWORD dwchWritten;
WriteConsole(hConsole, pText, lstrlen(pText), &dwchWritten, NULL);
//Done!
bResult = true;
}
}
//Restore cursor position & attributes
SetConsoleCursorPosition(hConsole, csbi.dwCursorPosition);
SetConsoleTextAttribute(hConsole, csbi.wAttributes);
}
return bResult;
}
Re: Learning to use Microsoft Visual C++
Quote:
OK. You're getting a bit ahead of yourself.
I know it does seem like that but that is really just me experimenting with code - there's nothing else in that file except a quoted out maths program. I haven't gotten up to classes yet, so I haven't experimented with them. Mainly I plan things by doing stuff like that. It generally lets me work out problems before I have loads of them to fix. ;) I'll do that loads of times with loads of different bits of code.
Quote:
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
Tried using this (with added 'foreground intensity') but I don't think it's the same colour, does this mean I can set the intensity?
Quote:
#include "stdafx.h"
Tried to run your code but it couldn't find this library. (Compiler is Microsoft V 2008.) Is it something I have to download? Thanks for all your help though!
Re: Learning to use Microsoft Visual C++
Quote:
Originally Posted by
Ion Zone
Tried using this (with added 'foreground intensity') but I don't think it's the same colour, does this mean I can set the intensity?
I believe so. The color range available to a console application is very limited, but that is just something for you to begin learning with.
Also, do you realize that you can combine colors, for instance FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED will result in a white color and so on.
Quote:
Originally Posted by
Ion Zone
Tried to run your code but it couldn't find this library. (Compiler is Microsoft V 2008.) Is it something I have to download? Thanks for all your help though!
No, you don't have to download it. If it gives you headache, remove it, it's probably already included in your project.