Week 1 Day 4: Finish up the Pong Game and Start a Side-Scrolling Platform Game

Learning Objectives:

Finalize Pong Game:

  • Add keyboard interaction
  • Reduce code duplication using functions

Hairstyle Customization Lab:

  • mouse up event
  • controlling the playhead using gotoAndStop() to change visual content of a movieclip

Side-Scrolling Platform Game:

  • Write code to handle key down event, so that pressing LEFT or RIGHT arrow keys moves the platforms, the spinning coin, and the "?" box; pressing SPACEBAR makes the character jump.

How the Completed Files Work:

File #1: Organize code using functions, and reduce code duplication by organizing code using functions

Same game play as before, but part of the code is organized using functions. Also document the code (commenting).

 

File #2: Add keyboard interaction
Implement one or both of the following features:

(1) Rotate the paddle upon a key press

How the Completed File May Work:
Rotate the paddle when you hold down the SPACEBAR. The paddle returns to the upright position when the SPACEBAR is not pressed.
(Note: Click inside the area first. Othewise, it won't respond to the key press.)

(2) Program a cheat

For example, lengthen the paddle upon a key press so that it will be "almost" impossible to miss the ball.

How the Completed File May Work:
Lengthen the paddle upon pressing the SHIFT key. The paddle returns to the original length when the SHIFT is not pressed.
(Note: Click inside the area first. Othewise, it won't respond to the key press.)

 

File #3: Hairstyle Customization

Click on the hair icons on the right to change the hair on the head.

 

File #4: Starting a Side-Scrolling Platform Game

  • 2 instances of the platform, a coin, and a "?" box can scroll with LEFT and RIGHT arrow keys.
  • No gravity applied yet
  • No endless scrolling yet (you will see the end of the platform)
  • No collecting the coin or "?" box yet
  • The hero is not jumping up yet

 


Extra Effort:

Extra #1:
The "bounciness" of the ball determines how many points you get. Catching a bouncy ball gets you more points.
Hint: You may need to use Math.abs(). Look it up in Flash Help.


Extra #2:
Add code to make the game into a two-player game, with the following specifications:

  • A second paddle on the right. This paddle is controlled by UP and DOWN arrow keys.
  • A second score textbox. One textbox keeps score for the player on the left, and the second textbox keeps score for the player on the right.
  • Whenever the ball goes off the edge, it will restarts at the center of the stage.
  • The second paddle should not go off the top and bottom edge.
  • Of course, the ball bounces off the second paddle too.