Android cocos2d slingshot game catapult source code

Source: Internet
Author: User

Based on the following two articlesArticleStep by step.ProgramRun on Samsung Galaxy G2 and thanks to these contributors

Http://www.raywenderlich.com/4756/how-to-make-a-catapult-shooting-game-with-cocos2d-and-box2d-part-1

Http://mssyy2010.blog.51cto.com/4595971/847000

As for the program design and logic, the above two articles are very clear.

NowSource codeProvided to you, you can download from the link below

Https://github.com/PaynePan/share_src/archive/master.zip

Usage

1) decompress to the Cocos directory level, such as: D: \ cocos2d-2.1rc0-x-2.1.2 \ catapult \

Catapult has the following directories: classes and proj. Android.

2) Import proj. Android to eclipse

3) Run proj. Android/build_native.sh in cgywin to generate libgame. So

4) Compile and run it in eclipse.

Description

Notes:

The project is directly rewritten using the running helloworld, which is mainly to rewrite helloworldscene. cpp and helloworldscene. h.

 

1) the copy part of the build_native.sh resource file is omitted.

Coco2dx the biggest headache for Android is to run build_native.sh in cygwin to copy the resource files. These operations are incompatible with the permissions under win7.

So the copy part is removed. These files are already in proj. Android/asset.

2) Since cocos2d is constantly improvingCodeThere are two differences from the original article.

Original

 

Required * delayaction = Response: actionwithduration (0.2f); cccallfunc * callselecttion = cccallfunc: callback (this, callfunc_selector (helloworld: resetgame); this-> runaction (ccsequence :: actions (delayaction, callselecttion, null ));

Now
Scheduleonce (schedule_selector (helloworld: resetgame), 0.2f );

Original

 

 

 
Cctouch * Touch = (cctouch *) touches-> anyobject (); ccpoint location = touch-> locationinview (touch-> View (); location = ccdirector: shareddire () -> converttogl (location );

 

 

Change

 

Cctouch * Touch = (cctouch *) (touches-> anyobject (); ccpoint location = touch-> getlocation ();

 

3) added the logic for reloading in tick.

 

If (m_bulletbody & m_bulletjoint = NULL) {b2vec2 position = m_bulletbody-> getposition (); ccpoint myposition = This-> getposition (); ccsize screensize = ccdirector: shareddire () -> getwinsize (); static int COUNT = 0; If (++ count % 60 = 0) {cclog ("++ after X: % F, Y: % F ", position. x, position. y); If (ABS (m_bullet_position.x-position.x) <1.5f & ABS (m_bullet_position.y-position.y) <1.5f) {attachbullet (); return;} m_bullet_position = position;} // move the camera. if (position. x> screensize. width/2.0f/ptm_ratio) {myposition. X =-min (screensize. width * 2.0f-screensize. width, position. x * ptm_ratio-screensize. width/2.0f); this-> setposition (myposition );}}

 

 

Now you can play the game easily.

 

Related Article

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.