Presentation is loading. Please wait.

Presentation is loading. Please wait.

VIDEO GAME PROGRAMMING Video Game Programming Level One – Breakout INSTRUCTOR Big Dan Teague TEACHER’S ASSISTANT Delmar O'Donnell.

Similar presentations


Presentation on theme: "VIDEO GAME PROGRAMMING Video Game Programming Level One – Breakout INSTRUCTOR Big Dan Teague TEACHER’S ASSISTANT Delmar O'Donnell."— Presentation transcript:

1 VIDEO GAME PROGRAMMING Video Game Programming Level One – Breakout INSTRUCTOR Big Dan Teague TEACHER’S ASSISTANT Delmar O'Donnell

2 VIDEO GAME PROGRAMMING PART 1 – BRIX BASICS Objective: –Create the Splash Screen and have it display for 3 seconds before the Main Menu is displayed. Step 1 – Game Properties Step 2 – Timer Step 3 – Splash Screen Step 4 – Save and Test

3 VIDEO GAME PROGRAMMING CONCEPT – File Formats A file format is the way data is encoded for different types of files. Some common file formats are.bmp,.gif,.txt,.doc,.mp3 and.wav Images in Fun are.bmp (Bitmaps) and sounds are.wav (WAVE form audio format).

4 VIDEO GAME PROGRAMMING STEP 1: Set Up the Game Properties Right-click on Game and select Properties. Select 640x480 in the Resolution menu. Select True Color (32 bit) from the Color Bit- Mode. Set the Compiler to the compiler currently installed on the computer. In the Window Title text box enter Brix (your name). Click OK.

5 VIDEO GAME PROGRAMMING Step 2: Create the Timer Function Right-click Object Functions and Select Add. Enter MyTimer in the name box. Click on the Timer button and check the Activate Timer box. Set the timer for 3000 Milliseconds, select Run Once at the bottom and then click OK. Change Used By to Levels, then enter the following code and save.

6 VIDEO GAME PROGRAMMING MyTimer Code myGame->LevelName("MainMenu");

7 VIDEO GAME PROGRAMMING STEP 3: The Splash Screen Add The Level: –Right-click on the first level listed below Game and select Rename. –Enter SplashScreen in the box that pops up and then click on OK.

8 VIDEO GAME PROGRAMMING MAP: Set up the Map: –Expand the SplashScreen Level. –Right-click on Maps and select Add. –Enter Splash_Screen for the name. –Browse for the map file and select –Brix\Art Assets\Maps\Brix_Splash_Screen.bmp –Now click OK to close the map properties window.

9 VIDEO GAME PROGRAMMING LEVEL BEHAVIORS Set the Level Behaviors: –Right-click SplashScreen and select Properties. –In the Level Properties window click on the Behavior tab. –Add the MyTimer function to the list.

10 VIDEO GAME PROGRAMMING STEP 4: Save and Test Save the Project: –Click on Project and Save. Run the Project: –Click on the Build/Run button in the menu bar. Results: –Splash screen should display.

11 VIDEO GAME PROGRAMMING PART 2 – BRIX MENUS Objective: –Create the Main Menu and detect mouse over collisions and mouse click collisions with buttons on the menu. Step 1 – Start and Exit Buttons Step 2 – Cursor and Cursor Functions Step 3 – Main Menu Step 4 – Save and Test

12 VIDEO GAME PROGRAMMING CONCEPT – Actors vs Sprites Actors are the visual representations of the characters in FUN games. Sprites are considered to be living creatures that live, move and die during the game. Actors only define the shape that Sprites take to be represented in the game.

13 VIDEO GAME PROGRAMMING STEP 1: Start and Exit Buttons Add the Actor: START_BUTTON –Right-click Actors and Select Add. –Enter START_BUTTON in the dialogue box and click ok. Add the Actor: EXIT_BUTTON –Right-click Actors and Select Add. –Enter EXIT_BUTTON in the dialogue box and click ok.

14 VIDEO GAME PROGRAMMING CONCEPT – Animation An animation is a sequence of one or many frames that visually represent an action such as walking, shooting etc… In Fun Animation Sets make up Actors.

15 VIDEO GAME PROGRAMMING START BUTTON: Add the Animation: START_BUTTON –Right-click on the START_BUTTON actor and select Add Animation Set. –In the Control that comes up Enter the name of the animation MAIN_MENU_START1 in the text box at the top. –Click on Add to bring up the dialogue box for choosing the frame art. –Select Brix\Art Assets\Actors\ Brix_Menu_Start1.bmp –Click ok.

16 VIDEO GAME PROGRAMMING START BUTTON: CONTINUED Add the Second Animation: START_BUTTON –Right-click on the START_BUTTON actor and select Add Animation Set. –In the Control that comes up Enter the name of the animation MAIN_MENU_START2 in the text box at the top. –Click on Add to bring up the dialogue box for choosing the frame art. –Select Brix\Art Assets\Actors\ Brix_Menu_Start2.bmp –Click ok.

17 VIDEO GAME PROGRAMMING EXIT BUTTON: Add the Animation: EXIT_BUTTON –Right-click on the EXIT_BUTTON actor and select Add Animation Set. –In the Control that comes up Enter the name of the animation MAIN_MENU_EXIT1 in the text box at the top. –Click on Add to bring up the dialogue box for choosing the frame art. –Select Brix\Art Assets\Actors\ Brix_Menu_Exit1.bmp –Click ok.

18 VIDEO GAME PROGRAMMING EXIT BUTTON: CONTINUED Add the Second Animation: EXIT_BUTTON –Right-click on the EXIT_BUTTON actor and select Add Animation Set. –In the Control that comes up Enter the name of the animation MAIN_MENU_EXIT2 in the text box at the top. –Click on Add to bring up the dialogue box for choosing the frame art. –Select Brix\Art Assets\Actors\ Brix_Menu_Exit2.bmp –Click ok.

19 VIDEO GAME PROGRAMMING CONCEPT – Game Loop A game loop is code that executes repeatedly throughout a game and deals with taking input from the user or other systems, then updates the objects in the game and finally renders the resulting objects to the screen.

20 VIDEO GAME PROGRAMMING STEP 2: Cursor and Cursor Functions Add the Actor: –Right-click Actors and Select Add. –Enter CURSOR in the dialogue box and click ok.

21 VIDEO GAME PROGRAMMING THE CURSOR Add the Animation: –Right-click on the CURSOR actor and select Add Animation Set. –In the Control that comes up Enter the name of the animation ARROW in the text box at the top. –Click on Add to bring up the dialogue box for choosing the frame art. –Select Brix\Art Assets\Actors\Brix_Cursor_Arrow.bmp and click ok.

22 VIDEO GAME PROGRAMMING CURSOR: Object Function Detect_Mouse_Over_Buttons Use: –Detect when the cursor is over a sprite and change the animation for that sprite when it is. Add the Object Function: Mouse Over –Right-click Object Functions and Select Add. –Enter Detect_Mouse_Over_Buttons in the name box. –Click on the Used By drop down menu and select Cursor. –Enter the following code and save.

23 VIDEO GAME PROGRAMMING Detect_Mouse_Over_Buttons SpritePTR Start_Button( “Start_Button” ); SpritePTR Exit_Button( “Exit_Button” ); if ( pFunCursor->CollisionWithSprite( “Start_Button” ) ) Start_Button->Animation(1); else Start_Button->Animation(0); if ( pFunCursor->CollisionWithSprite( “Exit_Button” ) ) Exit_Button->Animation(1); else Exit_Button->Animation(0);

24 VIDEO GAME PROGRAMMING CURSOR: Object Function Detect_Mouse_Click_On_Buttons Use: –Detect when the user clicks on a sprite and load Level 1 or exit the game accordingly. Add the Object Function: Mouse Click –Right-click Object Functions and Select Add. –Enter Detect_Mouse_Click_On_Buttons in the name box. –Click on the Used By drop down menu and select Cursor. –Enter the following code and save.

25 VIDEO GAME PROGRAMMING Detect_Mouse_Click_On_Buttons if ( pFunCursor->IsPressedOnSprite( “Start_Button”, DIM_LEFT) ) myGame->NextLevel(); else if ( pFunCursor->IsPressedOnSprite( “Exit_Button”, DIM_LEFT) ) myGame->EndGame();

26 VIDEO GAME PROGRAMMING STEP 3: The Main Menu Add The Level: –Right-click Game and select Add Level. The added level will pop up at the end of the list of levels. –Right-click on the new level and select Rename. –Enter MainMenu in the box that pops up and then click on OK.

27 VIDEO GAME PROGRAMMING MENU CURSOR Set up the Cursor: –Expand the MainMenu Level. –Right-click on Cursor and select Add. –Uncheck the Use Default check box and select CURSOR from the Actor drop down menu. –Now add the Detect_Mouse_Over_Buttons and Detect_Mouse_Click_On_Buttons functions to the Behaviors. –Click OK to close the cursor properties window.

28 VIDEO GAME PROGRAMMING MAP: Set up the Map: –Right-click on Maps and select Add. –Enter Main_Menu for the name. –Browse for the map file and select –Brix\Art Assets\Maps\ Brix_Main_Menu.bmp –Now click OK to close the map properties window.

29 VIDEO GAME PROGRAMMING SPRITES: Start_Button Add the Sprite: Start Button –Right-click on Sprites and select Add. –Enter Start_Button for the name. –Select Main_Menu for the map. –Click on the Animation tab and select START_BUTTON for the actor. –Now click on the Collision tab and check the Activate Sprite Collision check box. –Click on the Position tab and position the Start_Button. –Now click OK to close the sprite properties window.

30 VIDEO GAME PROGRAMMING SPRITES: Exit_Button Add the Sprite: Exit Button –Right-click on Sprites and select Add. –Enter Exit_Button for the name. –Select Main_Menu for the map. –Click on the Animation tab and select EXIT_BUTTON for the actor. –Now click on the Collision tab and check the Activate Sprite Collision check box. –Click on the Position tab and position the Exit_Button. –Now click OK to close the sprite properties window.

31 VIDEO GAME PROGRAMMING STEP 4: Save and Test Save the Project: –Click on Project and Save. Run the Project: –Click on the Build/Run button in the menu bar. Results: –Splash screen should display and then load the Main Menu after 3 seconds.

32 VIDEO GAME PROGRAMMING PART 3 – BRIX LEVEL 1 Objective: –Create Level 1 complete with the bricks, paddle and ball. Step 1 – Bricks, Paddle and Ball Step 2 – My Functions Step 3 – Global Data Step 4 – Level 1 Step 5 – Save and Test

33 VIDEO GAME PROGRAMMING CONCEPT – Collision A collision is when more than one object is occupying the same position in space. Collisions in games can be for many things such as a ball bouncing around, a bullet colliding with a ship or even a character’s foot touching the ground.

34 VIDEO GAME PROGRAMMING STEP 1: BRICKS, PADDLE, BALL Add the Actor: BRICK –Right-click Actors and Select Add. –Enter BRICK in the dialogue box and click ok.

35 VIDEO GAME PROGRAMMING THE BRICK: Add Animation Set: –Right-click on the BRICK actor and select Add Animation Set. –In the Control that comes up Enter the name of the animation BRICK_1 in the text box at the top. –Click on Add to bring up the dialogue box for choosing the frame art. –Select Brix\Art Assets\Actors\Brix_Brick1.bmp and click ok –Now click on the Collision Data button and add the collision data for this Animation frame. Be sure that the collision data is pointing out. –Click OK to close the Animation Set window.

36 VIDEO GAME PROGRAMMING THE BRICK: Object Function DestroyBrick Add The Function: DestroyBrick –Right-click Object Functions and Select Add. –Write the Function: –Enter DestroyBrick in the name box. –Click on the Used By drop down menu and select Sprites. –Enter the following code into the code window and click on the save button when done.

37 VIDEO GAME PROGRAMMING DestroyBrick if (This->CollisionWithSprite("Ball")) { This->Unused(true); This->DeleteFlag(true); }

38 VIDEO GAME PROGRAMMING THE PADDLE Add the Actor: –Right-click Actors and Select Add. –Enter PLAYER_PADDLE in the dialogue box and click ok.

39 VIDEO GAME PROGRAMMING THE PADDLE: CONTINUED Add Animation Set: –Right-click on the PLAYER_PADDLE actor and select Add Animation Set. –In the Control that comes up Enter the name of the animation PADDLE_1 in the text box at the top. –Click on Add to bring up the dialogue box for choosing the frame art. –Select Brix\Art Assets\Actors\Brix_Paddle.bmp and click ok –Now click on the Collision Data button and add the collision data for this Animation frame. Be sure that the collision data is pointing out. –Click OK to close the Animation Set window.

40 VIDEO GAME PROGRAMMING THE PADDLE: Object Function MoveWithArrows Use: Detect when the player is pressing the left or right arrow keys and move the paddle accordingly. Add The Function: MoveWithArrows –Right-click Object Functions and Select Add. –Enter MoveWithArrows in the name box. –Click on the Used By drop down menu and select Sprites. –Enter the following code into the code window and click on the save button when done.

41 VIDEO GAME PROGRAMMING MoveWithArrows if ( pKeyboard->IsPressed(DIK_RIGHT) ) { This->WorldPositionXInc( 5, 500 ); } else if ( pKeyboard->IsPressed(DIK_LEFT) ) { This->WorldPositionXDec( 5, 0 ); }

42 VIDEO GAME PROGRAMMING CONCEPT – Color Keying Color keying otherwise know as chroma keying is a method of replacing a certain color in an image with a false background. This method is used in television to superimpose the weatherman in front of the map and in many other special effects. In games using transparencies gives the same effect, and in Fun the transparency can be selected for each Animation Set

43 VIDEO GAME PROGRAMMING THE BALL Add the Actor: –Right-click Actors and Select Add. –Enter BALL in the dialogue box and click ok.

44 VIDEO GAME PROGRAMMING THE BALL: CONTINUED Add Animation Set: –Right-click on the BALL actor and select Add Animation Set. –In the Control that comes up Enter the name of the animation BALL_1 in the text box at the top. –Click on Add to bring up the dialogue box for choosing the frame art. –Select Brix\Art Assets\Actors\Brix_Ball.bmp and click ok –Now click on the Collision Data button and add the collision data for this Animation frame. Be sure that the collision data is pointing out. –Click OK to close the Animation Set window.

45 VIDEO GAME PROGRAMMING THE BALL: Object Function BallCollision Use: Increment the speed of the ball when it collides with a Brick or the Paddle. Add The Function: BallCollision –Right-click Object Functions and Select Add. –Write the Function: –Enter BallCollision in the name box. –Click on the Used By drop down menu and select Sprites. –Enter the following code into the code window and click on the save button when done.

46 VIDEO GAME PROGRAMMING BallCollision if( This->CollisionWithSprite("Brick") ) { This->SpeedInc(0.5,10); } else if( This->CollisionWithSprite( "Player_Paddle") ) { This->SpeedInc(0.5,10); }

47 VIDEO GAME PROGRAMMING THE BALL: Object Function DetectOffScreen Use: Detect when the ball is off of the screen, and decrement the number of lives when this happens. Add The Function: DetectOffScreen –Right-click Object Functions and Select Add. –Write the Function: –Enter DetectOffScreen in the name box. –Click on the Used By drop down menu and select Sprites. –Enter the following code into the code window and click on the save button when done.

48 VIDEO GAME PROGRAMMING DetectOffScreen if ( !This->InViewport() ) { PlayerLives--; SpawnBall(); This->Speed(2); }

49 VIDEO GAME PROGRAMMING STEP 2: My Functions Definition: –My Functions (or user-defined functions) are functions that have global scope throughout the game play. They are independent of any FUN objects. Objective: –Use these to spawn the ball and give it a random direction.

50 VIDEO GAME PROGRAMMING SpawnBall Use: –Places the ball back in the viewport and gives it a random direction. Add the Function: –Right-click My Functions and Select Add. –Enter SpawnBall in the name box. –Enter void SpawnBall(void) in the Declaration box. –Enter the following code into the code window and click on the save button when done.

51 VIDEO GAME PROGRAMMING SpawnBall SpritePTR pBall( “Ball” ); SpritePTR pPlayer_Paddle( “Player_Paddle” ); pBall->WorldPosition( pPlayer_Paddle->WorldPositionX(), pPlayer_Paddle->WorldPositionY() – 30 ); pBall->Speed(2); pBall->VectorDirection( RandFlt(2), -RandFlt(2), 0 );

52 VIDEO GAME PROGRAMMING STEP 3: Global Data Definition: –Global Data are data that have global scope throughout the game play. They are independent of any FUN objects. Objective: –Create a variable to keep track of the number of lives the player has.

53 VIDEO GAME PROGRAMMING PlayerLives Use: –Keeps track of the number of lives that a player has Add the Data: –Right-click Global Data and Select Add. –Enter PlayerLives in the name box. –Select int for the type and click on unsigned. –Enter 3 for the Initial Value. –Click OK to close.

54 VIDEO GAME PROGRAMMING STEP 4: Level 1 Add The Level: –Right-click Game and select Add Level. The added level will pop up at the end of the list of levels. –Right-click on the new level and select Rename. –Enter Level_1 in the box that pops up and then click on OK.

55 VIDEO GAME PROGRAMMING Level 1: CONTINUED Set the Level Properties: –Right-click Level_1 and select Properties. –Now click on the On Start tab and enter the following code. –Then click on OK.

56 VIDEO GAME PROGRAMMING Level 1 On Start SpawnBall(); PlayerLives = 3;

57 VIDEO GAME PROGRAMMING MAP: Set up the Map: –Expand the Level_1 Level. –Right-click on Maps and select Add. –Enter Level1_Background for the name. –Browse for the map file and select –Brix\Art Assets\Maps\ Brix_Background.bmp

58 VIDEO GAME PROGRAMMING MAP: CONTINUED Map Collision: –Click on the Collision Data button and put inward collision on the left right and top sides and either outward collision or no collision on the bottom. –Save this collision data and close the window. –Now click OK to close the map properties window.

59 VIDEO GAME PROGRAMMING SPRITES: Brick Add the Sprite: Brick –Right-click on Sprites and select Add. –Enter Brick for the name. –Select Level1_Background for the map. –Change the Display List to 0. –Click on the Animation tab and select BRICK for the actor. –Click on the Behavior tab and add DestroyBrick function to the list.

60 VIDEO GAME PROGRAMMING Brick: CONTINUED –Now click on the Collision tab and select Precise Collision. –Check the Activate Sprite Collision and Check With Sprites check boxes. –Now click OK to close the sprite properties window. Create The Bricks Group: –Right-click on the Brick sprite and select Create Group. –Place the Brick sprites in position here and select Options/Create Sprites to place the sprites int the group. –Now select Shapes/Close and enter Bricks for the group name. –Click OK to create the group.

61 VIDEO GAME PROGRAMMING SPRITES: Player_Paddle Add the Sprite: Player_Paddle –Right-click on Sprites and select Add. –Enter Player_Paddle for the name. –Select Level1_Background for the map. –Change the Display List to 1. –Click on the Animation tab and select PLAYER_PADDLE for the actor. –Click on the Behavior tab and add MoveWithArrows function to the list.

62 VIDEO GAME PROGRAMMING Player_Paddle: CONTINUED –Now click on the Collision tab and select Precise Collision. –Check the Activate Sprite Collision and Check With Sprites check boxes. –Check the Check Collision With Map check box. –Click on the Position tab and position the Player_Paddle. –Now click OK to close the sprite properties window.

63 VIDEO GAME PROGRAMMING SPRITES: Ball Add the Sprite: Ball –Right-click on Sprites and select Add. –Enter Ball for the name. –Select Level1_Background for the map. –Change the Display List to 2. –Click on the Animation tab and select BALL for the actor. –Click on the Behavior tab and add DetectOffScreen and BallCollision functions to the list.

64 VIDEO GAME PROGRAMMING Ball: CONTINUED –Now click on the Collision tab and select Precise Collision. –Check the Activate Sprite Collision and Check With Sprites check boxes. –Check the Check Collision With Map check box. –Click on the Effects tab and check the Reflection box. –Now click OK to close the sprite properties window.

65 VIDEO GAME PROGRAMMING STEP 4: Save and Test Save the Project: –Click on Project and Save. Run the Project: –Click on the Build/Run button in the menu bar. Results: –Level 1 should come up with the bricks, paddle and ball. –Bricks should disappear when hit. –The paddle should move with the arrow keys. –The ball should bounce around.

66 VIDEO GAME PROGRAMMING PART 4 – Adding Sounds Objective: –Play sounds when different events happen like when the ball hits something –Play music in the background. Step 1 – Splash Screen Music Step 2 – Main Menu Music Step 3 – Level 1 Music Step 4 – Update the Object Functions Step 5 – Save and Test

67 VIDEO GAME PROGRAMMING CONCEPT – Sound In games sounds are used as audio responses to events taking place. There are 2 types, Sound Effects (SFX) and Music. SFX are used for short clips such as footsteps or a doorbell. Music is played in the background sometimes to set the mood of the game at a given time.

68 VIDEO GAME PROGRAMMING STEP 1: Splash Screen Music Add The Sound: –Expand SplashScreen. –Right-click on Sound Effects and select Add. –Enter Intro_Music for the name. –Change the Type to Music. –Check the Loop check box. –Browse for the sound file and select –Brix\Art Assets\Sounds\Music\ JivinIntro.wav –Now click OK to close the sound properties window.

69 VIDEO GAME PROGRAMMING Splash Screen Music: CONTINUED Update the Code: –Right Click on SplashScreen and select Properties. –Click on the On Start tab and add the following code. –Then click OK to close.

70 VIDEO GAME PROGRAMMING Splash Screen On Start StreamedSoundPTR pIntro_Music( “Intro_Music” ); pIntro_Music->Play();

71 VIDEO GAME PROGRAMMING STEP 2: Main Menu Music Add The Sound: –Expand MainMenu. –Right-click on Sound Effects and select Add. –Enter Menu_Music for the name. –Change the Type to Music. –Check the Loop check box. –Browse for the sound file and select –Brix\Art Assets\Sounds\Music\ JivinMenu.wav –Now click OK to close the sound properties window.

72 VIDEO GAME PROGRAMMING Main Menu Music: CONTINUED Update the Code: –Right Click on MainMenu and select Properties. –Click on the On Start tab and add the following code. –Then click OK to close.

73 VIDEO GAME PROGRAMMING Main Menu On Start StreamedSoundPTR pMenu_Music( “Menu_Music” ); pMenu_Music->Play();

74 VIDEO GAME PROGRAMMING STEP 3: Level 1 Music Add The Sound: –Expand Level_1. –Right-click on Sound Effects and select Add. –Enter Level_Music for the name. –Change the Type to Music. –Check the Loop check box. –Browse for the sound file and select –Brix\Art Assets\Sounds\Music\ JivinLoop.wav –Now click OK to close the sound properties window.

75 VIDEO GAME PROGRAMMING Level 1 Music: CONTINUED Update the Code: –Right Click on Level_1 and select Properties. –Click on the On Start tab and add the following code. –Then click OK to close.

76 VIDEO GAME PROGRAMMING Level 1 On Start StreamedSoundPTR pLevel_Music( “Level_Music” ); pLevel_Music->Play();

77 VIDEO GAME PROGRAMMING Level_1: Beep Add The Sound: –Expand Level_1. –Right-click on Sound Effects and select Add. –Enter Beep for the name. –Browse for the sound file and select –Brix\Art Assets\Sounds\SFX\Beep1.wav –Now click OK to close the sound properties window.

78 VIDEO GAME PROGRAMMING Level_1: Boop Add The Sound: –Right-click on Sound Effects and select Add. –Enter Boop for the name. –Browse for the sound file and select –Brix\Art Assets\Sounds\SFX\Boop3.wav –Now click OK to close the sound properties window.

79 VIDEO GAME PROGRAMMING STEP 4: Update the Object Functions BallCollision Update the code: –Double-click on the BallCollision function to bring up the Function Properties window. –Update the code with the following changes in bold type then save.

80 VIDEO GAME PROGRAMMING BallCollision: Update if( This->CollisionWithSprite("Brick") ) { This->SpeedInc(0.5,10); SoundPTR pBeep("Beep"); pBeep->Play(); } else if( This->CollisionWithSprite("Player_Paddle") ) { This->SpeedInc(0.5,10); SoundPTR pBoop("Boop"); pBoop->Play(); }

81 VIDEO GAME PROGRAMMING STEP 5: Save and Test Save the Project: –Click on Project and Save. Run the Project: –Click on the Build/Run button in the menu bar. Results: –Music should be played in the background. –Sounds should play when the ball collides with a brick or the paddle.

82 VIDEO GAME PROGRAMMING PART 4 – BRIX GAME LEVEL 2 Objective: –Create a second level and detect when all of the bricks are destroyed so the next level can be loaded. Step 1 – Detect the end of the level. Step 2 – Level 2 Step 3 – Save and Test

83 VIDEO GAME PROGRAMMING STEP 1: Detect the End of the Level Add the Object Function: –Right-click Object Functions and Select Add. –Enter DetectEndOfLevel in the name box. –Change Used By to Levels and then enter the following code and then save.

84 VIDEO GAME PROGRAMMING DetectEndOfLevel Code Sprite* pBrick = Sprite::Search("Brick"); if(pBrick == NULL) myGame->NextLevel();

85 VIDEO GAME PROGRAMMING Detect the End of the Level: CONTINUED Update the Behaviors: –Right-click on Level_1 and select Properties. –Click on the Behavior tab and add the DetectEndOfLevel function to the list of behaviors. –Click OK to close.

86 VIDEO GAME PROGRAMMING STEP 2: Create Level 2 Add the Level: –Right-Click on Level_1 and select Insert Copy… –Enter Level_2 for the name and click on Insert After Level_1. –Click OK to close.

87 VIDEO GAME PROGRAMMING Level 2: CONTINUED Modify Level 2: –Right-Click on Level_2 and select Properties. –Click on the On Start tab and remove the following line of code. PlayerLives = 3; –Click OK to close.

88 VIDEO GAME PROGRAMMING Level 2: Bricks Group Restore to a Single Sprite: –Now right-click on the Bricks sprite group in Level_2 and select Rename. –Enter Brick and click OK. –Right-click on the Brick sprite group and select Restore to One. Recreate The Bricks Group: –Right-click on Brick and select Create Group. –Place the Brick sprites in position here and select Options/Create Sprites to place the sprites in the group. –Now select Shapes/Close and enter Bricks for the group name. –Click OK to create the group.

89 VIDEO GAME PROGRAMMING STEP 3: Save and Test Save the Project: –Click on Project and Save. Run the Project: –Click on the Build/Run button in the menu bar. Results: –Level 2 should load when all the blocks are destroyed in Level 1.

90 VIDEO GAME PROGRAMMING PART 5 – Win/Lose Screens Objective: –Create Winning and Losing screens to be displayed when the player wins or loses. Step 1 – Detect Winning/Losing. Step 2 – Winning Screen Step 3 – Losing Screen Step 4 – Save and Test

91 VIDEO GAME PROGRAMMING STEP 1: Detect Winning/Losing Note: The game is already set up to detect winning because this happens when the bricks are all destroyed and the DetectEndOfLevel function does this for us. Detect Losing: –Double-click on DetectOffScreen and change the code to match the following

92 VIDEO GAME PROGRAMMING DetectOffScreen: Update if ( !This->InViewport() ) { PlayerLives--; if ( PlayerLives == 0 ) myGame->LevelName( “LosingScreen” ); else { SpawnBall(); This->Speed(2); }

93 VIDEO GAME PROGRAMMING STEP 2: The Winning Screen Add The Level: –Right-click Game and select Add Level. The added level will pop up at the end of the list of levels. –Right-click on the new level and select Rename. –Enter WinningScreen in the box that pops up and then click on OK.

94 VIDEO GAME PROGRAMMING Winning Screen: CONTINUED Set the Level Properties: –Right-click WinningScreen and select Properties. –Click on the Behavior tab. –Add the MyTimer function to the list. –Now click on the On Start tab and enter the following code. –Click OK to close.

95 VIDEO GAME PROGRAMMING Winning Screen On Start StreamedSoundPTR pWin_Music( “Winning_Music” ); pWin_Music->Play();

96 VIDEO GAME PROGRAMMING MAP: Set up the Map: –Right-click on Maps and select Add. –Enter Winning_Screen for the name. –Browse for the map file and select –Brix\Art Assets\Maps\Brix_Winning_Screen.bmp –Now click OK to close the map properties window.

97 VIDEO GAME PROGRAMMING SOUND EFFECTS Add The Sound: –Right-click on Sound Effects and select Add. –Enter Winning_Music for the name. –Change the Type to Music. –Browse for the sound file and select –Brix\Art Assets\Sounds\Music\ JivinEndingPos.wav –Now click OK to close the sound properties window.

98 VIDEO GAME PROGRAMMING STEP 3: The Losing Screen Add The Level: –Right-click Game and select Add Level. The added level will pop up at the end of the list of levels. –Right-click on the new level and select Rename. –Enter LosingScreen in the box that pops up and then click on OK.

99 VIDEO GAME PROGRAMMING Losing Screen: CONTINUED Set the Level Properties: –Right-click LosingScreen and select Properties. –Click on the Behavior tab. –Add the MyTimer function to the list. –Now click on the On Start tab and enter the following code. –Click OK to close.

100 VIDEO GAME PROGRAMMING Losing Screen On Start StreamedSoundPTR pLose_Music( “Losing_Music” ); pLose_Music->Play();

101 VIDEO GAME PROGRAMMING MAP: Set up the Map: –Right-click on Maps and select Add. –Enter Losing_Screen for the name. –Browse for the map file and select –Brix\Art Assets\Maps\Brix_Losing_Screen.bmp –Now click OK to close the map properties window.

102 VIDEO GAME PROGRAMMING SOUND EFFECTS Add The Sound: –Right-click on Sound Effects and select Add. –Enter Losing_Music for the name. –Browse for the sound file and select –Brix\Art Assets\Sounds\Music\ JivinEndingNeg.wav –Now click OK to close the sound properties window.

103 VIDEO GAME PROGRAMMING STEP 4: Save and Test Save the Project: –Click on Project and Save. Run the Project: –Click on the Build/Run button in the menu bar. Results: –The winning/losing screens should display when the player wins/loses.

104 VIDEO GAME PROGRAMMING Final Test Brix is now completed!! Take some time to enjoy your creation.


Download ppt "VIDEO GAME PROGRAMMING Video Game Programming Level One – Breakout INSTRUCTOR Big Dan Teague TEACHER’S ASSISTANT Delmar O'Donnell."

Similar presentations


Ads by Google