1. Game Development
  2. Game Design

Create a "Rapid Roll" Game in Flash

Read Time:12 minsLanguages:

Take a look through this Premium Tutorial and create an entertaining falling platforms game using Flash and ActionScript 3.0. Don't hit the purple platforms or move outside of the screen, or you'll lose a life!

Step 1: Brief Overview

Using the Flash drawing tools we'll create a good looking graphic interface that will be powered by several ActionScript 3 classes.

The user will be able to move a character across the stage and the platforms, you can modify the parameters in the class to customize the game.

Step 2: Flash Document Settings

Open Flash and create a 320 pixels wide, 480 pixels tall document. Set the Frame rate to 24fps.

Step 3: Interface

A colorful nice looking interface will be displayed, this involves multiple shapes, buttons, sounds and more.

Continue to the next steps to learn how to create this GUI.

Step 4: Background

Select the Rectangle Tool (R) to create a 320x480px #DEBDA0 rectangle and center it in the stage. Duplicate the previous shape and change the width to 2px and its color to #C3A287, duplicate the shape (Cmd + D) several times and move each 2px to the right to get the result shown above.

Step 5: Menu Screen

Select the Text Tool (T), choose a good looking font, and write your game title. I used this format: Candara Bold, 80pt, #746253. You can also add the player and platform graphics that we'll be creating in the next steps.

Use the same technique to create two buttons, align them to the center and name them startB and creditsB. Convert all to a MovieClip and set its instance name to menuView.

Step 6: Score & Lives

This will be the GameView. Add the background MC to the stage and create two Dynamic TextFields and place them as shown in the image. You can also add some simple shapes behind the TextFields to make the text more clear.

Step 7: Player

Use the Rectangle Primitive Tool (R) to create a 30x30px square and fill it with #CC6600. Duplicate the shape, change its size to 28x28px and use this gradient fill: #F9D03 to #EA7736. You can add an icon or letter to identify your character, I've used the a from the ActiveTuts+ logo.

Lastly, select the bottom part of the shape (as shown in the image) convert it to MovieClip and name it hArea, this will be really useful for avoiding unwanted collisions with the blocks. Select all the shapes and convert them to a single MC; name it Player and mark the Export for ActionScript box.

Step 8: Blocks

Use the same technique used in the last step to create two 60x14px blocks, convert them to MC, name the grey one Block and the purple one BadBlock. Don't forget to mark the Export for ActionScript box.

Step 9: Alert

An alert will be shown when you lose all your lives, it will show the final score you reached. Use the Rectangle Primitive Tool to create it and add the filter shown in the image for a better look. Set its instance name to AlertView and mark the Export for ActionScript box.

Step 10: Credits

This screen will be easy to make as we already have all the graphics. Set its instance name to CreditsView and mark the Export for ActionScript box.

Step 11: Tween Nano

We'll use a different tween engine from the default included in Flash, this will increase performance as well as being easier to use.

You can download Tween Nano from its official website. For info on installing it, read this tutorial.

Step 12: Soungle

We'll use Sound Effects to enhance the feeling of the game (in this case to let the player know when they have lost a life), you can find the sound used in this example on using the keyword blip. Save the sound in your Library with a Class Name of Blip.

Step 13: Create a new ActionScript Class

Create a new (Cmd + N) ActionScript 3.0 Class and save it as in your class folder.

Step 14: Class Structure

Create your basic class structure to begin writing your code.

Step 15: Required Classes

These are the classes we'll need to import for our class to work, the import directive makes externally defined classes and packages available to your code.

Step 16: Variables

These are the variables we'll use, read the comments in the code to know more about them, some of their names are self explaining so there will be no comment there.

Step 17: Constructor

The constructor is a function that runs when an object is created from a class, this code is the first to execute when you make an instance of an object, or the first to run when the project has loaded if it is in the Document Class.

It calls the necessary functions to start the game. Check those functions in the next steps.

Step 18: Initial Listeners

We'll start by adding the mouse listeners to the buttons in the menu view, these will take us to the game screen or the credits screen.

Step 19: Game View

When the Start button is pressed, the focus is set to stage in order to receive the keyboard actions to move the player, then the Menu view is tweened and removed.

Step 20: Show Credits

The credits screen is shown when the user clicks the credits button, a mouse listener is added to the full MC to remove it.

Step 21: Create Initial Blocks

The following code adds the blocks specified in the parameter at a random position, it will also call the function to add the player to the stage.

Step 22: Add Player

The player will be added when the initial blocks are on the stage. It will appear in the center X of the stage.

Step 23: Move Player

The following code will set the appropiate movement variable value to true or false depending on which key was pressed, then the variable will be checked every frame (in another function). This will make the player move according to that variable.

Step 24: Stop Player

When the arrow keys are released the appropiate variable is set to false to stop movement.

Step 25: Add Blocks

This function is called by a Timer; it will calculate a random integer from 0 to 3, when the result equals 0, a bad block will be added, if the result is different than 0, a normal block will be added. The blocks are added to a Vector property called blocks, this way we are able to access them outside this function.

Step 26: Add Life

Another timed function, a life graphic will be added when the timer is complete. The life position will be the last block in the vector - 1.

Step 27: Game Listeners

This function adds and removes the necessary listeners to start the game.

Step 28: Animate Lives

When the player loses a life, a little animation will be shown in the lives textfield and a sound will be played to warn the user.

Step 29: Controls

In this part we start the main function of the game, this function will be executed every frame.

The next lines of code check the movement variables, if true, the player will be moved.

Step 30: Screen Boundaries

This code creates invisible walls on the sides of the stage to prevent the player from going out of it.

Step 31: Player Gravity

The player is pushed down by the gravity variable.

Step 32: Block Collisions

The next lines check for collisions between the player and the blocks. When the player collides with a normal block it stays on top of it. When a bad block is hit, a life is lost and the player is relocated.

Step 33: Blocks Gravity

Gravity affects the blocks too, but in the opposite direction.

Step 34: Remove Offstage Blocks

The blocks are destroyed when they are no longer visible on stage.

Step 35: Score

The game score raises every frame, this code changes the textfield to reflect that.

Step 36: Lives

The following lines handle the life graphic and variables.

If a Life (a 1-Up) is on the stage, it will be moved upwards, and removed if it's hit by the player or is no longer visible on stage.

Step 37: Game Over

When theplayer is out of lives, the showAlert() function is called. This function will stop the game and reveal the final score.

Step 38: Levels

You can add as many levels as you want, this is an example of how you can add a level.

When the score reached 500 the gravity increases by 1, this will make the game move faster and harder to land on the platforms, it also reduces the time the lives are added.

Try making the speed increase after every 500 points.

Step 39: Alert

This function will stop the game and reveal the final score, it also adds a mouse listener to reset the game when clicked.

Step 40: Restart

The next function will reload the SWF, resetting all variables and methods and returning to the Menu Screen.

Step 41: Set Main Class

Add the class name to the Class field in the Publish section of the Properties panel to associate the FLA with the Main document class.


You've created a very entertaining game, try to add your own features and graphics.

I hope you liked this tutorial, thank you for reading!

Looking for something to help kick start your next project?
Envato Market has a range of items for sale to help get you started.