710 likes | 861 Views
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.
E N D
Video Game ProgrammingLevel 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 • Open Platform Engine.fun • Change the window title to Platformer (Your Name) • Save the project as Platformer_(Your Name).fun.
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.
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.
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
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.
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.
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.
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.
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
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.
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.
STEP 1: Add the Levels • Add a level called TitleScreen. • Add a level called MainMenu. • Add a level called Level_1.
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.
STEP 2: Bypass to Level_1 • Add the following code to the game’s OnStart to skip to Level_1: myGame->LevelName(“Level_1”);
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
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.
PART 4 – The Player Objective: Put the player into the game. • Step 1 – Add the Player Sprite • Step 2 – Save and Test
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.
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
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.
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
STEP 1: Import the Key Actor • Open the Import Wizard and import the KEY actor from platformer11.fun.
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
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.
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.
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
PlayerUpdateFN Code Sprite* key = This->CollisionWithSpritePtr( "Key" ); if ( key ) { PlayerLD *PlayerData = GetPlayerLD( This ); PlayerData->HaveKey = true; key->DeleteFlag( true ); }
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.
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
STEP 1: Import the Gate Actor • Open the Import Wizard and import the GATE actor from platformer11.fun.
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
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.
STEP 3: Modify PlayerUpdateFN • Update PlayerUpdateFN with the following bold face code changes.
STEP 3: Modify PlayerUpdateFN Sprite* 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(); }
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.
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
STEP 1: Copy Level_1 • Insert a copy of Level_1 and name it Level_2.
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.
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.
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
STEP 1: Import the Actor • Import the ENEMY actor from platformer11.fun
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.
STEP 3: Create EnemyOnWhatSM • Make a copy of PlyrOnWhatSM and name it EnemyOnWhatSM. • Replace the code in the platform state with the following:
EnemyOnWhatSM This->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); else This->Animation(ENEMY_IDLE);
STEP 3: Create EnemyOnWhatSMCONTINUED • Now modify the platform to air edge which contains return PlayerJump(This); • Replace the existing code with the following: return false;
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.
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.
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