Build an AS3 Tetris Game From the Ground Up – Active Premium
plus

Build an AS3 Tetris Game From the Ground Up – Active Premium

Tutorial Details
  • Difficulty: Advanced
  • Platform: Flash
  • Language: AS3
  • Software Used: FlashDevelop (Flash Pro, Flash Builder, FDT supported)
  • Estimated Completion Time: 2 hours
Download Source Files

In today’s Active Premium tutorial we’ll be creating a variant of the classic Tetris game, explaining general game concepts as well as some specific to this genre.


This Premium Tutorial is Filled with Solid OOP Principles and a Whole Pile of Other Programming Concepts

Check out the final result below!


Introduction

Let’s start with a short history lesson for those who are not familiar with this game (even though I doubt that it’s an unknown game to anyone).

Tetris is a puzzle video game from the 80s in which pieces made out of four square units (or cells) fall down in a grid (or matrix) and you have to move and rotate them until they land so that you obtain horizontal lines of units without gaps.

The pieces in the game are called tetrominoes and are geometrical shapes composed of four squares. There are five unique tetrominoes; however in the Tetris game we use two more which are reflections of two pieces from the first five.

The game was designed and programmed by Alexey Pajitnov and released in 1984 and still remains a popular game although many variations of the game were created (but using the same concept).

To read more on Tetris game, Tetrominoes, and associated topics, you can read their wiki pages: Tetris and Tetromino.


Prerequisites

For this tutorial I’ll be using FlashDevelop (see a guide to installing and using that here) but you can use whatever software you like (Flash CS3+, Flash Builder, FDT). If you don’t like or you can’t get FlashDevelop for whatever reason I strongly recommend that you use something other than Flash because of the weak code editor it has and because we will only be writing classes and you’ll like the features that you find in a strong code editor. But if you’ll only be copying and pasting, Flash will do just fine.


Professional and Detailed Instructions Inside

Premium members can Log in and Download! Otherwise, Join Now! Below are some sample images from this tutorial.


Active Premium Membership

Activetuts+ Premium Membership

We run a Premium membership system which costs $19 a month which periodically gives members access to extra tutorials, like this one! You’ll also get access to Psd Premium, Vector Premium, Audio Premium, Net Premium, Ae Premium, Cg Premium and Photo Premium too. If you’re a Premium member, you can log in and download the tutorial. If you’re not a member, you can of course join today!

Also, don’t forget to follow @envatoactive on twitter and grab the Activetuts+ RSS Feed to stay up to date with the latest tutorials and articles.

Alex is alexxcz on Activeden
  • daniele

    Very very very great tutorial! Im impressed with your work! Thank you!

  • David

    What the heck is wrong with level 9???
    Anyways, this is a great tutorial, but it lacks some key components such as a hold function

    • Alex
      Author

      Could you specify what exactly is going wrong on level 9? Do you get an error?

      As for the missing key components I could of added many of them but the number of steps would have increased dramatically. Maybe in a future part of this tutorial.

      Thanks!

  • Tyrone

    Hello I am working through the tutorial but I am stuck on step 16:Randomization Method, when trying to compile it gives me the error 1120: Access to undefined property ALL, how would I go about fixing this please

    Thanks

    public static function get random():String
    {
    var t:String;

    for(var i:int = 0; i < 4; i++)
    {
    t = ALL[randomPosition];

    if(isRecent(t))
    continue;
    else break;
    }
    addToHistory(t);
    return t;
    }

    • http://romuhica-industry.com Romuhica

      A big thank you ! >>Because this tutorial has opened for me the way to game development with Flash, and more broadly of games! ^ ^ Alex, you come from C + +? How to program your talking to me!

      Otherwise, I develop a Tetris, “New Tetris,” it based on your work, but on Android ! With a combo system and more. If you want, I send the application once finished so you can congratulate you on your tutorial!

      Thank you again, thanks to you, and ActiveTuts more broadly, I am always more fun to program.

      @++

  • Franck

    First Thank you for this great tutorial! I’m really impressed!

    I used FlashDevelop4 to test the Tetris source and the start-pause button fonts are missing and no score is displayed, even if the tetris work (in both the source and in final result folders). Do you have an idea to fix this?

    Thank again,
    Franck

  • Bram

    I have the same problem that Franck is having and another question.

    This Tetris, like so many others, uses a way of rotating the blocks that is not correct.
    You should be able to rotate a block that is aligned with the side. Like a long block or an L shape.
    It doesn’t allow you to do so in this version. Anyone have an idea on how to do this?