Cocos2d high imitation dow.jump no source code, cocos2ddo.pdf
1. Game videos
Familiar with the main character? That's right. The last time I dumped the game's "30" game, there were three types of items, including the halo of the protagonist, bamboo, wings, two types of monsters, crabs and birds, and five types of boards. Click on the screen, and 30 will launch its mouth 3 to attack the monster. For the last reference to cocos2d simple and high imitation everyday parkour game, Apple has passed the review... but it is very poor and will be updated later. In the future, more leading games will be considered.
In fact, I hate the word "high imitation" and strive for more original parts of the next game.
2. Implementation of upward hop displacement
Under normal circumstances, if you do not use anything, the protagonist jumps out of the top screen and cannot see it! There is no feeling that the main character is always in the middle of the screen in the video. How can this effect be achieved? Very simple. Here I have to vomit cocos2d. If I have studied Opengl or DirectX, I should know that a Camera exists. The 2D game only chooses parallel projection) refer to this article DirectX Camera. however, Camera before 3.2 is not available at all, and Camera is added only after 3.3. if you use Camera, it will be very easy to implement, and it is also consistent with the reality. 1. If Camera is used, PositionY of all boards is fixed. The higher the PositionY of a board, the larger the PositionY. When the main character jumps up, the PositionY of the main character increases. There is a Camera, and its position can be moved with the main character. That's simple. 2. I don't use Camera. I use cocos2d of 3.2, so it's hard to use Camera. I use the implementation of moving the entire Layer. What should I do if the protagonist jumps out of the top screen? Move the entire Layer down.
float minPositionY = 0;void update(float dt){//follow the herofloat nextPositionY = VISIBLE_HEIGHT / 2 - hero->getPositionY();if(nextPositionY < minPositionY){minPositionY = nextPositionY;this->setPositionY(minPositionY);}}
It looks simple. If the main character falls down at the bottom of the screen, there is a feeling of falling, which is logically troublesome. It is better to use Camera.
3. Board generation logic
It is troublesome. The first is the continuous generation logic of the board. It is impossible to generate dozens of boards at a time. Users on and off the screen cannot see the logic at a time. That is to say, the entire game is enough if there are more than 10 boards. No more than 10. Normal update is performed 60 times in one second. We need a whole slow timer, which will not affect performance too much. schedule (schedule_selector (GameObjectsLayer: createAndRemoveObjects), 0.064 );, create and remove unnecessary boards.
deque<JumpBoard*> _boardObjects;void generateSomeBoards(const int& lastPositionX,int startPosition,const int& count);void createAndRemoveObjects(float dt){ if(_pause == true){ return; } if(_boardObjects.size() <= 12){//generate some boards if we only have few boards JumpBoard *lastBoard = _boardObjects.back(); generateSomeBoards(lastBoard->getPositionX(), lastBoard->getPositionY() + getGeneratorHigh(),5); } //remove unused boards JumpBoard* firstBoard = _boardObjects.front(); if(hero->getPositionY() - firstBoard->getPositionY() > 600){ firstBoard->removeFromParent(); _boardObjects.pop_front(); }}
In a simple language, the above section does not provide generateSomeBoards with detailed code.
Games have many things to consider: 1. at the beginning, the distance between the two boards was shorter and seemed to be more confidential. This made the game easier to use and the distance between the two boards increased as the main character increased. 2. At the beginning, the Board generation type should be simpler. Here I only have the two types, and various types of boards will appear at the end. I am more and more aware that if the main gameplay of a game can easily be modified without understanding program logic, the game will be well written. The gameplay here is how to control the generation of boards. I must admit that this is not doing well.
typedef enum{ kNormalBoard, //0 kCloudBoard, //1 kMoveBoard, //2 kMoveLttleBoard, //3 kSpringBoard //4}JumpBoardType;int level1[] = {0,0,0,0,0,0,0,0,0,0,1,1,1};int level2[] = {0,0,0,0,0,0,0,0,0,0,1,1,2,3,4};
Here there are two arrays. They will be used to initialize two vectors <int> and then random_shuffle to shuffles them. Different arrays are selected based on the current hero height. When the index is moved to the last one, it returns 0 and shuffled again.
Int getBoardTypeDueToFloorNum () {int floorCount = getFloorCount (); int result = 0; if (floorCount <= 2) {if (_ levelIndex> = _ level1.size ()) {_ levelIndex = 0; random_shuffle (_ level1.begin (), _ level1.end ();} result = _ level1 [_ levelIndex]; ++ _ levelIndex; return result ;} else if (floorCount> 2 & floorCount <= 10) {if (_ levelIndex> = _ level2.size () {_ levelIndex = 0; random_shuffle (_ level2.begin (), _ level2.end ();} result = _ level2 [_ levelIndex]; ++ _ levelIndex; return result;} else {// infinite mode }}
Of course, the infinite mode is more complex. I shuffled five different types of arrays. I will not go into details here.
4. Position of item and monster generation
I simply processed the position of the item and the monster generation, and placed it at several screen heights.
//typedef enum{// kHelicopterItem, //0// kFlyItem, //1// kShortItem, //2// kLongItem, //3// kDefenceBall //4//}EatItemType;int allEatItemType[] = {4,4,4,0,0,1};
In order to make different items have different probabilities, the logic similar to that of the Panel subclass is used. Here there are two types of monsters, and 50% probability will generate different monsters. Dow.jump is doing a good job of metamorphosis. Before a monster appears, there will be items that will kill the monster or escape the monster.
5. Protagonist halo and parabolic drop
For more information about the elliptical movement of the protagonist's halo, see cocos2d moving around the elliptical. Another is the drop track of the item after use. This first time I played dow.jump, I was pleasantly surprised. After the time was reached, I threw it away perfectly and handled it very naturally and interestingly. The implementation is similar to the following elliptical movement. It is the parabolic form used in mathematics, but it is open-down. Only the red part on the left is used. The formula I used is x = t *-400, y = x *-0.02 (x = [0,-400]). In update, t = [0, 1]. You can use this formula.
6. Miscellaneous
Other positions such as item generation are more exquisite and finally added to the board, so that the Board moves, it will move, it will naturally point. Whether the main character hits a monster or the main character's mouth hits a monster, the monster will fly out in that direction with a rotation. This effect is very good, and you can simply calculate the angle of the next two points, give the monster a speed attribute and move it in each update frame. When the main character's mouth is flying out, it will fly back. When it comes back, because the position of the main character has been changing, it is also necessary to change the position in each update frame, getting closer and closer to the main character, like tracking missiles of airplanes. I will not go into details here.
Feeling that Cocos2d-x 3.2, this gravity sensor Accelerometer control seems to be a problem, in this game occasionally gets out of control, I still don't know the cause and regularity, very headache. There is also the speed of the game, which seems to be 60 frames, but the speed is occasionally different. I think these highly imitation games are unlikely to have a good market. They can only use their accumulated experience to create truly original games. However, these games are more interesting than those online games. Have the feeling of a real game.
Http://www.waitingfy.com/archives/1358