📜 ⬆️ ⬇️

We are developing the game on AS3 (Part 2: Duck Hunt mini-game)


figure 4
Duck hunt

Purpose: development of a computer game
Target audience: beginners, interested, onlookers
Tools: ActionScript 3.0


Cycle content



')

Introduction


In previous releases ...
  • Perhaps a slightly vague introduction;
  • Some set of comments is defined;
  • Created and described the required tools;
  • The task for the present part.


The inspiration for the mini-game was the old warm " Duck Hunt ". However, the repetition of anything practically deprives this process of creativity, turning it into a boring routine. Yes, and copies of this game, most likely, already have (carefully, you can get an aesthetic shock from the flight of ducks). It must be remembered that a small game is being created, so do not overload it with unnecessary features (and so there are some pretty funny variations ).
We will do some team parody of old computer games, thereby justifying any noticeable use of the objects of someone else’s copyright for which the parody is being made.



Sketch


When drafting a sketch, I stopped thinking that I was creating a game about duck hunting. In Figure 5, you can familiarize yourself with it: an abstract screen, on which abstract targets fly, which must be abstractly destroyed. Everything. Everything else details.

figure 5
Duck Hunt. Sketch


Prototype



Note 10:
For abstract purposes, one could come up with some kind of simple animation (static black square), but since I already had an animation for ducks, then I found it permissible to create the goals I needed right away. Figure 6 shows a simple UML diagram:

figure 6
Duck Hunt. Uml Chart of developed classes
On the abstract CDisplay screen, the abstract targets CTarget fly , which CTargetEmitter releases, using the CTargetFactory abstract target factory . The user is prompted to shoot down targets with abstract CWeapon weapons (with the CWeaponMagazine shots shop ).
Figure 7 shows a screenshot of the resulting prototype.

figure 7
Duck Hunt. Prototype
Ducks CDuckTarget extends CTarget become targets that are proposed to destroy from a single-shot ( CSniperRifleMagazine extends CWeaponMagazine ) sniper rifle CSniperRifle extends CWeapon .


Note 11:
CRandomTargetFactory extends CTargetFactory allows you to combine different target factories into one, so CTargetEmitter can release different goals for a particular strategy (in this case, in a pseudo-random manner).

CGame is a sequential set of CRound rounds to be displayed on the screen. A general statistics CStatistic game consists of statistics for each round. CRound carries all the necessary information in order to be able to play it: how many and with what speed to release goals, what effects to use, what to consider as a successful completion of the round, etc.


Comparison of development with and without unit testing
The answer to one of the questions of Mr. meiciuc .
Why unit testing in ActionScript ? And why is ActionScript so bad? Well, no need to list. I wanted to say that unit testing is a proven practice in general. Try reading:
  1. Is Unit Testing worth the effort? [closed] ;
  2. How not to shoot yourself in the foot ;
  3. On the use of unit tests and TDD .

Now ask your question differently: why is ActionScript so good that it won't work for him?

It should be noted that at first the game was implemented as a program in almost one class, which does everything in the “best traditions”. In Figures 8 and 9 you can look at the screenshots of this creation. This option even remained available in Git: alx.duckhunt.CDraft.

figure 8
Duck Hunt. First version

figure 9
Duck Hunt. First version
As you can see, it is very similar to what we received as a “prototype”.
This creation was developed "on the knee." So I really had the opportunity to compare the development with and without using unit testing. I even kept track of time, so I could share specific figures, but, to be honest, the development was done on a case-by-case basis, and it would not be entirely correct to make this comparison. Too many factors influenced time. In the end, I even abandoned the idea of ​​keeping a journal of the time spent.
I would like to point out that you can familiarize yourself with the extremely simple structure of alx.duckhunt.CDraft. Perhaps testing here would be superfluous. However, look at what happened in this article (further it will be even more difficult). As soon as the complexity of the project goes from a monosyllabic craft on a knee to something more complex, the benefit from the use of even partial unit testing becomes tangible:
  • Refactoring is easier;
  • It is easier to correct mistakes, and, importantly, to prevent their “reincarnation”;
  • Reusing code, not errors, is easier;
  • The search time for the error of the developed application is much less (Subjectively)

Of course, if you are developing a banner in Flash , all this will not be necessary for you.

The question deserves a separate article, which I did not plan to write.


By the way ...
  1. Applied design pattern Abstract Factory [CTarget; CTargetFactory], [CDuckTarget; CDuckTargetFactory], [CCloudTarget; CCloudTargetFactory] ;
  2. Design pattern applied Factory method CWeapon :: createMagazine ;
  3. Applied a kind of design pattern Linker [CTargetFactory; CRandomTargetFactory] ;
  4. Applied design pattern Observer [CDisplay; IDisplayListener], CWeapon implements IDisplayListener; CGame implements IDisplayListener .




"Duck Hunt"



Note 12:
I want to disappoint, but the idea of ​​embedding a mini-game in another game gradually ceased to please me for certain aesthetic reasons. Therefore, you most likely will not see her in this role. But we will be consistent, we will arrange the game as a separate one, the good will not disappear.
We will not discuss here which of my "designer". CDuckHuntGame extends CGame adds a user interface and some styling to our mini-game.
CNickGenerator is a simple generator of funny nicknames inherent in one famous game.
Clouds are defined as targets in the usual way ( CCloudTarget extends CTarget , CCloudTargetFactory extends CTargetFactory ). It is not necessary to destroy such targets, so they are brought out of the current list of targets. The factory is able to generate animation for clouds of various sizes from a primitive cloud. In Figure 10 you can admire an example of what is produced.

figure 10
Duck Hunt. Cloud show
Figure 11 shows a screenshot of the resulting game.

figure 11
Duck hunt

Note 13:
I don’t insert a SWF video into the article, and my website on a free hosting will obviously not be happy even with a relatively small influx of visitors. I decided to look for a platform where I could post my video, and it would be available to everyone. During the search, the service “rawgit.com” was found, which provides a wonderful opportunity to open a file hosted on “github.com” right in the browser.
Demonstration of the game (attention! Sound!).


Note 14:
If you try to assemble a SWF movie yourself, then note that in order for all the ducks to be in place, they must first be removed from the project and then added again. This is how Flash works. We will fix this situation later when the application context setting tool appears.


Conclusion


In the next issue:



Source: https://habr.com/ru/post/241917/


All Articles