Address 2 Amusement Programming Arranging your Diversion Improvement Workstation

2660 days ago, 990 views
PowerPoint PPT Presentation ... filled circle that shows up in the focal point of the screen and at first moves ...

Presentation Transcript

Slide 1

´╗┐Address 2 Game Programming Configuring your Game Development Workstation Lecture 2 Game Programming Configuring your Game Development Workstation

Slide 2

Selecting an Operating System We will utilize standard C/C++ for our scripting language and open-source apparatuses, for example, Allegro. In this manner you are welcome to utilize any working framework you incline toward. The notes of this course will be utilize illustrations utilizing Windows XP/Vista, however all tasks ought to be transportable to Linux without adjustment. The adaptation of Allegro utilized as a part of the cases makes utilization of DirectX, however is straightforward to the software engineer. Allegro executes a similar usefulness in each environment utilizing the local illustrations primitives accessible. Microsoft Windows Linux Mac OS X Solaris BeOS FreeBSD

Slide 3

Selecting a Compiler/IDE Since we will utilize standard C/C++ and Allegro we have chosen Dev-C++ created by Bloodshed accessible at .

Slide 4

Selecting a Gaming Software Library We will utilize Allegro 4.2 in our diversion programming cases. Executions for this variant of Allegro are accessible locally at: Useful Links

Slide 5

Configuring Dev-C++ 1. Run the installer devcpp- on your diversion improvement PC. 2. Duplicate the record into the C:\Dev-Cpp (expecting you made the default area in Stride 1) and unfasten it. 3. Duplicate the documents in the Allegro lib index into the Dev-Cpp/lib registry. 4. Duplicate the documents in the Allegro incorporate index into the Dev-Cpp/incorporate registry. 5. Duplicate the DLLs in the Allegro canister catalog into Windows/System32 registry. 6. Begin Dev-Cpp and make a New Project called Test_Allegro or comparable. This ought to be a void venture. 7. Make and spare a source record named main.cpp for this venture. Compose or duplicate the specimen program on the following slide into main.cpp . 8. Under venture choices, change the venture Type to Win32 GUI. also, include the reference - lalleg to the Linker choices under the Parameters tab. 9. Run/Debug your first Allegro Dev-Cpp program...

Slide 6

Sample Program Test_Allegro #include <allegro.h> int primary( void ) { allegro_init(); set_gfx_mode(GFX_SAFE, 640, 480, 0, 0); install_keyboard(); textout_ex(screen,font, "Hello World!" ,1,1,10,- 1); textout_ex(screen, textual style, "Press ESCape to quit." ,1,12,11,- 1); while (!key[KEY_ESC]); allegro_exit(); return 0; } END_OF_MAIN()

Slide 7

The First Game Pong was the main computer game, so we will make it our first programming exercise. 1. Make an Allegro GUI Project 2. Utilize strong (filled) rectangles as the oars. Actualize paddle movement for left and right oars utilizing the "An" and "Z" keys for the left oar and the "K" and "M" keys for the right oar. 3. Make a ball utilizing a filled circle that shows up in the focal point of the screen and at first moves on a level plane to one side or the right (substitute). 4. Decide a bob work for the ball off the oars that is an element of the speed of the oar when reached by the ball. 5. Incorporate a straightforward ricochet work for the top and base of the screen to keep the ball in play. 6. Include keys for begin amusement, and quit diversion and a legend depicting their capacity. 7. Incorporate a score-board and component for closure the diversion when one of the players achieves a score of 11. 8. Add sound to your diversion. 9. Include any elements you feel enhance your amusement.

Slide 8

Game Space Layout (SCREEN_W,0) (0,0) keep up 4 to 3 angle proportion (0,SCREEN_H) (SCREEN_W,SCREEN_H)

Slide 9

#include <allegro.h> #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 characterized by Allegro set_gfx_mode( ). You ought to utilize these parameters to put your diversion protests so that screen determination can be effortlessly changed.

Slide 10

Handling Player Input install_keyboard(); : if(key[KEY_A]) padLeftY - = padVy; if(key[KEY_Z]) padLeftY += padVy; if(key[KEY_K]) padRightY - = padVy; if(key[KEY_M]) padRightY += padVy; Allegro capacity install_keyboard( ) introduces console input. In the fundamental amusement circle you ought to utilize a progression of if( ) articulations to test for key presses as opposed to a switch( ) build, since you need to recognize if more than one key has been squeezed in a solitary go through the diversion circle. The position of a portable question can be controlled by including or subtracting a settled speed, padVy.

Slide 11

Checking Game Space Limits (0,0) ? if(padLeftY<padHeight/2) padLeftY = padHeight/2; if(padLeftY>SCREEN_H - padHeight/2) padLeftY = SCREEN_H - padHeight/2; if(padRightY<padHeight/2) padRightY = padHeight/2; if(padRightY>SCREEN_H - padHeight/2) padRightY = SCREEN_H - padHeight/2; padHeight padLeftY After player inputs have been taken care of the new places of the portable items should be checked to guarantee that they are inside the amusement space limits. What to do to keep the items inside the amusement space relies on upon the question's capacity. For the oars, you can simply supplant the new position with the constraining position as though it has hit a limit.

Slide 12

diversion circle init factors quit amusement ? init allegro new diversion ? spare old positiions init amusement state ball at top or base ricochet ball leave allegro ball hit paddle return ball miss paddle score & reset redesign scoreboard players input paddles at top or base stop paddle enliven end circle Pong Game Block Diagram