Aircraft War Development 05 The realization of bullets fired by angle and trailer bullets

Source: Internet
Author: User
Tags addchild

Multi-angle Bullets:

The implementation of this can still be used Moveby action to complete, set a bullet offset angle, calculated out of the screen, bullets in x shafts and y the distance moving on the axis, moving it OK up.

On the code:

void Gamelayer::createbulletbyangle (float angle) {Size screensize = director::getinstance ()->getwinsize (); VEC2 Crepos = M_pplayerplane->getposition ();//The initial position of the bullet float flytime = 1.0f; Sprite * Pbullet = sprite::create ("bullet3.png");p bullet->setposition (Crepos); AddChild (pbullet,zorder_bullet_ PLAYER);p bullet->setrotation (angle), float Varx = director::getinstance ()->getwinsize (). width-crepos.x; if ( Angle < 0) {Varx = crepos.x;} float VarY = Varx * Atan (angle); float Movedis = sqrt (Varx * varx + VarY * varY); flytime = Movedis/director::getinstanc E ()->getwinsize (). Height,//screen height as standard if (angle < 0) {VarY =-vary; varx =-varx;} Pbullet->runaction (Sequence::create (Moveby::create (FLYTIME,VEC2 (varx,vary)), Callfuncn::create (CC_CALLBACK_1 (Gamelayer::p layerbulletmoveendcallback,this)), Removeself::create (True), nullptr)); M_pplayerbullet.pushback ( Pbullet);}


Rear-end bullet effects:

like a meteor, the bullet flew out with a long tail. Seems to have seen this special effect on the Tyrannosaurus fighter, very beautiful, imitation realized a, pass the end, OK. The starting point is the position of the aircraft. No precise control of radians.

On the code:

void Gamelayer::createbulletbybezier (Vec2 endpos) {//Two control points should be on the same side of the starting point and the focus line, which will form a path with only one arc size screensize = Director:: GetInstance ()->getwinsize (); VEC2 Crepos = M_pplayerplane->getposition ();//The initial position of the bullet Vec2 cp_1 = crepos;//Control point close to the starting point Vec2 cp_2 = endpos;//Control point near end point Flo at var_x = 100.0f; float a = 0; float b = 0; if (crepos.x <= endpos.x)//1,4 Quadrant {cp_1.x + = var_x; cp_2.x + = var_x;} else//2,3 Quadrant {cp_1.x-= var_x; cp_2.x-= var_x;}  A =-(crepos.x-endpos.x)/(CREPOS.Y-ENDPOS.Y); b = crepos.y-crepos.x * A; cp_1.y = a * cp_1.x + b; b = Endpos.y- Endpos.x * A; cp_2.y = a * cp_2.x + b; ccbezierconfig bezier;bezier.controlpoint_1 = Cp_1;bezier.controlpoint_2 = Cp_2;b Ezier.endposition = endpos;float flytime = 0.2f; Auto Bezierforward = Bezierto::create (Flytime, Bézier); Motionstreak * Pbullet = Motionstreak::create (0.5f, 1.0f, 10.0f, color3b (255, 255, 0), "bullet1.png"); AddChild (pbullet,z Order_bullet_player);p bullet->setposition (crepos);p bullet->runaction (Sequence::create (BézierForward,delaytime::create (0.5f), Removeself::create (True), nullptr));} 


Aircraft War Development 05 The realization of bullets fired by angle and trailer bullets

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.