资源简介

C++编写的类似水果忍者的切水果的效果,很简单很好学习

资源截图

代码片段和文件信息

#include “Blade.h“
#include 
#include 
//#include 
#include  
//#include 

Blade::Blade()
{
winWidth = 0;
winHeight = 0;
mousePosX = 0;
mousePosY = 0;

vertexArrStartPos = 0;
//vertexArrEndPos = 0;

pointCount = 0;
drawFlag = 0;
mouseDownFlag = 0;

sampleInterval = 0.015f;
fadeInterval = 0.02f;

bladeThreshold = 0.032f;

init();
}

Blade::~Blade()
{}

void Blade::calcSideVertex(GLfloat *startVertex GLfloat *endVertex GLfloat returnSideVertex[][2] GLfloat sideWidth GLfloat end2StartRatio)
{
GLfloat tmpAngle = 0.0;
GLfloat tmpVertex[2] = {0.0f 0.0f};
GLfloat tmpSideVertex[2][2] = {{0.0f 0.0f} {0.0f 0.0f}};
GLfloat tmpResult = 0.0;

tmpAngle = atan((endVertex[1] - startVertex[1])/(endVertex[0] - startVertex[0]));

tmpVertex[0] = endVertex[0]-(endVertex[0]-startVertex[0])*end2StartRatio;
tmpVertex[1] = endVertex[1]-(endVertex[1]-startVertex[1])*end2StartRatio;

if (endVertex[0] > startVertex[0]) {
tmpSideVertex[0][0] = tmpVertex[0] + (sideWidth * sin(tmpAngle));
tmpSideVertex[0][1] = tmpVertex[1] - (sideWidth * cos(tmpAngle));
tmpSideVertex[1][0] = tmpVertex[0] - (sideWidth * sin(tmpAngle));
tmpSideVertex[1][1] = tmpVertex[1] + (sideWidth * cos(tmpAngle));
} else {
tmpSideVertex[0][0] = tmpVertex[0] - (sideWidth * sin(tmpAngle));
tmpSideVertex[0][1] = tmpVertex[1] + (sideWidth * cos(tmpAngle));
tmpSideVertex[1][0] = tmpVertex[0] + (sideWidth * sin(tmpAngle));
tmpSideVertex[1][1] = tmpVertex[1] - (sideWidth * cos(tmpAngle));
}

//判断点在向量的左边还是右边
tmpResult = (startVertex[0] - tmpSideVertex[0][0])*(endVertex[1] - tmpSideVertex[0][1]) - (startVertex[1] - tmpSideVertex[0][1])*(endVertex[0] - tmpSideVertex[0][0]);
if (tmpResult > 0.0f) {
returnSideVertex[0][0] = tmpSideVertex[1][0];
returnSideVertex[0][1] = tmpSideVertex[1][1];
returnSideVertex[1][0] = tmpSideVertex[0][0];
returnSideVertex[1][1] = tmpSideVertex[0][1];
} else {
returnSideVertex[0][0] = tmpSideVertex[0][0];
returnSideVertex[0][1] = tmpSideVertex[0][1];
returnSideVertex[1][0] = tmpSideVertex[1][0];
returnSideVertex[1][1] = tmpSideVertex[1][1];
}
}

void Blade::init(void)
{
int i = 0;

for (i = 0; i < vertexArrTail; i++) {
bodyVertex[i][0] = 0.0f;
bodyVertex[i][1] = 0.0f;

uniformSideVertex[i][0][0] = 0.0f;
uniformSideVertex[i][0][1] = 0.0f;
uniformSideVertex[i][1][0] = 0.0f;
uniformSideVertex[i][1][1] = 0.0f;

outerSideVertex[i][0][0] = 0.0f;
outerSideVertex[i][0][1] = 0.0f;
outerSideVertex[i][1][0] = 0.0f;
outerSideVertex[i][1][1] = 0.0f;

innerSideVertex[i][0][0] = 0.0f;
innerSideVertex[i][0][1] = 0.0f;
innerSideVertex[i][1][0] = 0.0f;
innerSideVertex[i][1][1] = 0.0f;
}
}

void Blade::vertexSampling()
{
int tmpIndex1 = 0 tmpIndex2 = 0;
GLfloat uniformX = 0.0f uniformY = 0.0f;
GLfloat realX = 0.0f realY = 0.0f;
drawFlag = 0;
pointCount++;

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      48640  2012-05-07 21:56  水果刀\Debug\水果刀.exe

     文件     364004  2012-05-07 21:56  水果刀\Debug\水果刀.ilk

     文件     502784  2012-05-07 21:56  水果刀\Debug\水果刀.pdb

     文件       9471  2012-04-13 17:46  水果刀\水果刀\Blade.cpp

     文件       1469  2012-04-12 09:29  水果刀\水果刀\Blade.h

     文件      29381  2012-05-07 21:56  水果刀\水果刀\Debug\Blade.obj

     文件       9142  2012-05-07 21:56  水果刀\水果刀\Debug\BuildLog.htm

     文件         67  2012-05-07 21:56  水果刀\水果刀\Debug\mt.dep

     文件      30566  2012-05-07 21:56  水果刀\水果刀\Debug\Ninjia.obj

     文件     347136  2012-05-07 21:56  水果刀\水果刀\Debug\vc90.idb

     文件     110592  2012-05-07 21:56  水果刀\水果刀\Debug\vc90.pdb

     文件        663  2012-05-07 21:56  水果刀\水果刀\Debug\水果刀.exe.embed.manifest

     文件        728  2012-05-07 21:56  水果刀\水果刀\Debug\水果刀.exe.embed.manifest.res

     文件        621  2012-05-07 21:56  水果刀\水果刀\Debug\水果刀.exe.intermediate.manifest

     文件       1693  2012-04-13 17:44  水果刀\水果刀\Ninjia.cpp

     文件       4036  2012-05-07 21:56  水果刀\水果刀\水果刀.vcproj

     文件       1413  2012-05-07 22:17  水果刀\水果刀\水果刀.vcproj.DIST-MZM.yeyan.user

     文件    2722816  2012-05-07 22:17  水果刀\水果刀.ncb

     文件        893  2012-05-07 21:55  水果刀\水果刀.sln

    ..A..H.      9216  2012-05-07 22:17  水果刀\水果刀.suo

     目录          0  2012-05-07 21:56  水果刀\水果刀\Debug

     目录          0  2012-05-07 21:56  水果刀\Debug

     目录          0  2012-05-07 21:56  水果刀\水果刀

     目录          0  2012-05-07 21:56  水果刀

----------- ---------  ---------- -----  ----

              4195331                    24


评论

共有 条评论