Cocos2d-x-3.3-023-imitation WeChat aircraft war-overall analysis and modeling, cocos2dx3.3

Source: Internet
Author: User

Cocos2d-x-3.3-023-imitation aircraft war-overall analysis and modeling, cocos2dx3.3

The original text is synchronously published on my wiki. To view the original text or updates, go to: Click the open link.


Overall Analysis
  • I started to understand the problem.

    1. The visible elements in the game use the is-a genie, or the has-a genie: directly inheriting the genie for relatively simple use, while using a combination strategy for complex UI composition, at this time, it is a good choice to inherit the Node and use the relationship between the has-a genie.
    2. The reflection on the bullet launching action (including generating enemy planes, playing heroes, and providing supplies), cocos provides directors and scenarios for process control, while the layer is a canvas; the genie is an element on the canvas. Therefore, you must specify the canvas to which a bullet belongs when launching or creating a bullet. Then the child plays the animation.
    3. In order to separate the relatively independent ui display and reduce code coupling, it is a good practice to place different functions on different layers, such as the background layer and control layer.
    4. How many pixels per second is the speed? This problem applies to other elements, such as the life value, attack power, and flight speed. In a real game development team, this job should be planned by a dedicated team. Here we will make initial adjustments according to the running results.
    5. How can I create a role on the canvas based on the story or level? Provides a level manager. Its power source is the scheduler. Set a scheduler callback for him, and then generate enemies Based on the settings of the current level continuously in the callback, similar to actionManager.
    6. The whole process of the game is to make a movie: the General Director arranges a good person to frame the camera, selects the shooting scene, and determines whether the scene is switched. The general director is responsible for these major events. The details should be handed over to the deputy director. The Deputy Director should look for the masses and actors, arrange the playing sequence, and drive the logic-collision monitoring on the field. The scripts for each level are different. The script Administrator is responsible for configuring and managing the story.
    7. The main character and the masses of actors make different makeup Based on the plot configuration, with different equipment, different skills, and so on.
    8. The relationship between the display of the UI Button and the main character: In my understanding, the two should not be the relationship between is-a and has-a, but the relationship between publishing and subscription.
  • Thoughts on Expansion

    1. I have also read some examples, including the column mentioned in the previous article. Is collision detection performed by 'dual-loop collision detection by using an array of bullets held by the Deputy Director (or who) and an array of enemies? My idea is that the Code related to collision detection is implemented by the cocos framework and callback is provided. The client code does not need to keep two arrays and loops, but instead allows the bullets to be fired to perform collision detection by themselves, switch the status based on the corresponding callback, so the game code looks more aesthetic.
    2. This problem is caused by the above 'collision detection 'problem. Using the above collision detection scheme, the genie elements in the game are more like 'pick-up puppets ', in each frame, the "Deputy Director" must shout "for Collision Detection", and "attack upon collision '... This will exhaust the deputy director. If the sprite element can detect the collision by itself, switch the status based on the relevant callback, and play different animation effects, you can put the logic code in the "Deputy Director" into different sprite elements, such code coupling will be reduced, better encapsulation, and easier expansion.
    3. Can the physical engine meet the above requirements?
    4. For the answer, see the next section.
Detailed Item Analysis
Aircraft: Our fighters and enemy planes are all planes, the camp is different. Planes can be damaged. Planes can be repaired. Planes have guns. Bullets are fired. Planes have flight speeds. Planes have directions. Planes can get supply guns: the number of bullets fired at a time is different for different types of guns, and the number of bullets fired at a time is different: lethal, after a powerful bullet kills the enemy, its life cycle also ends? Bullet eye? Can a bullet hurt people in the same camp? First, there is no eye, there is no tangle of bullets, there is a speed, there is a starting position, the bullets have a direction to supply-blood package: + blood supply-double-row guns: Gun change, after a bullet hits the light, it switches back to the default Gun Supply-bomb: several missiles are mounted to the plane. After the bullet is launched, the whole screen will destroy the blame, supply speed, supply start position, supply direction
The following figure shows how to create a family chart.

Https://github.com/cheyiliu/All-in-One/raw/master/res/cocos2d/warofairplain.jpg

Description
  • Aircraft Series
Role: Role Definition. attributes include: Team, blood volume, attack power, and resources. Actions include determining that an enemy is a friend, attacking, being attacked, and obtaining various supplies; roleHero provides the static factory method RoleHero, which has the following attributes: Multiple guns are used for remote attacks; Various supplies are available; RoleEmemy: enemies: only attacks and attacks can be performed. RoleEnemy has three sub-classes, representing large, medium, and small enemies, and is responsible for instantiating different resources.
  • Supply System
Supply: Replenishment class, which defines basic methods and factory methods. Supply has three sub-classes for different replenishment tasks.
  • Gun and ammunition Series
Gun: a Gun that can be used to fire a bullet. It contains a static factory method. Gun has three sub-classes, containing different bullets, representing different guns. Bullet: Bullet base class, attributes are powerful, resources, and so on; behavior is killing; static factory methods are also available (for later development, check whether the requirements need to be separately separated from the factory class) bullet has three sub-classes, representing different types of bullets.
  • One note
Why do we need to provide so many sub-classes? Each system has several sub-classes. My idea is that I don't want to use too many if else when selecting different resources to represent different types of objects. If it is not subclass, the parent class will carry too many judgment statements. The above supplies and ammunition systems all act on aircraft systems.
Draft Code
  • Recently with java more, first with java made a draft, sorted out the idea, the above class corresponding code in https://github.com/cheyiliu/test4java/tree/master/src/test/cocos/airplain
  • The next step is to use c ++ and cocos mechanisms. Follow the relationships of the above classes as much as possible during implementation. Of course, necessary adjustments are inevitable.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.