We all love to play games. And surely many of us would like to create them. Today we will make a very simple flash toy. We will try to meet in half an hour ...
1. The idea.
Let it be a “find and click” game. There is a field in front of us (let it be in the form of a computer table), where the factories are hiding - the goal of our hunt. The factories will appear in different places and hide again. The player must have time to click on the factory until he hides again. Habraokhota lasts only 30 seconds, after which the player is given a report on how many hubrikov he caught. Let's start the implementation.
2. Graphics.
The game will be 3 frames. On the first, a description of the game and the launch button, on the second, the gameplay itself will occur and on the third, the game will be summed up.
To begin with we will draw a game field - provide places from where the bricks will come out. If you draw your workplace, it will be more interesting to play :)

Now we will draw the khabrikov themselves Honestly, I don't know what they look like. =) I drew such a factory.

The next step is the animation of the factory. Create a new clip, which will be our habrik. Make a simple animation (MotionTween) and add a mask - it turns out that habrik will gradually appear from below. In a separate layer, let's add a transparent hitzone clip - this will be the zone that the player should click on in order to catch the factory. In the first frame of the movie clip, write stop (); - so that the clip does not play ahead of time.

It now remains to arrange the khabrikov around the scene and give the names of their clips. Call them habr1, habr2 and habr3 - this will be used in the script.
')
3. Coding
Perhaps the code itself, I will not give here. All code takes only 60 lines along with comments and you can freely view it in the source. I will simply describe the logic. We have a function for displaying habs, which is called every 300 milliseconds. There is also a code that handles clicking the left mouse button and checks if the player caught it or missed. The last function is a timer. It counts down the time and if it is over, ends the game. The last screen is the calculation and display of statistics on the game.
That's all. Good luck to you!
This was my debut on Habrahabr. Of course, this article cannot claim to be a full guide, but after reading it you can understand the basic principles on which this game is arranged and make your version (add or remove habits, change the playing field, etc.) based on the source even less than in half an hour!
Waiting for comments and well in my
blog !
The source and the game can be found
here .