| |||||||||||
|
Main Menu Other |
Intro to Constants | ||||||||||
|
Quick Intro to Constants (con't)Here's some examples of constants you might use in a game. // gamestate constants const int GS_NORMAL = 1; const int GS_TITLESCREEN = 2; // titlescreen constants const int TS_MAIN = 0; const int TS_LOAD = 1; const int TS_SAVE = 2; const int TS_OPTIONS = 3; const int TS_EXIT = 98247; This is just a quick example of constants for tracking the current game state. The numbers we set them to don't matter whatsoever. They can be anything, just as long as there isn't another similar constant with the same number. For example, your program doesn't have to care that TS_EXIT is ludicrously high. Just use TS_EXIT throughout your program and it always means TS_EXIT, no matter what number it's set to. Then when looking at your code you can obviously see what the constants are for, but you don't need to know the number it represents. Easy, huh? Now if you have gamestate constants, you'll have to have a int GameState variable. In your game, you can set I hope this tutorial has been helpful. Let me know if you thought anything in it was confusing or made no sense. And if so I'll just laugh at you. =P
|
|||||||||||