ActionScript 3.0 Pong

January 29th, 2008

I’ve finally put my hands on ActionScript 3.0 and I created a Pong game from scratch.

(Either JavaScript is not active or you are using an old version of Adobe Flash Player. Please install the newest Flash Player.)
You need Flash Player 9 to see the contents.

Instructions:

Select one of the 5 modes. Try the full-screen mode.
Keyboard control keys are: Q and A.
Click on the “Game Over” sign to play again.

ActionScript

The game was made entirely using ActionScript 3.0. The .fla file is empty, no symbols in the library. The graphics are created using the drawing API. It has only one reference to a Main class which is used to instantiate the Game class and load the sounds.
The pong game package has the following classes:

  • Main. Controls instances of the PongMenu class and the Game class.
  • Game. Handles the game logic.
  • Solid. Super class for both paddles and ball. Handles the physics.
  • Paddle. Represents a paddle.
  • Ball. Represents the ball. Checks collisions agains borders and paddles.
  • PongArtist. Draws the net and the “game over” sign, on any sprite.

Controllers

  • controllers.PongController. Controls a paddle. This is a super class for the other 3 controllers: keyboard, mouse and AI.
  • controllers.MouseController. Controls a paddle according to mouse cursor position. Speed can be adjusted.
  • controllers.KeyboardController. Controls a paddle reading the keyboard input. Speed can be adjusted.
  • controllers.AIController. Controls a paddle automatically. Difficulty level can be adjusted.

Menu & Score

  • PongDigit. Draws a digit from 0 to 9. Used by Game to display the score.
  • PongMenu. Handles the main menu with the title and the 4 options.
  • PongMenuButton. Extends Sprite and represents a menu button.

Source code

You can now download the source files.

3 Responses to “ActionScript 3.0 Pong”

  1. Unai Says:

    Impressive!

  2. Daniel D'Cotta Says:

    Interesting way of displaying the score and the “Game Over” sign with drawRect().

  3. Phantobass Says:

    Awesome, thanks for sharing your code too!

Leave a Reply