This framework is to help students on the SP1 module to get started quickly on their projects. This framework only works on the Windows environment as it uses Windows API in some of its features.
- Game loop
- Key press detection
- Go to a certain console coordinate
- Colours in console
- Frame rate limiter
- Team leader should fork this project into their own repository
- Add your team mates as collaborators
- Read and understand the code
- Team leader should add this repository as a upstream remote repository if you want to get the latest bug fix or improvements. Configuring a remote for a fork
- Periodically sync changes to this repository to get latest awesome code. Syncing a fork
- Start working on your project! Remember to commit often!
The framework is a basic bare bones implementation of a game loop. You should not mess around with the main files unless you know what you are doing.
There are certain functions that you should be implementing.
Initializes the game variables, load data, allocate memory, etc. Code that should run before the game starts should be here.
Detects input from input sources, e.g. keyboard. This is where you detect if the user has given any input to the game, and set your flags accordingly.
This is the meat of your code, the game logic should be done here. i.e. reaction to input, enemy movement, enemy spawning, win game condition, lose game condition, state of game, etc. Sounds can be played here.
Renders the current state of game onto screen. Go to a specific coordinate on the screen, set colours, write output, etc.
Code for cleaning up of game, writing of files, close files, free up memory, etc.
There are 2 types of console functions, one that uses that std::cout, and one that uses the Console object.
For beginners, the functions that work with std::cout is more suitable as they are more familiar.
If you experience flickering of the screen, that is because the output is flushed to the std output every time it is written. Hence, a faster way is to write the output to a buffer, and flushed at the end of the render() loop.
The following functions might need a console object to be instantiated and then you can call these functions. Needless to say, these functions are going to be deprecated and you should not be using them.
Go to a specific location on the screen and writes to the std output from there. Origin is top left.
Sets a specific colour to be used in the next call to std::cout.
Clears the screen with the last colour attribute set.
You will only need to create one console object, and use this one true object in your code for all the console output.
Inits the console size, and give it a title, pass in a C-Style string
Gets the console size, in a COORD struct.
Sets the console title
Sets the console font. You can set the width and height of the raster fonts. If you are using a TrueType font, you can use the height as the font size.
Clears the data buffer, hence "clearing the screen", preparing for new data.
The origin of the screen is on the top left. These 6 functions writes to the buffer at that coordinate, you can use C-Style strings, C++ string class or a char. The attribute is a optional parameter. The last 3 functions are overloaded versions of the first 3 functions.
Call this at the end of the render() function so that the contents of the buffer will be displayed onto the screen.
How do I set the size of the console?
The console size is set in the constructor of the console object. See the sample code to see how this is done. Note that if you tried to set an invalid size, the size of the console will be set to a default size, and you will get an error message.
The screen flickers!
It could be due to too much flushing of the buffer to the screen. Make sure that there is no std::cout functions called in your code. You should be clearing the buffer only once. You should be flushing the buffer to the console only once.
Unicode
Right now, there is no support for unicode, but talk to me if you really need unicode, and we see if we can try out some stuff.
- Do not write all your code in just the files provided. Create your files, write your code in your own files and call your functions.
- Each functionality should be in its own file, this will make it easier for you to merge changes later.
- Pass in the data you need into your function, do not use global variables unnecessarily.
- Talk to your teammates, keep them updated, and informed, especially if you have difficulties.
- Try not to have more than 1 person working on the same file, or even worse, same function.
- One commit for one functionality
- Mega commits are frowned upon. It might kill your project. -
- Commit often, commit early