新手上路

- UID
- 151552
- 帖子
- 3
- 威望
- 0
- 久币
- 0
- 贡献
- 0
- 阅读权限
- 10
- 在线时间
- 0 小时
- 注册时间
- 2019-5-18
|
游戏《水果忍者》完整游戏源码,代码下载下来打开工程直接可以编译通过运行
可以生成安卓apk包,winows,ios环境下跨平台运行
100%完整代码,源码编译 无bug运行
刀光算法- void CFControlLayer::drawLine(CCPoint startPoint,CCPoint endPoint)
- {
- int dx, dy, p, c1, c2, x, y, xinc, yinc, i;
- dx = startPoint.x - endPoint.x;
- dy = startPoint.y - endPoint.y;
- xinc = getSingle(dx);
- yinc = getSingle(dy);
- dx = dx>0?dx:-dx;
- dy = dy>0?dy:-dy;
- x = startPoint.x;
- y = startPoint.y;
- ccPointSize(1);
- //设置后面要进行绘制时所用的色彩
- ccDrawColor4B(0,0,255,128);
- if (dx >= dy)
- {
- p = (dy << 1) - dx;
- c1 = dy << 1;
- c2 = (dy - dx) << 1;
- for (i = 0; i <= dx; i++)
- {
- ccDrawPoint(ccp(x,y));
- if (p < 0)
- {
- p += c1;
- }
- else
- {
- p += c2;
- y += yinc;
- ccDrawPoint(ccp(x,y));
- }
- x += xinc;
- }
- }
- else
- {
- p = (dx << 1) - dy;
- c1 = dx << 1;
- c2 = (dx - dy) << 1;
- for (i = 0; i <= dy; i++)
- {
- ccDrawPoint(ccp(x,y));
- if (p < 0)
- {
- p += c1;
- }
- else
- {
- p += c2;
- x += xinc;
- ccDrawPoint(ccp(x,y));
- }
- y += yinc;
- }
- }
- }
- CCPoint CFControlLayer::getPoint(CCPoint startPoint,CCPoint endPoint,int dx,int dy,int num)
- {
- int p, c1, c2, x, y, xinc, yinc, i;
- xinc = getSingle(dx);
- yinc = getSingle(dy);
- dx = dx>0?dx:-dx;
- dy = dy>0?dy:-dy;
- x = endPoint.x;
- y = endPoint.y;
- if (dx >= dy)
- {
- p = (dy << 1) - dx;
- c1 = dy << 1;
- c2 = (dy - dx) << 1;
- for (i = 0; i <= num; i++)
- {
- if (p < 0)
- {
- p += c1;
- }
- else
- {
- p += c2;
- y += yinc;
- }
- x += xinc;
- }
- }
- else
- {
- p = (dx << 1) - dy;
- c1 = dx << 1;
- c2 = (dx - dy) << 1;
- for (i = 0; i <= num; i++)
- {
- if (p < 0)
- {
- p += c1;
- }
- else
- {
- p += c2;
- x += xinc;
- }
- y += yinc;
- }
- }
- CCPoint point(x,y);
- return point;
- }
- void CFControlLayer::drawHead(/*CCPoint startPoint,CCPoint endPoint*/)
- {
- int dx,dy;
- CCPoint startPoint , endPoint ;
- if (m_pointArray->count()<2)
- {
- return;
- }
- endPoint = m_pointArray->getControlPointAtIndex(m_pointArray->count()-1); //最后一个点
- startPoint= m_pointArray->getControlPointAtIndex(m_pointArray->count()-2); //倒数第二个点
- dx = endPoint.x-startPoint.x ;
- dy = endPoint.y -startPoint.y ;
- CCPoint dingdian,shangb,xiab;
- dingdian = getPoint(startPoint,endPoint,dx,dy,20);
- shangb = getPoint(startPoint,endPoint,-dy,dx,5);
- xiab = getPoint(startPoint,endPoint,dy,-dx,5);
- CCPoint vertices5[] = {shangb,dingdian,xiab};
- ccDrawSolidPoly( vertices5, 3, ccc4f(255,255,255,255) );
- glLineWidth(2);
- ccDrawColor4B(17, 164 ,246,255);
- ccDrawPoly(vertices5,3,false);
- glLineWidth(1);
- ccDrawColor4B(255,255,255,255);
- }
- void CFControlLayer::drawReal(/*CCPoint startPoint,CCPoint endPoint*/)
- {
- int dx,dy;
- CCPoint startPoint , endPoint ;
- int width = 6-m_pointArray->count();
- if (m_pointArray->count()<2)
- {
- return;
- }
- endPoint = m_pointArray->getControlPointAtIndex(1);
- startPoint= m_pointArray->getControlPointAtIndex(0);
- // ccDrawLine(startPoint,endPoint);
- dx = startPoint.x - endPoint.x;
- dy = startPoint.y- endPoint.y ;
- CCPoint dingdian,shangb,xiab;
- dingdian = getPoint(endPoint,startPoint,dx,dy,20);
- if(m_pointArray->count()==2)
- {
- shangb = getPoint(endPoint,startPoint,-dy,dx,2);
- xiab = getPoint(endPoint,startPoint,dy,-dx,2);
- }
- else
- {
- shangb = getPoint(endPoint,startPoint,-dy,dx,width);
- xiab = getPoint(endPoint,startPoint,dy,-dx,width);
- }
- CCPoint vertices5[] = {dingdian,shangb,xiab};
- ccDrawSolidPoly( vertices5, 3, ccc4f(255,255,255,255) );
- ccDrawPoly(vertices5,3,true);
- }
- void CFControlLayer::drawCentre(/*CCPoint startPoint,CCPoint endPoint*/)
- {
- int dx,dy;
- CCPoint startPoint , endPoint ;
- if (m_pointArray->count()<2)
- {
- return;
- }
- int count = 6;
- int width = 6-m_pointArray->count();
- for(int i = 0; i<m_pointArray->count()-1;i++)
- {
- endPoint = m_pointArray->getControlPointAtIndex(i+1);
- startPoint= m_pointArray->getControlPointAtIndex(i);
- dx = endPoint.x-startPoint.x ;
- dy = endPoint.y -startPoint.y ;
- CCPoint endPointS,endPointX,startPointS,startPointX;
- if (m_pointArray->count()==2)
- {//这样写有点瑕疵,以后在写
- startPointS = getPoint(endPoint,startPoint,-dy,dx,2);
- startPointX = getPoint(endPoint,startPoint,dy,-dx,2);
- endPointS = getPoint(startPoint,endPoint,-dy,dx,5);
- endPointX = getPoint(startPoint,endPoint,dy,-dx,5);
- }
- else
- {
- startPointS = getPoint(endPoint,startPoint,-dy,dx,width);
- startPointX = getPoint(endPoint,startPoint,dy,-dx,width);
- width++;
- endPointS = getPoint(startPoint,endPoint,-dy,dx,width);
- endPointX = getPoint(startPoint,endPoint,dy,-dx,width);
- }
- CCPoint vertices1[] = {endPointS,endPointX,startPointS};
- CCPoint vertices2[] = {startPointS,startPointX,endPointX};
- ccDrawSolidPoly( vertices1,3, ccc4f(255,255,255,20) );
- ccDrawSolidPoly( vertices2,3, ccc4f(255,255,255,20) );
- if (centrePoint.x==startPoint.x&& centrePoint.y == startPoint.y)
- {
- CCPoint vertices3[] = {centrePoint,lastUp,startPointS};
- CCPoint vertices4[] = {centrePoint,startPointX,laseDown};
- ccDrawSolidPoly( vertices3,3, ccc4f(255,255,255,255) );
- ccDrawSolidPoly( vertices4,3, ccc4f(255,255,255,255) );
- }
- centrePoint = endPoint;
- lastUp = endPointS;
- laseDown = endPointX;
- }
- }
- void CFControlLayer::drawDaoguang()
- {
- if (m_pointArray->count()<2)
- {
- return;
- }
- drawReal();
- drawCentre();
- drawHead();
- }
复制代码 |
|