Cocos2d-x--发射多发子弹(2)

来源:未知 责任编辑:责任编辑 发表时间:2013-12-06 08:43 点击:
< from.x) && (to.y > from.y); bool isInQuadrant3 = (to.x < from.x) && (to.y < from.y); bool isInQuadrant4 = (to.x > from.x) && (to.y < from.y); bool isOnXR = (to.y == from.y) && (to.x > from.x); bool isOnXL = (to.y == from.y) && (to.x < from.x); bool isOnYT = (to.x == from.x) && (to.y > from.y); bool isOnYD = (to.x == from.x) && (to.y < from.y); bool isZero = (to.x == from.x) && (to.y == from.y); //起始点和触摸点形成的直线的斜率 float mMidLineSlope = (from.y - to.y) / (from.x - to.x); //弧度值 float mMidLineAngleR = atan(mMidLineSlope); //角度值 float mMidLineAngleD = R2D(mMidLineAngleR); //如果在二,三象限,mMidLineAngleD会小于0 if (isInQuadrant2 || isInQuadrant3) { //转换为正数,方便计算 mMidLineAngleD = 180 + mMidLineAngleD; } else if (isOnYT) { mMidLineAngleD = 90; } else if (isOnXR) { mMidLineAngleD = 0; } else if (isOnXL) { mMidLineAngleD = 180; } else if (isInQuadrant4) { //在第四象限mMidLineAngleD小于0,转换为正数 mMidLineAngleD = 360 + mMidLineAngleD; } else if (isOnYD) { mMidLineAngleD = 270; } else if(isZero) { return HelloWorld::Increment(0, 0); } //每颗子弹形成的直线的角度 float mLineAngleD = mMidLineAngleD + (mMidValue - index) * angle + shakeAngle; //每颗子弹形成的直线的弧度 float mLineAngleR = D2R(mLineAngleD); if (mLineAngleD > 360) { mLineAngleD = mLineAngleD - 360; } if (mLineAngleD < 0) { mLineAngleD = 360 + mLineAngleD; } //判断在直角坐标系中的位置 isInQuadrant1 = (mLineAngleD > 0) && (mLineAngleD < 90); isInQuadrant2 = (mLineAngleD > 90) && (mLineAngleD < 180); isInQuadrant3 = (mLineAngleD > 180) && (mLineAngleD < 270); isInQuadrant4 = (mLineAngleD > 270) && (mLineAngleD < 360); isOnXR = (mLineAngleD == 0); isOnXL = (mLineAngleD == 180); isOnYT = (mLineAngleD == 90); isOnYD = (mLineAngleD == 270); //x和y方向的增量 float mIncrementX = 0; float mIncrementY = 0; float mIncrement = speed; if (isInQuadrant1) { mIncrementX = abs(mIncrement * cos(mLineAngleR)); mIncrementY = abs(mIncrement * sin(mLineAngleR)); } else if (isInQuadrant2) { mIncrementX = mIncrement * cos(mLineAngleR); mIncrementY = abs(mIncrement * sin(mLineAngleR)); if(mIncrementX > 0) mIncrementX = -mIncrementX; } else if (isOnYT) { mIncrementY = speed; } else if (isOnXR) { mIncrementX = speed; } else if (isOnXL) { mIncrementX = -speed; } else if (isInQuadrant3) { mIncrementX = mIncrement * cos(mLineAngleR); mIncrementY = mIncrement * sin(mLineAngleR); if(mIncrementX > 0) mIncrementX = -mIncrementX; if(mIncrementY > 0) mIncrementY = -mIncrementY; } else if (isInQuadrant4) { mIncrementX = abs(mIncrement * cos(mLineAngleR)); mIncrementY = mIncrement * sin(mLineAngleR); if(mIncrementY > 0) mIncrementY = -mIncrementY; } else if (isOnYD) { mIncrementY = -speed; } HelloWorld::Increment mResult = HelloWorld::Increment(mIncrementX, mIncrementY); return mResult; } /**角度转弧度*/ double HelloWorld::D2R( double angle ) { return angle / 180.0 * PI; } /**弧度转角度*/ double HelloWorld::R2D( double radian ) { return radian / PI * 180; } void HelloWorld::registerWithTouchDispatcher() { CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, 0, true); } bool HelloWorld::ccTouchBegan( CCTouch *pTouch, CCEvent *pEvent ) { //触摸点 CCPoint mLocalTouch = pTouch->getLocation(); CCSize mScreenSize = CCDirector::sharedDirector()->getWinSize(); //子弹开始位置 Position mFrom = Position(mScreenSize.width / 2, 20); //子弹飞向的位置 Position mTo = Position(mLocalTouch.x, mLocalTouch.y); //一发5个子弹 int count = 3; //圆形子弹的半径 float mRadius = 10; //子弹速度 float mSpeed = 5; //子弹之间的夹角 float mAngle = 50; //子弹的抖动角度 float mShakeAngle = 0; for (int index = 0; index
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
用户名: 验证码:点击我更换图片
最新评论 更多>>

推荐热点

  • cocos2d-x学习笔记(19)--label 、label atlas
  • cocos2d-x学习笔记(23)--地图的使用3--CCTMXLayer
  • Cocos2d-x学习(一):HelloWorld
  • cocos2dx在xcode下开发,编译到android上(2)
  • cocos2d 设置屏幕默认方向
  • Cocos2d-x 2.0 之 Actions “三板斧” 之一
  • cocos2d-x学习笔记(22)--地图的使用2(TMX) --Z-Order、AnchorPoi
  • cocos2d-x学习笔记(18)--游戏打包(windows平台)
  • cocos2d-x学习笔记(16)--spritesheet(精灵表单)
网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
Copyright © 2008-2015 计算机技术学习交流网. 版权所有

豫ICP备11007008号-1