Cocos2d-x game instances (15)-vertical version shooting game (2)

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

The previous article introduced the basic construction of the vertical version of the shooting game. This article is further improved. We continue to improve our game. First, we have many game elements in the vertical version of the shooting game, including the main character, bullet, and enemy, we first define all of these as a base class gamesprite. The definition is as follows:


Each of our game elements includes a ccsprite. We need to define its get and set functions so that we can get the genie. Then we need an integer state variable to record the current state of the element, in addition, the collision function is used to handle collisions. In addition, we also have a processing logic function tick, and we also need a setposition function that can set the main character position.

First, we define a role to inherit from gamesprite and implement the above functions respectively. When constructing the function, we can use the spritewithfile function of ccsprite to obtain ccspirte, the subsequent location setting is to set the location for ccsprite. The logic of the protagonist is controlled by the player, so tick is empty, and the rest is get and set. As for the collision, we will consider it later, in this way, we simply implement a gamesprite. All enemies and bullets regard gamesprite as the base class, and then we can make corresponding changes in the scenario class.

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.