Create a game like Perfectionism with Flash – Step 3

Welcome to the 3rd step.

At the end of step 2, we left our buttons with a rollover effect. But a button it’s not a button if you can’t press it.

Pressing the buttons

When you press a button, I want the green line to stay on the field, and the button to change color to show it has been pressed.

Line 5: Declaring an array to store the position of the horizontal button I clicked (if any). 0 means the button is not clicked, 1 means I am over it

Line 6: Same thing for the vertical one

Line 18: If the (pos-1)-th element of the horizontal_click array is equal to 1 (the button has been clicked)…

Line 19: Show the 3rd frame of the button movieclip. The 3rd frame is the same as the 2nd one, just with a different background color

You will see later in this script how do I change horizontal_click (and vertical_click)elements

Lines 32-34: Same thing as for lines 18-20, just applied to vertical buttons

Line 41: I used to draw the horizontal line only if the button was rolled over, now I draw the horizontal line also if the button is clicked

Line 45: Same thing with the vertical line

Line 51: Beginning of the function to be executed everytime the mouse is pressed

Line 52: Cycle to scan all elements in horizontal_hover and vertical_hover arrays

Line 53: If the x-th element of the horizontal_hover is equal to 1… (if the mouse is over it and the player clicked the mouse…)

Line 54: Change the x-th value of the horizontal_click array from 0 (not pressed) to 1 or from 1 to 0

Lines 56-58: Same thing as lines 53-55, just applied to the vertical buttons.

In other words, the click routine works this way: when the mouse button is pressed, I check if there is any game button that has been rolled over. There can be only one button rolled over at the same time, just like with real buttons. If I click on a rolled over button, the button becomes pressed if it was unpressed, and unpressed if it was pressed.

And that’s the result:

Now you can click the buttons and watch lines remain on the field

Adding elements

Now it’s time to add some elements to the game… I’ll add the square and the ring, this way:


Then, the source code is:

Line 7: Declaring an array called level that stores the entire 8×8 grid. The top-left cell in the grid is at level[0], while the bottom-right element is at level[63]

I coded the level this way:

0: empty cell
1: ring
2: square
3 (2+1): ring + square

Line 8: Cycle scanning all 64 level array elements

Line 9: If the x-th element of level array is equal to 1…

Line 10: Attach the ring movieclip (linked as cell) as a child of grid movieclip, and put it in the right position according to x value

Lines 12-14: Same thing as lines 9-11, just using squares (linked as atom, don’t ask me why do I use those stupid names)

And here it is:

Now we have all elements we need to make a working game… during next step I’ll show you the most hardest part… making things move and swapping elements

Meanwhile, download the source code.

  • JDog

    First Post !

    Keep them coming Emanuele, doing great ! Looking good to.

    You should make a game like Death Worm aswel, that game is as fun as heck !

  • Suely (Snakesue)

    Second Post!
    Great! Amazing!
    You shoud make a game like Block Champs.

  • Ughh…third post?

    Anyways, like Jdog said, you should make a game like deathworm.


  • Third Post!

    I have a feeling that this is going to be much better than I thought!

  • Emanuele Feronato

    At the end of this tutorial I’ll take a look at deathworm

  • Grifo

    youtube watch?v=NwSjfsC9NoU

    That’s the original Deathworm. The one at newgrounds was made by another person, and lacks gameplay features.

    I don’t find it interesting enough to turn into a good game, though, if there will not be something new gameplay-wise.

  • JDog

    Thanks Emanuele ! Made my day, its well worth it. At the moment though keep plugging away at Perfectionism !