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, we added a motion track to the enemy and the enemy can appear again. This article continues with the previous article and adds the bullet launching function to the enemy. The effect is as follows:
First, add a bullet to the enemy. Just like adding a bullet to the protagonist, we createGamebulletArray and initialize it,CodeAs follows:
Note: Here, I setTypeAttribute. This is to distinguish the bullets of the main character, because their motion tracks are different.TypeDifferent (main character bulletTypeSet0).TypeDifferent bullets are controlled in different bullet logic. As shown in the following code:
So how can we let the protagonist issue a bullet? We can control it in the enemy's logic, add a bullettick variable to the enemy, set a value, and let the value automatically increase before it reaches this value, when this value is reached, we will clear the value0The Code is as follows:
If the enemy does not exit the screen, add the bullettick, clear it when it reaches a certain value, and play the bullet in the following code, as the logic of the previous protagonist shot the bullet:
If there are any errors, I hope you can correct them more.
Next article continues the vertical version of the shooting game instance