Cocos2d-x game instances (20)-vertical version shooting game (7)

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, 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

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.