Cocos2d-x game instances (21)-vertical shooting game (8)

Source: Internet
Author: User

Small man (Bill man) Personal Original, welcome to reprint, reprint please indicate the address, small man (Bill man) column address http://blog.csdn.net/bill_man

In the previous article, a bullet was added to the enemy. In this article, an injury was added to the main character and a bullet was added to indicate the main character's blood volume.UIFirst, let's look:

First, you can note that the lower left corner shows the main character's blood volume.CodeAs follows:

This is to define three variables based on this image and present them on the interface, and use a variable to store the current blood volume of the main character.PlaylifeWhen the main character is injured, I do the following:

We reduce the volume of blood for the main character1And then "Extinguish" A blood volume.UIAnd then handle the "injury" action of the main character.CcblinkAction, and use a variableIsreduceTo record the current injury status of the main character, because at this time, the main character should not be detected again, and will get a period of "Invincible time", and then move5.0 sThenIsreduceSet backFalse.

The following code detects the collision between the main character and the enemy bullet

IfIsreduceIsFalseThat is to say, if the protagonist is not injured, traverse the array of bullets to detect the collision.IscollisionDetects a collision. If a collision occurs, the previousReducelifeFunction and set the bullet to not display, the following isIscollisionFunction.

Then we can detect the collision between the enemy and the protagonist and implement it in the enemy's logic:

If the enemy and the protagonist collide, the enemy will die, set the particle system, and call the protagonistReducelifeAnd then2.0 sThen let the enemy be reborn.

If there are any errors, I hope you can correct them more.

Next article continues the vertical version of the shooting game instance

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.