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