Lecture 2 Game Programming Configuring your Game Development Workstation. Lecture 2 Game Programming Configuring your Game Development Workstation. Selecting an Operating System.
Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.
Configuring your Game
Configuring your Game
We will be using standard C/C++ for our computer language and open-source tools such as Allegro. Therefore you are welcome to use any operating system you prefer.
The notes of this course will be use examples using Windows XP/Vista, however all projects should be transportable to Linux without modification.
The version of Allegro used in the examples makes use of DirectX, but is transparent to the programmer. Allegro implements the same functionality in every environment using the native graphics primitives available.
Since we will be using standard C/C++ and Allegro we have selected Dev-C++ developed by Bloodshed available at http://www.bloodshed.net/dev/devcpp.html.
We will be using Allegro 4.2 in our game programming examples. Implementations for this version of Allegro are available locally at:
Other Useful Links
1. Run the installer devcpp-220.127.116.11_setup.exe on your game development computer.
2. Copy the mingw-4.2.0.zip file into the C:\Dev-Cpp (assuming you took the default location in Step 1) and unzip it.
3. Copy the files in the Allegro lib directory into the Dev-Cpp/lib directory.
4. Copy the files in the Allegro include directory into the Dev-Cpp/include directory.
5. Copy the DLLs in the Allegro bin directory into Windows/System32 directory.
6. Start Dev-Cpp and create a New Project called Test_Allegro or similar. This should be an empty project.
7. Create and save a source file named main.cpp for this project. Write or copy the sample program on the next slide into main.cpp.
8. Under project options, change the project Type to Win32 GUI. and add the reference -lalleg to the Linker options under the Parameters tab.
9. Run/Debug your first Allegro Dev-Cpp program...
set_gfx_mode(GFX_SAFE, 640, 480, 0, 0);
textout_ex(screen, font, "Press ESCape to quit.",1,12,11,-1);
Pong was the first video game, so we will make it our first programming exercise.
1. Create an Allegro GUI Project
2. Use solid (filled) rectangles as the paddles. Implement paddle motion for left and right paddles using the 'A' and 'Z' keys for the left paddle and the 'K' and 'M' keys for the right paddle.
3. Create a ball using a filled circle that appears in the center of the screen and initially moves horizontally to the left or the right (alternate).
4. Determine a bounce function for the ball off the paddles that is a function of the velocity of the paddle when contacted by the ball.
5. Include a simple bounce function for the top and bottom of the screen to keep the ball in play.
6. Add keys for start game, and quit game and a legend describing their function.
7. Include a score-board and mechanism for ending the game when one of the players reaches a score of 11.
8. Add sound to your game.
9. Add any features you feel improve your game.
maintain 4 to 3 aspect ratio
#define BLACK makecol(0,0,0)
#define GREEN makecol(64,255,64)
#define RED makecol(255,64,64)
#define YELLOW makecol(255,255,64)
int padLeftX, padRightX;
int padLeftY, padRightY;
int padLeftYold, padRightYold;
int padWidth = 6;
int padHeight = 40;
int padVy = 4;
padLeftX = 20;
padRightX = SCREEN_W - 20;
padLeftY = SCREEN_H/2;
padRightY = SCREEN_H/2;
int ret = set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0);
Initializing Game Parameters
The parameters SCREEN_W and SCREEN_H are defined by Allegro set_gfx_mode( ). You should use these parameters to place your game objects so that screen resolution can be easily changed.
padLeftY -= padVy;
padLeftY += padVy;
padRightY -= padVy;
padRightY += padVy;
Allegro function install_keyboard( ) initializes keyboard input.
In the main game loop you should use a series of if( ) statements to test for key presses rather than a switch( ) construct, since you want to detect if more than one key has been pressed in a single pass through the game loop.
The position of a movable object can be controlled by adding or subtracting a fixed velocity, padVy.
padLeftY = padHeight/2;
if(padLeftY>SCREEN_H - padHeight/2)
padLeftY = SCREEN_H - padHeight/2;
padRightY = padHeight/2;
if(padRightY>SCREEN_H - padHeight/2)
padRightY = SCREEN_H - padHeight/2;
After player inputs have been handled the new positions of the movable objects need to be checked to ensure that they are within the game space limits. What to do to keep the objects inside the game space depends on the object's function. For the paddles, you can just replace the new position with the limiting position as if it has hit a boundary.
save old positiions
init game state
ball at top or
ball hit paddle
ball miss paddle
score & reset
paddles at top