IntroductionOn this page I will help you with programming using C++, but first just a little bit of background information about my programming experience. I have programmed as a hobby for many years on different types of computers using BASIC, assembly language and C/C++.
BASIC is fine for beginners and for performing simple tests but it's often not advanced enough or fast enough to create software such as a game. I used to use QBASIC which came with versions of DOS which was good but the best version is Visual BASIC, also by Microsoft.
I have used assembly programming on a 6502 CPU using microcomputers, on the Amiga 68000 processor, on a Z80 CPU and the MIPS processor used in the N64 (some of my more advanced game codes are actually short programs). Assembly language gives you great control over the hardware and some time ago it was the only option for creating some types of software. But now I use it a lot less since it takes longer to make programs with and you are more likely to make mistakes.
I'll admit that I wasn't that keen to try out C++ although I knew it was about the best to use between BASIC and assembly language. But I got myself a Borland compiler that was designed for Windows 3.1 and 95 but amazingly I have got it working on Windows 98, 2000 and XP (not in compatibility mode!). I now know C/C++ very well and have written all sorts of programs using it including games and utilities.
Then there came a turning point for me; I had used the Borland compiler to program 2D games that used DirectDraw and wanted to move onto 3D yet there was the worry that I would have trouble getting Direct3D to work on the Borland compiler. I thought to myself that if any compiler should have no trouble with DirectX it should be a Microsoft compiler. So, almost with a tear in my eye I said goodybye to the Borland compiler and hello to Visual C++ (actually I still use the Borland compiler on another, older, computer of mine).
I wouldn't say that I made a mistake in downloading Visual C++ especially as it was the free version but it has been quite a pain to use. I like the compiler, particularly its ability (most of the time) to help you out by providing a list of member variables and functions that belong to a class and its IDE has been done well. But I have had many errors when using it thanks to its strict version of C++ and due to the support for managed code. I'm now writing programs when I can in only managed code as in theory that should mean better programming and less chance of errors but it requires that you have the .NET framework, something to remember if you give a managed program to someone else to try out.
As for Direct3D it worked with Visual C++ but I had much trouble getting it to work, and ended up settling for a slightly lower version than what my system was capable of (which wasn't a totally bad thing). And I ended up mixing native and managed code just so I could actually get on with progrmming my game.
DebuggingNo programmer is perfect and so there will be times when errors will show up while your program is running. Some problems can be fixed without much trouble but other will require debugging as to spot the mistakes in the code.
If you have a good idea what part of your program causes the error then you can set up a breakpoint which will pause your program at a particular point in your code (where the breakpoint is placed). When this happens you can then examine the state of the variables and step through each statement one at a time to more clearly see how your program behaves. Note that while you can have more than one breakpoint set at a time, there are certain places you cannot place a breakpoint such as where no code is generated (e.g., a comment).
Typical compilers offer several options as to how to carry on execution of your code when a breakpoint is reached. The key difference between the step over and step into options is that step over executes function calls as if they were a single statement but step into lets you step through each statement of the function. You can also choose to continue program execution until a breakpoint is reached again of stop the program completely.
Common tasksHere I will talk about programming common tasks needed to do by a typical program, and how to do them using Visual C++ and managed code.
Colour Palette
When most people think of a colour palette of the computer type, Microsoft's Paint program usually pops into their head. You too can have your own colour palette in your application without much effort.
Add to your program's form a ColorDialog component from the toolbox- note that it will appear in a separate section from the form-and be sure to name it something sensible such as colours. To get it to show up while your program is running, use the ShowDialog() member function:
colours->ShowDialog();
The user can then select a colour but you will need to check if he or she actually clicked on OK, using code such as:
if (colours>ShowDialog ()==System::Windows::Forms::DialogResult::OK)
If the user did click on OK then you can get the colour that was chosen, so for example, you could assign the colour that was picked to the form's background colour:
this->BackColor=colours->Color; Solving Common Errors(Added: 18/11/9) Visual C++ Catastrophic Failure Error: When you are using Visual C++ and you try to load the form designer you get the error Catastrophic Failure... Solution: Delete the intellisense file for your project and then reopen the form designer. Label Does Not Update Error: ToolStripStatusLabel text doesn't update while the application is doing heavy processing. Solution: After changing the text of the ToolStripStatusLabel, call the Refresh() method of the StatusStrip component that owns the ToolStripStatusLabel. Note: this may work for other components as well. | New: Added Solving Common Errors Added Debugging.
You can email me at james.boshikoopa@gmail.com
You may also like Program Your Own Video Game. |