实现子弹, 可以指定发射位置, 发发射角度, 有方向, 可以反弹
来源:互联网 发布:淘宝与天猫是一家的吗 编辑:程序博客网 时间:2024/06/10 20:25
实现子弹, 可以指定发射位置, 发发射角度, 有方向, 可以反弹,如图:
void CreateObstacleCopy::flyAction(){int currentPositionX = getPositionX();//当前坐标int currentPositionY = getPositionY();speed = CCRANDOM_0_1() *500+200;//随机速度Point destinationPosition;int tempY = directionY;if (directionY >0)//向上运动{float areaHeight = visibleSize.height-currentPositionY;//获取飞行区域高度float getRandom = CCRANDOM_0_1() *(visibleSize.width+areaHeight*2);//随机左上右的一个位置if(getRandom >areaHeight+visibleSize.width)//飞行最后触碰到左边的位置{destinationPosition = Point( 0 , visibleSize.height-(getRandom - visibleSize.width-areaHeight));directionY=1;}else if(getRandom>areaHeight)//飞行最后触碰到上边的位置{destinationPosition = Point( getRandom-areaHeight , visibleSize.height);directionY = -1;}else//飞行最后触碰到右边的位置{destinationPosition = Point(visibleSize.width, visibleSize.height-getRandom);directionY = 1;}//log("up");}else//向下运动{float areaHeight = currentPositionY;float getRandom = CCRANDOM_0_1() *(visibleSize.width+areaHeight*2);//随机左下右的一个位置if(getRandom >areaHeight+visibleSize.width)//飞行最后触碰到左边的位置{destinationPosition = Point( 0 , getRandom - visibleSize.width-areaHeight);directionY= -1;}else if(getRandom>areaHeight)//飞行最后触碰到下边的位置{destinationPosition = Point( getRandom-areaHeight , 0);directionY = 1;}else//飞行最后触碰到右边的位置{destinationPosition = Point(visibleSize.width, getRandom);directionY =-1;}//log("down");}float width = destinationPosition.x- currentPositionX;float heigth = destinationPosition.y - currentPositionY;//得到当前对象到目的地的矢量高float lenght = sqrt(width*width+heigth*heigth);//长度float radian = atan(width/ heigth);//h弧度float angle = (radian*360)/(2*3.141592);//化成角度了if(tempY<0) angle=180+angle;float during = lenght / speed;//飞行时间FiniteTimeAction* actionMoveTo = MoveTo::create(during,destinationPosition);//移动动画CallFunc * funcall= CallFunc::create(this, callfunc_selector(CreateObstacleCopy::animationDone));FiniteTimeAction* actionRotateTo = RotateTo::create(0.2,angle);//旋转动画FiniteTimeAction* task = Sequence::create(actionRotateTo, actionMoveTo,funcall, NULL);runAction(task);}void CreateObstacleCopy::animationDone()//动画结束后调用该函数{//isCreate = false;flyAction();}void CreateObstacleCopy::firstLaunch(){Point destinationPosition;//左上角到对象的角度float radian = atan(-getPositionX()/ (visibleSize.height-getPositionY()));//h弧度float angleUpLeft = (radian*360)/(2*3.141592);//化成角度了radian = atan((visibleSize.width-getPositionX())/ (visibleSize.height-getPositionY()));//h弧度float angleUpRight = (radian*360)/(2*3.141592);//化成角度了radian = atan( (getPositionY())/(visibleSize.width-getPositionX()));//h弧度float angleDownRight = (radian*360)/(2*3.141592)+90;//化成角度了 radian = atan(float(getPositionY())/ float(getPositionX()));//h弧度float angleDownLeft = -(radian*360)/(2*3.141592)-90;//化成角度了int angle = launchAngle;//传进来的方向if (angle>360+angleDownLeft)//角度转换,因为这的角度有负数,传进来的角度是正数{angle = angle - 360;}if (angleDownLeft<=angle &&angle<angleUpLeft){float width = getPositionX();float heigth = width/tan((launchAngle) *2*3.1415/360);//长不变, 算高destinationPosition.x = 0;destinationPosition.y = getPositionY()-heigth;//得到目的地位置float lenght = sqrt(width*width+heigth*heigth);speed = CCRANDOM_0_1() *200+500;float during = lenght / speed;//动画时间FiniteTimeAction* actionMoveTo = MoveTo::create(during,destinationPosition);//创建移动动画CallFunc * funcall= CallFunc::create(this, callfunc_selector(CreateObstacleCopy::animationDone));FiniteTimeAction* actionRotateTo = RotateTo::create(0.2,launchAngle);//旋转动画FiniteTimeAction* task = Sequence::create(actionRotateTo, actionMoveTo,funcall, NULL);runAction(task);} else if(angleUpLeft<=angle &&angle<angleUpRight){float heigth = visibleSize.height - getPositionY();float width = heigth*tan(launchAngle *2*3.1415/360);destinationPosition.x = getPositionX()+width;destinationPosition.y = visibleSize.height;directionY = -1;float lenght = sqrt(width*width+heigth*heigth);speed = CCRANDOM_0_1() *200+500;float during = lenght / speed;FiniteTimeAction* actionMoveTo = MoveTo::create(during,destinationPosition);CallFunc * funcall= CallFunc::create(this, callfunc_selector(CreateObstacleCopy::animationDone));FiniteTimeAction* actionRotateTo = RotateTo::create(0.2,launchAngle);FiniteTimeAction* task = Sequence::create(actionRotateTo, actionMoveTo,funcall, NULL);runAction(task);}else if(angleUpRight<=angle &&angle<angleDownRight){float width = visibleSize.width - getPositionX();float heigth = width*tan((launchAngle-90) *2*3.1415/360);destinationPosition.x = visibleSize.width;destinationPosition.y = getPositionY()-heigth;float lenght = sqrt(width*width+heigth*heigth);speed = CCRANDOM_0_1() *200+500;float during = lenght / speed;FiniteTimeAction* actionMoveTo = MoveTo::create(during,destinationPosition);CallFunc * funcall= CallFunc::create(this, callfunc_selector(CreateObstacleCopy::animationDone));FiniteTimeAction* actionRotateTo = RotateTo::create(0.2,launchAngle);FiniteTimeAction* task = Sequence::create(actionRotateTo, actionMoveTo,funcall, NULL);runAction(task);}else{float heigth = getPositionY();float width = heigth*tan((launchAngle-180) *2*3.1415/360);destinationPosition.x = getPositionX()-width;destinationPosition.y = 0;float lenght = sqrt(width*width+heigth*heigth);directionY = 1;speed = 500;float during = lenght / speed;FiniteTimeAction* actionMoveTo = MoveTo::create(during,destinationPosition);CallFunc * funcall= CallFunc::create(this, callfunc_selector(CreateObstacleCopy::animationDone));FiniteTimeAction* actionRotateTo = RotateTo::create(0.2,launchAngle);FiniteTimeAction* task = Sequence::create(actionRotateTo, actionMoveTo,funcall, NULL);runAction(task);}}
0 0
- 实现子弹, 可以指定发射位置, 发发射角度, 有方向, 可以反弹
- html5学习--实现坦克可以连续发射子弹
- 跳跃的实现(发射子弹)
- 飞机大战开发05按角度发射的子弹和拖尾子弹的实现
- 09-html5游戏坦克大战第五战(自己的坦克可以发射单颗子弹)
- 10-html5游戏坦克大战第六战(自己的坦克可以连续发射子弹)
- 【四圣龙神录的编程教室】第17章、让自机可以发射子弹吧
- cocos2d-x发射子弹
- unity之子弹发射
- 2.8.2 发射子弹
- UE4蓝图发射子弹
- Unity发射子弹
- 发射子弹 发射射线判断方法
- Unity3D实现再鼠标单击的方向发射子弹
- cocos2d-x如何发射子弹
- Cocos2d-x--发射多发子弹
- (6) cocos2d-x发射子弹
- unity学习之子弹发射
- [Python]什么时候使用自定义类
- 在DLL中产生对话框的方法一(Win32 DLL)
- wpf 中使用Log4net
- Java 文件 解压缩 示例
- hypertable架构与使用实践
- 实现子弹, 可以指定发射位置, 发发射角度, 有方向, 可以反弹
- CentOS 6 安装EPEL/RPMFusion/更新源
- 模拟器搭建之二:如何搭建 MTK 6589模拟器
- Tomcat - web.xml配置文件
- 深入jsp运行机制
- php命名空间namespace使用笔记
- Adobe Flash Builder 4.7下载地址及破解补丁(32位&64位)
- windows编程之WM_CLOSE,WM_DESTROY,WM_QUIT
- Dialogs in DLL