video game programming level one – platformer

67
VIDEO GAME PROGRAMMING Video Game Programmin g Level One – Platformer INSTRUCTOR: <Your Name Here>

Upload: eadoin

Post on 04-Jan-2016

50 views

Category:

Documents


1 download

DESCRIPTION

Video Game Programming Level One – Platformer. INSTRUCTOR: . PART 1 –Platformer Basics. Objective: Unpack the platform engine and perform a test build. Step 1 – Platformer Setup Step 2 – Save and Test. CONCEPT – Third Party Game Engines. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMINGVideo Game

Programming

Level One – Platformer

INSTRUCTOR:

<Your Name 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

CONCEPT – Third Party Game Engines

• Some game developers create their games using in house game engines, which are simply a framework and series of tools from which you can create a game. For instance, the ProjectFUN Editor is a game engine.

• They also put these pieces of software on the market for other developers to use.

Page 4: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

CONCEPT – Third Party Game Engines Continued ...

• In this project, you will be getting the Platformer Engine, which is something written in the ProjectFUN Editor to ease the creation of platformer-style games.

• The Platformer Engine has all the base code that you need to create a simple platforming game.

Page 5: 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 6: 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 7: 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 8: 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 9: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

CONCEPT – Horizontal Flipping • Consider the situation where you want a

character to walk both left and right; normally you would need to make two separate animations for this.

• The ProjectFUN Editor automates this process with Horizontal Flipping. H-Flip flips the animation when the movement direction changes signs (e.g. From positive to negative).

• NOTE: H-Flip assumes that the character is initially right-facing.

Page 10: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

STEP 2: Reviewing Engine Data

• There is already code and some Local Data entered into the Platformer Engine.

• Take a look at the following code:– PlyrOnWhatSM: Determines if the owning

Sprite is on a platform or in the air, and reacts accordingly.

– My Functions: These are some useful pre-written functions that ease the creation of your game, as well as providing detailed error messages when something goes wrong.

Page 11: 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 12: 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:– The project should build without any errors.

Page 13: 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 14: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

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 15: 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 16: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

STEP 2: Bypass to Level_1• When you’re creating a game that has

a lot of levels, it is hard to debug a problem on Level 20, say, when you have to keep playing through Levels 1-19 over and over.

• It’s a good idea to put in a “bypass” to Level 20, so you can go straight to the problem.

• That’s exactly what we’re doing here.

Page 17: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

STEP 2: Bypass to Level_1 Continued...

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

myGame->LevelName(“Level_1”);

Page 18: 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 19: 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 20: 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 21: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

CONCEPT – State Machines • In different game projects, a need arises for

controlled collections of different behaviour.

• Each “state” represents a different type of behaviour, such as an AI-controlled guard might patrol or chase away the player. Each behaviour, patrolling and chasing, is a different state.

• Between two States is an “edge”, which essentially controls if the current behaviour changes to a different state. For instance, if the guard sees the player, he will change from patrolling to chasing. This change, is represented as an Edge.

• In the ProjectFUN Editor, these States and Edges comprise what is known as a State Machine.

Page 22: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

CONCEPT – State Machines Continued... • Each State Machine has a “Starting State”, which

is the default behaviour to start in. An example with our guard would be that he starts out in the game patrolling, and then can change states from there.

• Additionally, every State Machine has a “Current State”, which is the currently active behaviour. This could be patrolling or chasing, respectively.

• Finally, each State has both an OnStart behaviour and an Update behaviour. The OnStart is called when the State is first activated (such as when changing states) and the Update is called every frame while the State is active.

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

able to jump around the screen.

Page 25: 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 26: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

CONCEPT – Pickups in Games • In many games there is the need to add a puzzle

element to the gameplay, which can be represented as a “pickup”.

• Pickups in games represent a goal that the player must achieve, while fulfilling the puzzle requirements. An example of pickups would be the colored keys in DOOM or the golden rings in Sonic.

• In the Platformer, the Key represents the goal that the player must achieve to open the door to the next level. Ideally, it will be difficult to get, but not too difficult.

Page 27: 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 28: 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 29: 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 30: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

STEP 4: 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 31: 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 32: 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 33: 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 34: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

CONCEPT – Sprites as Map Objects • Another necessity in many games are pieces of the

level that react to player input, such as a pressure pad to a door or mine in the sand.

• In the ProjectFUN Editor, you can accomplish this by letting Sprites masquerade as parts of the level.

• For instance, in the Platformer, the Gate has specific behaviour if it is opened, but it does not move. It acts as a door to the next level, and not as a separate moving entity. This is precisely the concept that we’re trying to get at. The Gate Sprite acts as if it were a piece of the level, and not necessarily a Sprite.

Page 35: 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 36: 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 37: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

STEP 3: Modify PlayerUpdateFN

• Update PlayerUpdateFN with the following bold face code changes.

Page 38: 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 39: 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 40: 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 41: 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 42: 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 43: 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 44: 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 45: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

STEP 1: Import the Actor

• Import the ENEMY actor from platformer11.fun

Page 46: 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 47: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

STEP 3: Create EnemyOnWhatSM

• Import the EnemyOnWhateSM from the platformer11.fun.

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, such as aggressive chasing behavior.

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

Page 51: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

CONCEPT – Artificial Intelligence (AI)• In almost every game, there is some form of

artificial intelligence (AI). This can span from the rudimentary to the incredibly complex.

• As with our previous example, we could simply have a guard that patrols and chases, or we could have a perfect Chess AI.

• There are many ways to create in-game AI, and paradigm “simplest is best” is usually the most successful path to follow.

• Some of the methods are as follows: State Machines, Neural Networks, Fuzzy Sensors, and more.

Page 52: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMINGCONCEPT – Artificial

Intelligence (AI)CONTINUED

• In games, it is easy in some cases to make incredibly stupid or incredibly brilliant AI, such as with the perfect Chess AI example.

• The most difficult AI to achieve is the perfectly balanced AI, one that acts intelligently, but not in-humanly intelligent.

• In the Platformer, the AI isn’t terribly bright, but it’s simple enough to work well for this type of game. Other games, however, most definitely need something more complex.

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 EnemyOnWhatSM• 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 that is already there

Page 59: 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 60: 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 61: 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 62: 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 63: 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 64: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMING

PART 10 – 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 65: 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 66: 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.

Page 67: Video Game Programming Level One – Platformer

VIDEO GAME PROGRAMMINGTwo Steps Forward, One Step

Back• By this time, you should have fully

completed the Platformer Game. There are a few things that you can do with this, though your primary focus should be developing ideas for you own game.

• The easiest additions are:– Adding new levels– Programming in a weapon for the Player

character