View
219
Download
1
Category
Preview:
Citation preview
VIDEO GAME PROGRAMMINGVideo Game
Programming
Junior – Number Attack
INSTRUCTOR
<instructor name>
TEACHER’S ASSISTANT
<TA name>
VIDEO GAME PROGRAMMING
CONCEPT – Wrapping Maps
• A Wrapping Map is a map that loops when you reach the edges.
• Imagine a map drawn on a toilet paper roll.
• Wrapping maps are used a lot in space games and flying games (as stars, clouds or ground).
VIDEO GAME PROGRAMMING
PART 1 – Wrapping Map
Objective:– Create the basic map that will scroll
underneath our plane.
• Step 1 – Create Map Art.• Step 2 – Add Wrapping Map to Title
Level.• Step 3 – Build and Run.
VIDEO GAME PROGRAMMING
STEP 1: Create Map Art
• Open MS Paint and create an 800x1200 map of some ground.
• Save as wrappingMap.bmp in your Maps folder.
VIDEO GAME PROGRAMMING
STEP 2: Add Wrapping Map to Title Level
• Add a new Map to the Title level.• Set the following in the General
tab:1. Map Name: wrappingMap2. File Name: the map you created.3. Wrap: Check this box.
VIDEO GAME PROGRAMMING
STEP 2: Add Wrapping Map to Title Level continued…
• Under the Scrolling tab, set the Y Speed to 5.
VIDEO GAME PROGRAMMING
STEP 3: Build and Run
• Build and Run your game.• If all is well, you should see your map
scrolling downward.• If you want the map to scroll faster or
slower, change the Y Speed to whatever you want.
VIDEO GAME PROGRAMMING
PART 2 – Transparent Map
Objective:– Create the Title Screen Logo. We’re going to
make it transparent so we can see our scrolling map behind it.
• Step 1 – Create Map Art.• Step 2 – Add Transparent Map to Title
Level.• Step 3 – Build and Run.
VIDEO GAME PROGRAMMING
STEP 1: Create Map Art
• Open MS Paint and create an 800x600 picture with the words “Number Attack” drawn in however you like.
• Make sure the area that is supposed to be transparent is green.
• Save as title.bmp in your Maps folder.
VIDEO GAME PROGRAMMING
STEP 2: Add Transparent Map to Title Level
• Add a new Map to the Title level.• Set the following in the General tab:1.Map Name: main2.File Name: the map you created.3.Use Transparency: Check this box.
VIDEO GAME PROGRAMMING
STEP 2: Add Transparent Map to Title Level continued…
• In the Position Tab, set the Z-Order to 1.
VIDEO GAME PROGRAMMING
STEP 3: Build and Run
• Build and Run your game.• If all is well, you should see your map
scrolling downward with your Number Attack art on top of it.
VIDEO GAME PROGRAMMING
PART 3 – Cursor
Objective:– Create a cursor for the title screen that will
allow us to interact with buttons later on.
• Step 1 – Tweak Cursor Art (Optional).• Step 2 – Add Cursor Sprite to Title Level.• Step 3 – Build and Run.
VIDEO GAME PROGRAMMING
STEP 1: Tweak Cursor Art (Optional)
• If you would like to change the cursor art, simply open the CURSOR actor’s CURSOR animation set.
• Double-click on the single frame of animation to open MS Paint.
• When you’re done, go to File->Save (not Save-As)
VIDEO GAME PROGRAMMING
STEP 2: Add Cursor Sprite to Title Level
• Add a new Sprite to the Title level.• Set the following in the General tab:1.Name: cursor2.Map: main3.Z-Order: 1
VIDEO GAME PROGRAMMING
STEP 2: Add Cursor Sprite to Title Level continued…
• In the Animation Tab, use the CURSOR Actor.
• In the Behavior Tab, add the MouseCursorMoveFN function.
VIDEO GAME PROGRAMMING
STEP 2: Add Cursor Sprite to Title Level continued…
• Check the following boxes or bubbles in the Collision tab:
1.Loose Collision2.Activate Sprite Collision3.Check With Sprites4.Ghost Collision5.Check Same Display List
VIDEO GAME PROGRAMMING
CONCEPT – Loose Collision
• Loose Collision tells FUN to use the sprite’s Bounding Box instead of any collision data we’ve defined.
• The Bounding Box is automatically created and wraps the ENTIRE sprite in a collision box.
• When would we not want to use Loose Collision?
VIDEO GAME PROGRAMMING
STEP 3: Build and Run
• Build and Run your game.• You should be able to move the
cursor around now.
VIDEO GAME PROGRAMMING
PART 4 – Interface Buttons
Objective:– Now that we have a cursor, let’s make some
buttons that let us Start or Quit the game.
• Step 1 – Add Start Sprite to Title Level.• Step 2 – Add Quit Sprite to Title Level.• Step 3 – Reposition Sprites Using Level
Preview.• Step 4 – Build and Run.
VIDEO GAME PROGRAMMING
STEP 1: Add Start Sprite to Title Level
• Add a new Sprite to the Title level.• Set the following in the General tab:1.Name: start2.Map: main
VIDEO GAME PROGRAMMING
STEP 1: Add Start Sprite to Title Level continued…
• In the Animation Tab, use the BUTTON_START Actor.
• In the Behavior Tab, add the ButtonStartFN function.
VIDEO GAME PROGRAMMING
STEP 1: Add Start Sprite to Title Level continued…
• Check the following boxes or bubbles in the Collision tab:
1.Loose Collision2.Activate Sprite Collision3.Check With Sprites4.Ghost Collision5.Check Same Display List
VIDEO GAME PROGRAMMING
STEP 1: Add Start Sprite to Title Level continued…
• You can change the art in the BUTTON_START Actor if you want to.
VIDEO GAME PROGRAMMING
STEP 2: Add Quit Sprite to Title Level
• Insert a copy of the start sprite and name it quit.
• In the Animation Tab, use the BUTTON_QUIT Actor.
• In the Behavior Tab, remove the ButtonStartFN function and add the ButtonQuitFN function.
VIDEO GAME PROGRAMMING
CONCEPT – If – Else Statements
• If Else statements are just like if statements, except if the conditional is false, then the computer executes the code under the else statement
• Open the ButtonQuitFN function.• You’ll notice a part in the code that
says something like:
VIDEO GAME PROGRAMMING
CONCEPT – If – Else Statements continued…
if(This->CollisionWithSprite("cursor")){
This->Animation(1);if(MouseTriggered(DIM_LEFT)){
myGame->EndGame();}
}else{
This->Animation(0);}
VIDEO GAME PROGRAMMING
STEP 3: Reposition Sprites Using Level Preview
• Open the Level Preview for the Title level and place your start and quit sprites wherever you want them.
• Place them kind of far apart from eachother; if they’re too close you might click on both of them at the same time. This would be bad…
VIDEO GAME PROGRAMMING
STEP 4: Build and Run
• Build and Run your game.• Check out what the start and quit
buttons do.• If you can click on both of them at the
same time, reposition them until you can’t.• What happens when you click the start
button? Why?
VIDEO GAME PROGRAMMING
PART 5 – Set Up Level1
Objective:– Add the maps to the first level.
• Step 1 – Add Wrapping Map to Level1.
• Step 2 – Add Map to Level1.• Step 3 – Build and Run.
VIDEO GAME PROGRAMMING
STEP 1: Add Wrapping Map to Level1
• Add a new Map to level1.• Set the following in the General
tab:1. Map Name: wrappingMap2. File Name: use wrappingMap.bmp3. Wrap: Check this box
VIDEO GAME PROGRAMMINGSTEP 1: Add Wrapping Map to
Level1continued…
• In the Scrolling tab, set the Y Scroll Speed to 5 (or whatever you set it to in the title level).
VIDEO GAME PROGRAMMING
STEP 2: Add Map to Level1
• Add a new Map to level1.• Set the following properties:1. Map Name: main2. File Name: mainBG.bmp3. Use Transparency: Check this.4. Z-Order: Set to 1.
VIDEO GAME PROGRAMMING
STEP 2: Add Map to Level1 continued…
• Now add Collision Data to the map. Just make a big square around the edge of the map.
• Make sure your normals are pointing toward the center of the map (inward).
VIDEO GAME PROGRAMMING
CONCEPT – Transparent Maps
• In FUN, you cannot add sprites (text objects, etc) to wrapping maps.
• To add sprites to our level, we need to have a non-wrapping map on top of our wrapping map.
• We make it completely transparent so we can see our wrapping map below it.
VIDEO GAME PROGRAMMING
STEP 3: Build and Run
• Now Build and Run your game.• This time, when you hit the start
button on the title screen it should be displaying something instead of a black screen when you enter level1.
VIDEO GAME PROGRAMMING
PART 6 – Adding the Player
Objective:– Add the player to the first level.
• Step 1 – Create Player Art.• Step 2 – Add PLAYER Actor.• Step 3 – Add Player Sprite to Level1.• Step 4 – Build and Run.
VIDEO GAME PROGRAMMING
STEP 1: Create Player Art
• Open MS Paint and create 2 planes (both 60x60).
• Make the first one have a red theme and the second have a blue theme.
• Save them in your Actors folder as player1.bmp and player2.bmp.
VIDEO GAME PROGRAMMING
STEP 2: Add PLAYER Actor
• Create a new Actor named PLAYER.• Add a new Animation Set named ONE.• Add player1.bmp to ONE and give it
collision data.• Add a new Animation Set named TWO.• Add player2.bmp to TWO and give it
collision data.
VIDEO GAME PROGRAMMING
STEP 3: Add Player Sprite to Level1
• Create a new Sprite in level1.• Set the following properties:1. Name: player12. Map: main3. Actor: PLAYER4. Initial Animation: ONE
VIDEO GAME PROGRAMMING
STEP 3: Add Player Sprite to Level1 continued…
5. Behavior: Add KeyboardWASDMovementFN.
6. Position: Manually place using ‘…’7. Precise Collision: Check this8. Activate Sprite Collision: and this9. Check With Sprites: and this…10.Check With Map: and this.11.Speed: 5
VIDEO GAME PROGRAMMING
STEP 4: Build and Run
• Now Build and Run your game.• You should have a red ship flying
around the screen.• Make sure you can move it with
WASD keys.
VIDEO GAME PROGRAMMING
PART 7 – Projectiles
Objective:– Add some projectiles to our game.
• Step 1 – Create Projectile Art.• Step 2 – Add PLAYERSHOT Actor.• Step 3 – Add PlayerShot Sprite to
Level1.• Step 4 – Build and Run.
VIDEO GAME PROGRAMMING
STEP 1: Create Projectile Art
• Open MS Paint and create 2 projectiles (both 16x16).
• Give the first one a red theme and the second one a blue theme.
• Save them as playerShot1.bmp and playerShot2.bmp in your Actors folder.
VIDEO GAME PROGRAMMING
STEP 2: Add PLAYERSHOT Actor
• Create a new Actor named PLAYERSHOT.
• Add a new Animation Set named ONE.• Add playerShot1.bmp to ONE and give it
collision data.• Add a new Animation Set named TWO.• Add playerShot2.bmp to TWO and give
it collision data.
VIDEO GAME PROGRAMMING
STEP 3: Add PlayerShot Sprite to Level1
• Add a new Sprite to level1.• In the General Tab set the
following:1. Name: playerShot2. Map: main3. Unused: Check this4. Local Data: ShotData
VIDEO GAME PROGRAMMING
CONCEPT – Local Data
• Local Data is a set of data that belongs to a particular object.
• We can define one set of Local Data that is used by multiple objects.
• For instance, we can define a set of local data containing Health and then give it to our enemy sprites. That way, FUN can track each enemies individual Health as they get hit.
VIDEO GAME PROGRAMMING
STEP 3: Add PlayerShot Sprite to Level1 continued…
• Set the following in the Animation Tab:
1. Actor: PLAYERSHOT2. Initial Animation: ONE3. Peg Registered: Check This
VIDEO GAME PROGRAMMING
CONCEPT – Peg Registered
• Normally, when FUN draws sprites, it starts drawing the top-left pixel at the position of the sprite.
• This is a problem if we have multiple frames of animation each with different sizes.
• Peg Registration means that FUN will draw the Sprite using its center as the position of the sprite.
VIDEO GAME PROGRAMMING
CONCEPT – Peg Registered continued…
VIDEO GAME PROGRAMMING
STEP 3: Add PlayerShot Sprite to Level1 continued…
• Check the following in the Collision Tab:
1.Precise Collision2.Activate Sprite Collision3.Check With Sprites4.Ghost Collision
VIDEO GAME PROGRAMMING
STEP 3: Add PlayerShot Sprite to Level1 continued…
• Add the SpriteDeleteOutOfViewportFN and ShotDeleteOnSpriteCollisionFN functions.
• Set the Speed to 8.
VIDEO GAME PROGRAMMING
CONCEPT – Delete Flag
• Open up the SpriteDeleteOutOfViewportFN function.
if (This->InViewport() == FALSE){
// delete this spriteThis->DeleteFlag(TRUE);
}
VIDEO GAME PROGRAMMING
CONCEPT – Delete Flag continued…
• When the sprite is no longer visible, we want to delete it.
• The problem is, if we delete it right then and there, it might cause problems in the game and crash it.
• Instead, we set a flag that tells FUN to delete that sprite at the end of the current game loop.
VIDEO GAME PROGRAMMING
PART 7.1 – Player Shooting
Objective:– Add proper behavior to allow the player
to shoot.
• Step 1 – Add Behavior to Player Sprite.
• Step 2 – Change Player HotSpots.• Step 3 – Build and Run.
VIDEO GAME PROGRAMMING
STEP 1: Add Behavior to Player Sprite
• Add the KeyboardShootFN to the player sprite.
VIDEO GAME PROGRAMMING
STEP 2: Change Player HotSpots
• Open the PLAYER actor’s ONE animation set.
• Where it says Hot Spots, click the ‘…’ button next to Hot Spot 0.
VIDEO GAME PROGRAMMING
STEP 3: Build and Run
• Build and Run your game.• Now try shooting. If your bullet is
coming out the wrong part of the ship, try changing Hot Spot 0 until it’s right.
VIDEO GAME PROGRAMMING
PART 8 – Adding Numbers
Objective:– Add numbers the player can shoot to receive
bonuses.
• Step 1 – Add Number Sprite to Level1.• Step 2 – Add Spawning Behavior to Level1.• Step 3 – Build and Run.
VIDEO GAME PROGRAMMING
STEP 1: Add Number Sprite to Level1
• Add a new Sprite to level1.• Set the following properties:1. Name: number2. Map: main3. Unused: Check this4. Display List: 1
VIDEO GAME PROGRAMMING
STEP 1: Add Number Sprite to Level1 continued…
5. Actor: NUMBER6. Initial Animation: ZERO7. Precise Collision: Check this8. Activate Sprite Collision: and this9. Check With Sprites: and this…10.Ghost Collision: and this.
VIDEO GAME PROGRAMMING
STEP 1: Add Number Sprite to Level1 continued…
• Under the Displacement Tab set:1. Speed: 42. Vector Direction: Y = 1
VIDEO GAME PROGRAMMING
STEP 1: Add Number Sprite to Level1 continued…
• Finally, add the SpriteDeleteBelowViewportFN function to the sprite.
• We use this function because our numbers will be falling and, once they reach the bottom of the screen, we can’t shoot them, so we delete them.
VIDEO GAME PROGRAMMING
STEP 2: Add Spawning Behavior to Level1
• Add the LevelNumberSpawnFN function to level1.
• Open this function, let’s have a look…
VIDEO GAME PROGRAMMING
CONCEPT – Game Loops
• A Game Loop represents the action the game takes every single frame.
• Game Loops do things like:Check for InputAIPhysicsPlay SoundRender
VIDEO GAME PROGRAMMING
CONCEPT – Game Loops continued…
• Once a Game Loop executes everything it’s supposed to do, it starts over again from the beginning.
VIDEO GAME PROGRAMMING
CONCEPT – While Loops
• While Loops are how we implement a Game Loop.
• A while loop repeatedly executes the code inside of it until the conditional becomes false, or rather, while the conditional is true.
VIDEO GAME PROGRAMMING
CONCEPT – While Loops continued…
• While loops look something like this…
while (somethingIsTrue){
doThisCode;}
VIDEO GAME PROGRAMMING
STEP 3: Build and Run
• Now Build and Run your game.• You should have some random
numbers appearing around the top of the level and slowly falling toward the bottom.
VIDEO GAME PROGRAMMING
PART 9 – Movement Patterns
Objective:– Make the numbers follow a specific movement
pattern.
• Step 1 – Add a New Movement Pattern.• Step 2 – Add Movement Pattern to Number
Sprite.• Step 3 – Build and Run.
VIDEO GAME PROGRAMMING
CONCEPT – Movement Patterns
• A Movement Pattern is a defined course a sprite will follow if it can.
• Movement Patterns are useful tools when we’re developing AI for enemies.
VIDEO GAME PROGRAMMING
STEP 1: Add a New Movement Pattern
• Under the Game Assets tree, right-click on Movement Patterns and select Add.
• Click the Free Track button and draw a movement pattern starting from somewhere near the top and working down.
• Name it NumberFallMP and Save.
VIDEO GAME PROGRAMMING
STEP 2: Add Movement Pattern to Number Sprite
• Open the Properties for the number sprite and click the Movement Tab.
• Click the Movement Pattern box.• Select the NumberFallMP pattern.• Click the Initially Started and Loop
boxes.
VIDEO GAME PROGRAMMING
STEP 3: Build and Run
• Now Build and Run your game.• Do the numbers follow the pattern
you gave them?• Go ahead and tweak the movement
pattern until the enemies are doing what you want them to do.
VIDEO GAME PROGRAMMING
PART 10 – Make Numbers Shootable
Objective:– Make the numbers follow a specific
movement pattern.
• Step 1 – Add Proper Behavior.• Step 2 – Build and Run.
VIDEO GAME PROGRAMMING
STEP 1: Add Proper Behavior
• Add the SpriteDeleteNumberOnCollisionFN function to the playerShot sprite.
VIDEO GAME PROGRAMMING
STEP 2: Build and Run
• You got it! Build and Run your game.
• At this point you should have numbers spawning, moving around, and dying when you shoot them.
• If not, let us know.
VIDEO GAME PROGRAMMING
PART 11 – Make Things Explode
Objective:– My personal favorite, now we’re going to
add some flashy visuals when something dies.
• Step 1 – Add a New Particle System.• Step 2 – Build and Run.
VIDEO GAME PROGRAMMING
STEP 1: Add a New Particle System
• Under level1, right-click on Particle Systems and select Add.
• Set the following properties:1. Name: ExplodeRed2. Unused: Check.3. Number of Particles: 10004. Belongs to: main
VIDEO GAME PROGRAMMING
STEP 1: Add a New Particle System continued…
• Now, open the text file Explode Particle System.txt located in your game’s root directory.
• Highlight all the code using <ctrl + a> then copy (<ctrl + c>) and paste (<ctrl + v>) it into the ExplodeRed particle system.
VIDEO GAME PROGRAMMING
STEP 2: Build and Run
• Build and Run your game.• Now try shooting some numbers.• You can play around with the values
inside the ExplodeRed particle system to see what each thing does.
VIDEO GAME PROGRAMMING
PART 12 – Operators
Objective:– Now we’re going to add the basic math
operators. The player will shoot these, along with some numbers, for a special bonus.
• Step 1 – Add Oper Sprite.• Step 2 – Add Behavior to playerShot
Sprite.• Step 3 – Build and Run.
VIDEO GAME PROGRAMMING
STEP 1: Add Oper Sprite
• Insert a copy of the number sprite and name it oper.
• We can’t name it operator because that’s a C++ Keyword (like ‘if’, ‘while’, etc)
• Change the Actor to OPERATOR.
VIDEO GAME PROGRAMMING
STEP 2: Add Behavior to playerShot Sprite
• Add the SpriteDeleteOperatorOnCollisionFN function the the playerShot sprite.
• Open up this function, time to learn MORE CODE!
VIDEO GAME PROGRAMMING
CONCEPT – Sprite Pointers
• Sprite Pointers (or SpritePTR in FUN) are how we uniquely identify different sprites of the same type.
• We can use Sprite Pointers to access data specific to one sprite.
• In the SpriteDeleteOperatorOnCollisionFN function, we use SpritePTR to access an oper sprite’s Delete Flag when we shoot it.
VIDEO GAME PROGRAMMING
STEP 3: Build and Run
• Build and Run your game.• You should have numbers and
operators falling from the sky now.
VIDEO GAME PROGRAMMING
PART 13 – New Particle System
Objective:– If you noticed in the
SpriteDeleteOperatorOnCollisionFN function, it tried to use a ExplodeYellow Particle System. Let’s add that.
• Step 1 – Create a New Particle System.• Step 2 – Change its Properties.• Step 3 – Build and Run.
VIDEO GAME PROGRAMMING
STEP 1: Create a New Particle System
• Insert a Copy of our ExplodeRed particle system and name it ExplodeYellow.
VIDEO GAME PROGRAMMING
STEP 2: Change its Properties
• Open the ExplodeYellow particle system.
Change: This-> Color(RGB(255,0,0),RGB(200,200,100));
To: This-> Color(RGB(255,255,0),RGB(200,200,100));
VIDEO GAME PROGRAMMING
STEP 3: Build and Run
• Build and Run your game.• Now try shooting some operators.• Do they explode?
VIDEO GAME PROGRAMMING
PART 14 – Math Expression
Objective:– Add text to display which numbers and
operators have been shot and what they must equal.
• Step 1 – Add the Symbol Sprite.• Step 2 – Add the Equal Sprite.• Step 3 – Add Text.• Step 4 – Build and Run.
VIDEO GAME PROGRAMMING
STEP 1: Add the Symbol Sprite
• Add a new Sprite to level1 and set:1. Name: symbol2. Display List: 13. Map: main4. Actor: SYMBOL5. Initial Animation: ADD6. Position: x = 270, y = 500
VIDEO GAME PROGRAMMING
STEP 1: Add the Symbol Sprite continued…
• Add the SymbolUpdateFN behavior to the symbol sprite.
• Open this function.
VIDEO GAME PROGRAMMING
CONCEPT – Setting Animation
• In the SymbolUpdateFN you should see a piece of code that looks like this:
This->Animation(Operator);
VIDEO GAME PROGRAMMING
CONCEPT – Setting Animation continued…
• This piece of code is how you change a sprite’s current animation set.
• Build and Run your game real quick to see this in action. As you shoot operators, the symbol animation changes.
VIDEO GAME PROGRAMMING
STEP 2: Add the Equal Sprite
• Insert a copy of the symbol sprite and name it equal.
• Set the following:1. ACTOR: symbol2. Initial Animation: NOTEQUAL3. Position: x= 400, y= 5004. Behavior: Remove the
SymbolUpdateFN function.
VIDEO GAME PROGRAMMING
STEP 3: Add Text
• Add a new Text Object to level1.• Set the following:1. Name: LeftNumber2. Type: Number3. Font Size: 724. Font Color: Red5. Initial Value: 0
VIDEO GAME PROGRAMMING
STEP 3: Add Text continued…
6. Position:Left: 210Top: 480Right: 270Bottom: 600
VIDEO GAME PROGRAMMING
STEP 3: Add Text continued…
• Insert a copy of LeftNumber and name it RightNumber.
• Change the following properties:1. Font Color: Blue2. Position:
Left: 340Top: 480Right: 400Bottom: 600
VIDEO GAME PROGRAMMING
STEP 3: Add Text continued…
• Insert a copy of RightNumber and name it AnswerNumber.
• Change the following properties:1.Font Color: Yellow2.Position:
Left: 470Top: 480Right: 580Bottom: 600
VIDEO GAME PROGRAMMING
STEP 4: Build and Run
• Build and Run your game.• You should now have some math text
at the bottom of your screen.• If not, let us know.
VIDEO GAME PROGRAMMING
PART 15 – Secondary Fire
Objective:– Add a secondary fire mode the player
can use to select the second number.
• Step 1 – Add the playerShot2 Sprite.• Step 2 – Add a New Particle System.• Step 3 – Build and Run.
VIDEO GAME PROGRAMMING
STEP 1: Add the playerShot2 Sprite
• Insert a copy of the playerShot sprite and name it playerShot2.
• Use Insert After: playerShot…• Change the Initial Animation to
TWO.
VIDEO GAME PROGRAMMING
STEP 2: Add a New Particle System
• Insert a copy of the ExplodeRed particle system and name it ExplodeBlue.
Change:
This->Color(RGB(255,0,0),RGB(200,200,100));
To: This->Color(RGB(0,0,255),RGB(200,200,100));
VIDEO GAME PROGRAMMING
STEP 3: Build and Run
• Build and Run your game.• You should be able to shoot your
secondary weapon using the right <alt> key.
• Try shooting some numbers with your secondary shot.
VIDEO GAME PROGRAMMING
PART 16 – Tie Everything Together
Objective:– Now we’re going to make it so the math
on the screen actually does something.
• Step 1 – Add Level Behavior.• Step 2 – Adjust Text Objects.• Step 3 – Build and Run.
VIDEO GAME PROGRAMMING
STEP 1: Add Level Behavior
• Add the LevelMathFN function to level1.
VIDEO GAME PROGRAMMING
STEP 2: Adjust Text Objects
• Open the Properties for the RightNumber text object.
• Uncheck the Visible box.• Do the same for the LeftNumber
text object.
VIDEO GAME PROGRAMMING
STEP 3: Build and Run
• Build and Run your game.• Shoot a combination of numbers
and operators using both your primary and secondary shot.
• Try to come up with the number that gives you the right answer.
VIDEO GAME PROGRAMMING
PART 17 – Add Scoring
Objective:– When the player shoots something or
gets the right math answer, increase their score.
• Step 1 – Add Score Text.• Step 2 – Add Score Number.• Step 3 – Build and Run.
VIDEO GAME PROGRAMMING
STEP 1: Add Score Text
• Add a new Text Object to level1.• Set the following properties:1. Name: ScoreText2. Type: Text3. Color: Red4. Initial Value: Score
VIDEO GAME PROGRAMMING
STEP 1: Add Score Text continued…
5. Position:Left: 0Top: 520Right: 70Bottom: 550
VIDEO GAME PROGRAMMING
STEP 2: Add Score Number
• Add a new Text Object to level1.• Set the following properties:1.Name: ScoreNumber2.Type: Number3.Color: Red4.Font Size: 265.Initial Value: 0
VIDEO GAME PROGRAMMING
STEP 2: Add Score Number continued…
6. Position:Left: 0Top: 550Right: 200Bottom: 600
7. Behavior: TextScoreUpdateFN
VIDEO GAME PROGRAMMING
STEP 3: Build and Run
• Build and Run your game.• You should see your score go up
every time you get the right answer.
VIDEO GAME PROGRAMMING
PART 18 – Multiplayer
Objective:– Now we’re going to add a 2 player mode.
• Step 1 – Add More and Less Sprites to Title level.
• Step 2 – Add Player Number and Text to Title Level.
• Step 3 – Build and Run.
VIDEO GAME PROGRAMMING
STEP 1: Add More and Less Sprites to Title Level
• In the title level, insert a copy of the quit sprite and name it more.
• Set these properties for more:1. Actor: BUTTON_MORE2. Initial Animation: NORMAL3. Behavior: Remove ButtonQuitFN and
ADD ButtonMorePlayersFN.4. Position: x= 0, y= 0
VIDEO GAME PROGRAMMINGSTEP 1: Add More and Less
Sprites to Title Level continued…
• Insert a copy of more and name it less.
• Change these properties for less:1. Actor: BUTTON_LESS2. Initial Animation: NORMAL3. Behavior: Remove
ButtonMorePlayersFN and ADD ButtonLessPlayersFN
VIDEO GAME PROGRAMMING
STEP 2: Add Player Number and Text to Title Level
• Add a new text object to title.• Set the following properties:1. Name: PlayersText2. Type: Text3. Font Size: 204. Color: Anything5. Initial Value: Players
VIDEO GAME PROGRAMMING
STEP 2: Add Player Number and Text to Title Level continued…
6. Position:Left: 0Top: 0Right: 100Bottom: 50
VIDEO GAME PROGRAMMING
STEP 2: Add Player Number and Text to Title Level continued…
• Add a new text object to title.• Set the following properties:1. Name: PlayersNumber2. Type: Number3. Font Size: 204. Color: Anything5. Initial Value: 16. Behavior: TextNumPlayersFN
VIDEO GAME PROGRAMMING
STEP 2: Add Player Number and Text to Title Level continued…
7. Position:Left: 0Top: 0Right: 40Bottom: 50
• Now use the Level Preview to place the new sprites and text.
VIDEO GAME PROGRAMMING
STEP 3: Build and Run
• Build and Run your game.• You should be able to select 1 or 2
players at the title screen.
VIDEO GAME PROGRAMMING
PART 19 – Add Player 2
Objective:– Now we’re going to add the second
player. They can use the <alt> key to shoot. The second player will shoot the second number in our math equation.
• Step 1 – Add player2 Sprite to level1.• Step 2 – Build and Run.
VIDEO GAME PROGRAMMING
STEP 1: Add player2 Sprite to level1
• In level1, insert a copy of the player1 sprite and name it player2.
• Set properties for player2 sprite:1. Unused: Check this2. Initial Animation: TWO3. Position: Use <…> to set manually
VIDEO GAME PROGRAMMING
STEP 1: Add player2 Sprite to level1 continued…
4. Behavior: Remove KeyboardWASDMovementFN and KeyboardShootFN. ADD KeyboardArrowMovementFN and KeyboardShoot2FN.
VIDEO GAME PROGRAMMING
STEP 2: Build and Run
• Build and Run your game.• You should now be able to play a 2
player game!• Player 2 uses the arrow keys to
move and <alt> to shoot.
VIDEO GAME PROGRAMMING
PART 20 – Enemies Part 1
Objective:– Add enemies with their own projectiles,
movement patterns, and particle explosions.
• Step 1 – Create Enemy and Enemy Projectile Art.
• Step 2 – Add Enemy and Enemy Shot Actors.• Step 3 – Add Enemy and Enemy Shot Sprites.• Step 4 – Build and Run.
VIDEO GAME PROGRAMMING
STEP 1: Create Enemy and Enemy Projectile Art
• In MS Paint create 2 images:1. enemy.bmp (60x60)2. enemyShot.bmp (16x16)3. Save them both in the Actors
folder.
VIDEO GAME PROGRAMMING
STEP 2: Add Enemy and EnemyShot Actors
• Create 2 new Actors:1. ENEMY
1. New Animation Set: DEFAULT2. Uses enemy.bmp3. Give it collision data.
VIDEO GAME PROGRAMMING
STEP 2: Add Enemy and EnemyShot Actors continued…
2. ENEMY1. New Animation Set: DEFAULT2. Uses enemyShot.bmp3. Give it collision data.
VIDEO GAME PROGRAMMING
STEP 3: Add Enemy and EnemyShot Sprites
• Add a new Sprite in level1 and set the following properties:
1. Name: enemy2. Map: main3. Unused: checked4. Display List: 15. Local Data: ShotData
VIDEO GAME PROGRAMMING
STEP 3: Add Enemy and EnemyShot Sprites continued…
6. Actor: ENEMY7. Initial Animation: DEFAULT8. Behavior:
SpriteDeleteBelowViewportFN, EnemyShootFN, SpriteDecreasePlayerHealthFN
9. Collision: Precise, Activate, Check With Sprites, Ghost Collision
VIDEO GAME PROGRAMMING
STEP 3: Add Enemy and EnemyShot Sprites continued…
10.Speed: 411.Vector Direction: Y = 1
VIDEO GAME PROGRAMMING
STEP 3: Add Enemy and EnemyShot Sprites continued…
• Insert a copy of playerShot named enemyShot and set the following properties:
1. Display List: 12. Actor: ENEMYSHOT3. Initial Animation: DEFAULT
VIDEO GAME PROGRAMMING
STEP 3: Add Enemy and EnemyShot Sprites continued…
4. Behavior: REMOVE SpriteDeleteNumberOnCollisionFN and SpriteDeleteOperatorOnCollisionFN. ADD SpriteDecreasePlayerHealthFN.
VIDEO GAME PROGRAMMING
STEP 4: Build and Run
• Build and Run your game.• What happens?• Why?
VIDEO GAME PROGRAMMING
PART 20 – Enemies Part 2
Objective:– Now that we have actors and sprites, let’s add
some behavior to make everything work.
• Step 1 – Add Spawn Behavior to level1.• Step 2 – Add Behavior to Sprites.• Step 3 – Add a New Particle System.• Step 4 – Build and Run.
VIDEO GAME PROGRAMMING
STEP 1: Add Spawn Behavior to level1
• Add the LevelEnemySpawnFN function to level1.
VIDEO GAME PROGRAMMING
STEP 2: Add Behavior to Sprites
• Add the SpriteDeleteEnemyOnCollisionFN function to the following sprites:
1. playerShot2. playerShot23. player14. player2
VIDEO GAME PROGRAMMING
STEP 3: Add a New Particle System
• Insert a copy of the ExplodeRed particle system and name it ExplodeEnemy.
• Go ahead and change the properties of this one to whatever you want.
VIDEO GAME PROGRAMMING
STEP 4: Build and Run
• Build and Run your game.• You should be able to shoot your
enemies as they fall. You should also be able to run into them and destroy them.
VIDEO GAME PROGRAMMING
PART 21 – Enemy Movement
Objective:– Add a simple movement pattern to
enemies.
• Step 1 – Create a new Movement Pattern.
• Step 2 – Add it to the enemy Sprite.• Step 3 – Build and Run.
VIDEO GAME PROGRAMMING
STEP 1: Create a new Movement Pattern
• Create a new Movement Pattern.• Name it EnemyMP.• Use the Free Track tool.
VIDEO GAME PROGRAMMING
STEP 2: Add it to the enemy Sprite
• Open the properties for the enemy sprite.
• Check Movement Pattern and use EnemyMP.
• Check both the Initially Started and Loop boxes.
VIDEO GAME PROGRAMMING
STEP 3: Build and Run
• Now Build and Run your game.• The enemies should be following the
new movement pattern.• Change it around until you’re happy.
VIDEO GAME PROGRAMMING
PART 22 – Health
Objective:– Add player health to the game.
• Step 1 – Add Health Text.• Step 2 – Add Health Numbers.• Step 3 – Build and Run.
VIDEO GAME PROGRAMMING
STEP 1: Add Health Text
• Add a new Text Object to level1 and set the following properties:
1. Name: HealthText2. Type: Text3. Color: Yellow4. Initial Value: Health
VIDEO GAME PROGRAMMING
STEP 1: Add Health Text continued…
5. Position:Left: 700Top: 520Right: 800Bottom: 600
VIDEO GAME PROGRAMMING
STEP 2: Add Health Numbers
• Add a new Text Object to level1 and set the following properties:
1.Name: HealthNumber12.Type: Number3.Font Size: 284.Color: Red5.Initial Value: 3
VIDEO GAME PROGRAMMING
STEP 2: Add Health Numbers continued…
5. Position:Left: 710Top: 550Right: 750Bottom: 600
6. Behavior: TextPlayer1HealthFN
VIDEO GAME PROGRAMMING
STEP 2: Add Health Numbers continued…
• Insert a copy of HealthNumber1 and set the following properties:
1.Name: HealthNumber22.Color: Blue3.Unused: check this
VIDEO GAME PROGRAMMING
STEP 2: Add Health Numbers continued…
4. Position:Left: 750Top: 550Right: 800Bottom: 600
5. Behavior: REMOVE TextPlayer1HealthFN. ADD TextPlayer2HealthFN.
VIDEO GAME PROGRAMMING
STEP 3: Build and Run
• Build and Run your game.• You should be able to get hit by the
enemies and have your health decreased (same goes for player2).
• Also, running into enemies should lower your health.
VIDEO GAME PROGRAMMING
PART 23 – Victory Screen
Objective:– Add a victory screen that prompts the player to
play again.
• Step 1 – Make Ending Screen Art.• Step 2 – Add Map to Victory Level.• Step 3 – Copy Sprites to Victory Level.• Step 4 – Build and Run.
VIDEO GAME PROGRAMMING
STEP 1: Make Ending Screen Art
• In MS Paint, create 2 images:1. victory.bmp (800x600)2. gameover.bmp (800x600)3. Save them both in your Maps
folder.
VIDEO GAME PROGRAMMING
STEP 2: Add Map to Victory Level
• Add a new Map to the victory level.
1. Map Name: main2. File Name: victory.bmp
VIDEO GAME PROGRAMMING
STEP 3: Copy Sprites to Victory Level
• You can copy sprites from one level to another by holding <ctrl> and dragging a sprite from one level to another.
• Drag these sprites from title into victory:
1. Cursor2. Start3. Quit
VIDEO GAME PROGRAMMING
STEP 3: Copy Sprites to Victory Level continued…
• Open the properties for the start sprite in the victory level.
• Change these properties:1. Name: play2. Actor: BUTTON_PLAY3. Initial Animation: NORMAL4. Behavior: REMOVE ButtonStartFN and
ADD ButtonPlayAgainFN.
VIDEO GAME PROGRAMMING
STEP 3: Copy Sprites to Victory Level continued…
• Go into the victory level preview and place the new sprites wherever you want them.
VIDEO GAME PROGRAMMING
STEP 4: Build and Run
• Now Build and Run your game.• Try and win if you can!
VIDEO GAME PROGRAMMING
PART 24 – Game Over Screen
Objective:– Add a game over screen that prompts
the player to play again.
• Step 1 – Add Game Over Level.• Step 2 – Set Level Properties.• Step 3 – Build and Run.
VIDEO GAME PROGRAMMING
STEP 1: Add Game Over Level
• Insert a copy of the victory level and name it gameover.
• In the gameover level, open the properties for the main map.
• Change the File Name to gameover.bmp
• Go into the Level Preview and place things where you want them.
VIDEO GAME PROGRAMMING
STEP 3: Build and Run
• Build and Run your game.• You should have:1. 2 Player Mode2. Enemies that shoot3. Numbers4. Mad math stuff5. Ending Screens
VIDEO GAME PROGRAMMING
CONGRADULATIONS!
• You’ve just finished Number Attack• If you want to add more levels,
insert a copy of level1 only make sure you select Insert After level1!!! If you don’t, things will break.
Recommended