Cocos2d simple high imitation everyday cool running game

Source: Internet
Author: User
1. view the game's appearance directly on the video (GIF cannot meet the game's display)



The most tangled part of the game is the map. collision is simple. You can write or use physical engines such as box2d on your own. The features of the game map are randomness. However, there are some specific plans at random, which gives gamers a little surprise. So I plan to implement it like this: write dozens of maps in the map editor, then shuffles them, and then shuffles them from the first one until the last one, take the first one. In this way, we can highlight the characteristics of everyday parkour games. There are specific random arrangements.

Creating a map in the game cannot be completed at one time, which is too slow. The screen on the mobile phone is as long as it is. Initializing two maps is enough. When you are about to get dressed, draw a new map and paste it behind the second map. When the first map is moved to the left of the screen, it can be deleted. In this way, it is enough to keep two maps. Similar to repeated background movement.


2. Custom simple map editor


After deciding to use the map editor, one problem is to use the tiled map or do it by yourself.

What I don't like about tiled map is that every square in it is an genie. This way, a large image is split into small blocks, which is very inefficient. If you use a custom object, you cannot view the map effect in real time. Try to write a simple map editor for the game.

My requirement: You can drag an element to the map and export a file containing content in a custom format for use in my game.


What to do is the following problem:

The map editor can be implemented using ordinary QT to achieve effects similar to tiled map. Tiled map is open-source and can be implemented by referring to it. But you don't have time to do this. We use cocos2d as the map editor. Of course, we recommend that you refer to tiled map to implement a very complicated editor.

I made a demo of the map editor and found it easier than I thought:

That is, some small genie are placed on the rightmost and cannot be moved. Each time you touch them, a new genie is generated and can be dragged. In this way, you can place it at will.


What format should map file data be stored?

XML. JSON is the two types I want to consider. I think JSON will be better. In the future, cocos2d JS can be directly included without parsing. Of course, the C ++ side still needs to be parsed. Cocos2d comes with rapid JSON, and parsing is not a problem. It is decided to use JSON.

The data format is roughly as follows:

{    "Bones": [{        "positionX": 1657.18,        "positionY": 345.044    }, {        "positionX": 1522.69,        "positionY": 336.114    }, {        "positionX": 1435.41,        "positionY": 259.934    }],    "TopBlocks": [{        "positionX": 2439.34    }],    "Blocks": [{        "blockType": 2    }, {        "blockType": 0    }, {        "blockType": 2    }}]}

The map editor is as follows:



A simple list. Click a map to edit a file. This map editor is relatively long, with around 3000 pixels. Of course, it can be moved infinitely to the right.



3. Simple collision


I wrote it myself here, but I didn't use a physical engine. It is also relatively easy. A trick is to give the protagonist a nextpositin variable. The position value of the role is set to nextposition only after the collision.

For example:


For (square * Square: squares) {If (hero-> nextright ()> = square-> getleft () {// right-side collision if (hero-> right () <square-> getleft () {If (hero-> bottom () <square-> gettop () & hero-> top ()> Square-> getbottom ()) {hero-> fixrightcoll (square); // collision repair and trigger events} If (hero-> left () <= square-> getright ()) {// The following collision if (hero-> bottom ()> = square-> gettop () & hero-> nextbottom () <= square-> gettop () & hero-> top ()> Square-> gettop () {hero-> fixtopcoll (square ); // collision repair and trigger event} // The above collision else if (hero-> top () <= square-> getbottom () & hero-> nexttop ()> = square-> getbottom () & hero-> bottom () <square-> gettop () {// What is done after collision }}}}

Of course, collision with gold coins and other things can directly determine whether the two rectangles are intersecting.

    for(Bone* bone : bones){                if(hero->right() >= bone->getLeft()){            if(bone->getRect().intersectsRect(hero->getRect())){                bone->removeFromParent();                bones.eraseObject(bone);                sRunGlobal->boneCount = sRunGlobal->boneCount + 1;                RunSound::playEffect(boneEffectName);                break;            }        }            }


4. Reuse of Objects


The game is designed to create a large number of objects and eliminate them. You must reuse the object to create a simple cache pool. For more information, see cocos2d cache pool Object reuse.


The source code and resources will not be published.

Http://www.waitingfy.com/archives/1318

Cocos2d simple high imitation everyday cool running game

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.