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