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.