Demand analysis
Now that we're playing a plane game, what are some of the game objects we need? Take a look at the pictures in the game below. First of all, the protagonist is of course a plane, there are player planes, wingman on both sides, enemy aircraft. Aircraft are equipped with a variety of weapons: ordinary bullets, missiles, lasers and so on. If it's just a constant plane, the bullets don't change and the plane doesn't change, it's too boring. So we also added props, when the enemy aircraft were shot down, there will be a certain chance to burst gems and other kinds of bonus items, such as weapon upgrades, fighter storm, repair armor, super Kill, Quantum shield.
Let's sum it up:
- What are the basic functions of airplanes? Flying, shooting, explosion;
- What are the basic properties of airplanes? Life, attack, collision body, appearance;
- What kinds of airplanes are there?
- Player aircraft: With special control mode, specific murmured, right-flying, and other special appearance of violent deformation;
- Wingman: Player aircraft affiliated, life: Invincible, with the player aircraft coexistence dead;
- Will kill wingman: invincible, Flight movement fixed: fly out from below, shooting n seconds, fly down;
- Enemy aircraft: From somewhere on the screen automatically fly out, do not shoot or automatic shooting;
- Advanced enemy aircraft: from somewhere on the screen automatically fly out, fly to a fixed position, deformation, and then shoot;
- Boss: The initial action and high-level enemy aircraft, but boss support multiple deformation, when the amount of blood less than a certain number of fixed value, will trigger the boss deformation, each deformation once, damage enhancement. When the boss is shot down, it creates a huge explosion.
- What are the basic functions of weapons? Fire, explosion;
- What are the basic attributes of a weapon? Attack, collision body, appearance;
- What kinds of weapons do they have?
- Bulk bomb: All kinds of parallel, flowering bullets;
- Custom bullets: detailed later;
- Tracking missiles: The closest enemy aircraft will always be tracked until the enemy plane is shot down;
- Laser: Rectangular shape, the damage value is calculated by the time of contact;
- What are the basic functions of props? Flight
- What are the basic properties of props? The type of props, different props to the aircraft have different effects;
- What kinds of props are there?
- Gems: Equivalent to Money, can be used to unlock, buy other equipment
- Weapon Upgrade: Increase the weapon level of a player's aircraft;
- Fighter: The weapon of the player's aircraft is raised to the highest level;
- Repair Armor: Restore the player's aircraft a certain health value;
- Super kill: Fly a huge wingman from the bottom of the screen, emit a super laser, kill all the enemy planes in the screen (e.g.);
- Quantum Shield: Adds a shield to the player's aircraft that can withstand a single bullet attack, while the shield is hit to release a special amount of energy that transforms all the bullets in the screen into gems;
"Super must kill" the clear screen effect is not feeling very good!!
Is there a translucent blue ring on the periphery of the golden plane in the lower right corner? This is the quantum shield.
Class design
Well, the demand analysis is almost over, let's now abstract these game objects, such as:
- First, we analyze all the game objects and summarize gameobject, a class derived from the Sprite, which contains several common methods: Pause ()/resume ()/getbody ()/setbody (),
- Pause ()/resume (): Pauses and resumes movement of the game object. These two functions are different from the pause ()/resume () in node, which causes all child nodes to invoke pause () and resume () while pausing/resuming the game object itself;
- GetBody ()/setbody (): For the sake of simplicity, we don't use the physics engine, we define the collision body. Each game object has a collision body, when the collision of different game objects collide, will have different effects, such as explosions, generate rewards and so on. The body here is a simple rectangle, and we define the size of the rectangle and the position relative to the sprite.
- Then, the aircraft (aircraft), weapons (Bulletgroup/bullet), props (reward) are inherited from the gameobject.
Here we need to focus on bulletgroup and bullet. We can interpret the Bulletgroup as a gun containing a magazine, and interpret the Bullet as a single bullet . The Gun (Bulletgroup) contains n rounds (Bullet). Gun (Bulletgroup) different, determines the appearance of the Bullet (Bullet), the initial position of the bullet and flight trajectory, the frequency of the projectile and the number of simultaneous injection of different. So, we put vector<bullet> this member variable in the Bulletgroup, which is a simplified "slug pool" that gets bullets from the pool when bullets are fired, and when bullets explode or fly out of the screen, the bullets need to be recycled and put back in the pool.
Next, we'll combine the code to tell a variety of game objects.
Imitation "Thunder Fighter" flying shooter Tour development--game object