Step by step AS3 translation of Flash game creation tutorial – part 2

This is the second part of Tim Edelaar‘s step by step AS3 translation of Flash game creation tutorial.

Now it’s time to translate to AS3 the content of Flash game creation tutorial – part 2 which I suggest you to read before this one.

The style of the coding is the same of the previous part, with actionscript written directly in the timeline with the critical parts commented.

The bounds

The coin – 1st attempt

The coin – 2nd attempt

The coin – 3rd attempt

And that’s all for today.

Download source codes and thank Tim Edelaar for the contribution

  • I think, when using circles, you might want to do a radius+radius distance test fro a very accurate hittest.
    For example:
    var dx = ball.x-coin.x
    var dy = ball.y-coin.y
    var dis = Math.sqrt(dx*dx+dy*dy)
    if (dis < (rad1 + rad2)) {
    // it hit
    }

  • Alex L.

    One thing you may want to do is make it so the coin cannot appear in the black border, or else it is impossible to get.

  • Robin W.

    @Alex L.
    That has already been taken care of with this code:
    coin.x = Math.random()*510+20; //Changes the x of the coin to a random number between 20 and 530.
    coin.y = Math.random()*360+20; //Changes the y of the coin to a random number between 20 and 380.

  • sorby

    @ Robin W
    That has already been taken care of with this code:
    coin.x = Math.random()*510+20; //Changes the x of the coin to a random number between 20 and 530.
    coin.y = Math.random()*360+20; //Changes the y of the coin to a random number between 20 and 380.

    The only problem is that the width of the stage is 500, so if your getting a random number between 510 and 20 there’s a chance the coin may appear off the screen.

  • ZealousZephyr

    I wrote a function for circle hit tests for a game before.

    function circleHitTest(
    circ1:MovieClip,
    circ2:MovieClip,
    extra:Number = 0):Boolean{
    //get distances between two circles
    var dx:Number = circ1.x – circ2.x;
    var dy:Number = circ1.y – circ2.y;
    //get “direct” distance
    var td:Number = Math.sqrt(dx*dx + dy*dy);
    //if the radius of both circles is
    //larger than the distance, then hit
    if(td < circ1.width/2 + circ2.width/2 + extra){
    return true;
    }
    return false;
    }

    (I hope the code displays correctly.)
    The “extra” parameter is if you want it to register as a hit if they are further away from eachother(I used it in my game to make sure that circles don’t spawn to close to each other).

  • kyle_mantesso

    hey just wanted to thank you for all the tutorials! im writting a game in AS3 using the nintendo wiimote for uni and I have found these tutorials very useful, thank you!

  • escorpior

    Realy nice tutorial, thank you very much.

  • billetdoux

    wow great work! just wondering if there’s the part 3 for this version of the tutorial :3