Video Game Programming Level One – Platformer

71
VIDEO GAME PROGRAMMING Video Game Programmin g Level One – Platformer INSTRUCTOR Instructor Here TEACHER’S ASSISTANT TA Here

description

Video Game Programming Level One – Platformer. INSTRUCTOR Instructor Here TEACHER’S ASSISTANT TA Here. PART 1 –Platformer Basics. Objective: Unpack the platform engine and perform a test build. Step 1 – Platformer Setup Step 2 – Save and Test. STEP 1: Platformer Setup. - PowerPoint PPT Presentation

Transcript of Video Game Programming Level One – Platformer

Page 1: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMINGVideo Game

Programming

Level One – Platformer

INSTRUCTOR

Instructor Here

TEACHER’S ASSISTANT

TA Here

Page 2: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

PART 1 –Platformer Basics

Objective:Unpack the platform engine and perform a test build.

• Step 1 – Platformer Setup• Step 2 – Save and Test

Page 3: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

STEP 1: Platformer Setup

• Open Platform Engine.fun• Change the window title to

Platformer (Your Name)• Save the project as

Platformer_(Your Name).fun.

Page 4: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

CONCEPT – Third Party Game Engines

• Third party game engines are suites of tools and code developed by one company and purchased by another to create a game.

• Some examples of third party game engines are Unreal Engine 3, Source Engine and C4 Engine.

Page 5: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

STEP 2: 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 project should build without any errors.

Page 6: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

PART 2 – Initial Asset Setup

Objective:Import the actors and animation sets using the Import Wizard. Look at some options to optimize the animations.

• Step 1 – The Import Wizard• Step 2 – Reviewing Engine Data• Step 3 – Save and Test

Page 7: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

STEP 1: The Import Wizard

• The Import Wizard is located in the Resources menu.

• Open the Import Wizard and use it to import the PLYR Actor from platformer11.fun.

Page 8: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

FUN CONCEPT – Horizontal Flipping

• Horizontal Flipping is used with animations to reduce the number of frames needed by an animation set.

• Horizontal Flipping can be used to have “Left Walking” and “Right Walking” animations but only one set of frames.

• Look to see that Horizontal Flipping is turned on int the PLYR_WALK animation.

Page 9: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

STEP 2: Reviewing Engine Data

• There is already some data types set up in the Platformer Engine.

• Take a look at the following data– PlyrOnWhatSM is a State Machine that

determines whether the Sprite it is attached to is on a platform or in the air.

– My Functions here there are several prewritten functions to deal with various tasks in the platformer game.

Page 10: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

STEP 2: 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 project should build without any errors.

Page 11: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

PART 3 – Levels

Objective:Add the levels to be in the game.

• Step 1 – Add the levels• Step 2 – Bypass to Level_1• Step 3 – Level_1’s Map• Step 4 – Save and Test

Page 12: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

STEP 2: Reviewing Engine DataCONTINUED

– GravityFactor is a global value used for gravity.

– PlayerLD is Local data to store values such as the player’s jumping power and speed.

Page 13: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

FUN CONCEPT – Adding Levels

• Sometimes it is good to add all of the levels that are fundamentally different at the same time.

• When levels are added later, a copy of another level can be made so information doesn’t need to be set up repeatedly.

Page 14: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

STEP 1: Add the Levels

• Add a level called TitleScreen.• Add a level called MainMenu.• Add a level called Level_1.

Page 15: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

STEP 2: Bypass to Level_1

• When developing a game it is a waste of time to have to wait through the menus so code can be added to jump to the place we want to test.

Page 16: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

STEP 2: Bypass to Level_1

• Add the following code to the game’s OnStart to skip to Level_1:

myGame->LevelName(“Level_1”);

Page 17: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

STEP 3: Level_1’s Map• Add a map to Level_1.• The collision data for the platforms

should be added to this map.• Each platform will need collision data

pointing up on the top.• The map should have collision data

added around the edges to keep the player in the world; the left and right sides of the map should have a Collision ID of 1

Page 18: Video Game Programming Level One – Platformer

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:– When the game is run Level_1 should come up

with the platforms map in the background.

Page 19: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

PART 4 – The Player

Objective:Put the player into the game.

• Step 1 – Add the Player Sprite• Step 2 – Save and Test

Page 20: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

STEP 1: Add the Player Sprite• Add the sprite “Player” to Level_1• Give the player sprite the

PlyrOnWhatSM state machine.• Give the player sprite the PlayerLD

local data object and set its Display List to 1.

• Set the player’s collision to precise and check collision with sprites and the map.

Page 21: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

FUN CONCEPT – State Machines

• State Machines are used as a way to control the behavior of a sprite in Fun.

• State Machines are made up of different states.

• Edge cases: incoming/outgoing• Initial Actions vs. Actions

Page 22: Video Game Programming Level One – Platformer

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:– When the game is run the player should be

able to jump around the screen.

Page 23: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

PART 5 – The Key

Objective:Put the Key pickup into the game.

• Step 1 – Import the Key Actor• Step 2 – Add the Key Sprite• Step 3 – Update the PlayerLD• Step 4 – PlayerUpdateFN• Step 5 – Save and Test

Page 24: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

STEP 1: Import the Key Actor

• Open the Import Wizard and import the KEY actor from platformer11.fun.

Page 25: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

STEP 2: Add the Key Sprite

• Create a new sprite and name it Key.• Set the Key to only check collision

with other sprites.• Set the Actor for the Key

Page 26: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

CONCEPT – Pickups in Games

• Pickups are used for many things in games such as the rings in Sonic, or the coins in Mario Bros.

• Pickups can be used for puzzles such as the key and door scenario.

Page 27: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

STEP 3: Update the PlayerLD

• Open the PlayerLD local data and add a boolean variable named HaveKey.

• This value will be used to keep track of whether or not the player holds the key, so set the initial value to false.

Page 28: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

STEP 3: PlayerUpdateFN

Use:This function will detect when the player picks up the key and will change the HaveKey flag in PlayerLD.

• Create an Object Function named PlayerUpdateFN and enter the following code for the function body.

• Then add this behavior to the Player sprite

Page 29: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

PlayerUpdateFN CodeSprite* key = This->CollisionWithSpritePtr( "Key" );if ( key ){

PlayerLD *PlayerData = GetPlayerLD( This );PlayerData->HaveKey = true;key->DeleteFlag( true );

}

Page 30: Video Game Programming Level One – Platformer

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:– When the game is run the player should be

able to pick up the key.

Page 31: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

PART 6 – The Gate

Objective:Put the Gate into the game.

• Step 1 – Import the Gate Actor• Step 2 – Add the Gate Sprite• Step 3 – Modify the PlayerUpdateFN• Step 4 – Save and Test

Page 32: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

STEP 1: Import the Gate Actor

• Open the Import Wizard and import the GATE actor from platformer11.fun.

Page 33: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

STEP 2: Add the Gate Sprite

• Create a new sprite and name it Gate.

• Set the Gate to only check collision with other sprites.

• Set the Actor for the Gate

Page 34: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

CONCEPT – Sprites as Map Objects

• Using sprites as static level objects makes it easy to add interactive objects to the map easily.

• These sprites are just regular sprites who’s behaviors are set up to make them seem as though they are part of the map, much like the gate in platformer.

Page 35: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

STEP 3: Modify PlayerUpdateFN

• Update PlayerUpdateFN with the following bold face code changes.

Page 36: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

STEP 3: Modify PlayerUpdateFNSprite* key = This->CollisionWithSpritePtr( "Key" );if ( key ){

PlayerLD *PlayerData = GetPlayerLD( This );PlayerData->HaveKey = true;key->DeleteFlag( true );

SpritePTR pGate( "Gate" );pGate->Animation( GATE_OPENED);

}

if ( This->CollisionWithSprite( "Gate" ) && GetPlayerLD( This )->HaveKey ){

myGame->NextLevel();}

Page 37: Video Game Programming Level One – Platformer

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:– When the player picks up the key the gate

should open.

Page 38: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

PART 7 – Level 2

Objective:Create Level_2 by making a copy of Level_1.

• Step 1 – Copy Level_1• Step 2 – Modify the New Level• Step 3 – Save and Test

Page 39: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

STEP 1: Copy Level_1

• Insert a copy of Level_1 and name it Level_2.

Page 40: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

STEP 2: Modify the New Level

• Create a map in an art program or use the provided level art.

• Use this map for Level_2’s map• Add the collision data to the map.• Change the key’s position.• Change the gate’s position.

Page 41: Video Game Programming Level One – Platformer

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 display with the new map. Test

and tweak this map to better gameplay.

Page 42: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

PART 8 – The Enemy Guard

Objective:Add in a guard and reuse the code for the behavior.

• Step 1 – Import the Actor• Step 2 – Add the GuardLD• Step 3 – Create EnemyOnWhatSM• Step 4 – Add the Guard Sprite• Step 5 – Save and Test

Page 43: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

STEP 1: Import the Actor

• Import the ENEMY actor from platformer11.fun

Page 44: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

STEP 2: Add the GuardLD

• Add Local Data GuardLD.• Add a boolean value Jumping with

initial value false.• Add a float value JumpStrength with

initial value 10.5.• Add an integer value delay with initial

value 100.

Page 45: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

STEP 3: Create EnemyOnWhatSM

• Make a copy of PlyrOnWhatSM and name it EnemyOnWhatSM.

• Replace the code in the platform state with the following:

Page 46: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

EnemyOnWhatSMThis->Speed( 2 );

int y = 0;

if(This->LookAheadCollisionWithMap(DOWN, 1, 0))y = -1;

This->VectorDirection( This->DirectionX(), y );

if( This->DirectionX() )This->Animation(ENEMY_WALK);

elseThis->Animation(ENEMY_IDLE);

Page 47: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMINGSTEP 3: Create

EnemyOnWhatSMCONTINUED

• Now modify the platform to air edge which contains return PlayerJump(This);

• Replace the existing code with the following:

return false;

Page 48: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

STEP 4: Add the Guard Sprite

• Add an Enemy sprite.• Give it the ENEMY actor and add the

GuardLD.• Use EnemyOnWhatSM for the

behavior.• Position the guard on the map away

from the start position of the player.

Page 49: Video Game Programming Level One – Platformer

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:– Level_2 should display and the guard should

appear in the level.

Page 50: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

PART 8 – AI for the Enemy Guard

Objective:Give the guard an update function that will make the guard appear to be somewhat intelligence.

• Step 1 – EnemyUpdateFN• Step 2 – Save and Test

Page 51: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

CONCEPT – Artificial Intelligence (AI)

• One of the most important parts of a game is the AI.

• In games the AI gives the illusion that characters and objects have intelligence.

• Many AI systems i.e. Neural Networks, Fuzzy Logic Systems, Genetic Algorithms, etc…

Page 52: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMINGCONCEPT – Artificial

Intelligence (AI)CONTINUED

• It is easy to make unbeatable AI’s, but hard to make balanced AI’s that still seem intelligent.

• Some well known AI examples, alien attack paths in Galaga, the guards in Metal Gear Solid, etc…

Page 53: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

STEP 1: EnemyUpdateFN

• Add the Object Function EnemyUpdateFN.

• Enter the following code into the function body.

• Then add this function to the Enemy sprite’s behavior.

Page 54: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

EnemyUpdateFNif ( This->DirectionY() == 0 ){

GuardLD* guardData = GetGuardLD(This);if ( guardData->delay <= 0 ){

SpritePTR pPlayer("Player");This->VectorDirection( pPlayer->WorldPositionX() -

This->WorldPositionX(), 0 );

guardData->delay = RandInt(30) + 15;}

if ( guardData->delay > 0 )guardData->delay = guardData->delay - 1;

}

Page 55: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

STEP 2: 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 guard should now go after the player.

Page 56: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

PART 9 –Making the Enemy Jump

Objective:Modify the EnemyUpdateFN with code that will make the enemy jump for the player.

• Step 1 – Modify EnemyUpdateFN• Step 2 – Add GuardJump function• Step 3 – Modify GuardOnWhatSM• Step 4 – Add Collision with the Enemy• Step 5 – Save and Test

Page 57: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

STEP 1: Modify EnemyUpdateFN

• Modify EnemyUpdateFN by adding the following lines of code to the bottom of the function body.

Page 58: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

EnemyUpdateFN (update)SpritePTR pPlayer("Player");

bool RightUnder = ( pPlayer->WorldPositionY() < This->WorldPositionY() ) && ( abs( pPlayer->WorldPositionX() – This->WorldPositionX() )

< 10 );

bool RealClose = This->Distance( pPlayer ) < 80;

if ( RightUnder || RealClose ){

guardData->Jumping = true;}

} // This is the closing bracket, it is already there

Page 59: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

CONCEPT – Customizing Open Source Game Engines

• When using an open source 3rd party game engine, it can be easier to copy one of the functions and simply modify it instead of creating the function yourself.

• Modification rules are covered in the open source aggreement.

Page 60: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

STEP 2: Add GuardJump function

• Insert a copy of the My Function PlayerJump and name it GuardJump.

• Modify the code to reflect the following bold face changes.

Page 61: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

GuardJump (update)GuardLD *guardld = GetGuardLD( This );

if ( guardld->Jumping ){

float vx = SpriteVectorX(This); // Horizontal vector componentfloat vy = -guardld->JumpStrength; // Vertical vector component

SpriteVectorX(This, vx);SpriteVectorY(This, vy);

guardld->Jumping = false;return true;

}else

return false;

Page 62: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

STEP 3: Modify EnemyOnWhatSM

• Now modify the platform to air edge which contains return false;

• Replace the existing code with the following:

GuardJump(This);

Page 63: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

STEP 4: Add Collision with the Enemy

• We must now edit the PlayerUpdateFN to allow the player to collide with the enemy.

• Add the following code to the bottom of the funtion:

if ( This->CollisionWithSprite( "Enemy" ) ){

myGame->RestartLevel();}

Page 64: Video Game Programming Level One – Platformer

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:– The guard should jump after the player now.

Page 65: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

PART 10 – The Menus

Objective:Put the maps into the menu levels and add in behavior to start the game.

• Step 1 – Add the maps• Step 2 – Add the behaviors• Step 3 – Modify the Game’s OnStart• Step 4 – Save and Test

Page 66: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

STEP 1 & 2:

• Create the maps, and then add the maps to the TitleScreen level and add behaviors to navigate these menus. Any behavior for the menu is ok such as a timer, waiting for a key to be pressed, or taking input from the mouse.

Page 67: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

STEP 3: Modify the Game’s OnStart

• Modify the game’s OnStart code to start with the TitleScreen.

Page 68: Video Game Programming Level One – Platformer

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 Levels should fade in and out when

switching.

Page 69: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

PART 11 – Smooth Transitions Between Levels

Objective:Add in transitional effects to the levels to make the level switches look better.

• Step 1 – Fade in the Levels• Step 2 – Save and Test

Page 70: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

STEP 1: Fade in the Levels

• Adjust the Level properties in each of the levels to have them fade in and out when switching.

• Adjust fade durations and tweak.

Page 71: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

STEP 2: 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 Levels should fade in and out when

switching.