游戏中的伤害值敌人伤害值,伤害数字飘飘悠悠最后消失
,我们将起归纳到Effect中,犹如粒子一样,有时间生命,资源如下:
![](http://www.cppblog.com/images/cppblog_com/wc250en007/number2.jpg)
我们根据不同的伤害选择不同的颜色,英雄对敌人伤害白色,怪物对英雄伤害红色….我们主要确定在屏幕的鼠标位置确定好我们的伤害数值的UV坐标,如我们队怪物伤害为59,分别将数字5和数字9作为粒子特效,出现消失
我们功过函数DrawNumberCharBitmap来确定每位数字的UV坐标
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
struct SChar
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
char c; // 字母
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
int x, y; // 位置
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
int bottom; // 底部参考坐标
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
int nWidth, nHeight; // 大小
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
DWORD dwBornTime; // 出生时间
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
DWORD dwLife; // 生命
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
float alpha;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
};
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
enum
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
eMiss,
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
eNumberBlue,
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
eNumberRed,
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
eNumberGreen,
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
eNumberYellow,
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
}
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
struct SParticle
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
int nType; //特效类型
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
int nStartX, nStartY;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
int x, y;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
int nWidth, nHeight;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
int nSrcWidth, nSrcHeight;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
DWORD dwColor;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
DWORD dwStartTime;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
DWORD dwLastUpdateTime;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
DWORD dwLife; //粒子存在时间
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
int nNumber; //将数值记录下来,eg:59伤害
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
int nNumChar; //伤害数字长度
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
SChar chars[eMaxChar]; //每位值都作为一个单独的粒子
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
};
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
for( int nChar = 0; nChar < pParticle->nNumChar; nChar++ ) //数字长度
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
SChar* pChar = &pParticle->chars[nChar];
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cppblog.com/Images/dot.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
DrawNumberCharBitmap( int x, int y, int w, int h, int start_line, DWORD color, int nNumber, Simple2DVertex vertex[] );
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
}
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
//确定UV坐标
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
void DrawNumberCharBitmap( int x, int y, int w, int h, int start_line, DWORD color, int nNumber, Simple2DVertex vertex[] )
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
static POINT index[10] =
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
0, 0,
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
0, 1,
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
0, 2,
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
0, 3,
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
0, 4,
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
0, 5,
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
0, 6,
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
0, 7,
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
1, 0,
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
1, 1,
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
};
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
RECT rect;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
rect.left = x;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
rect.top = y;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
rect.right = x+w;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
rect.bottom = y+h;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
//
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
float sdv = 1.0f / 4 * start_line;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
float du = 1.0f/8;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
float dv = 1.0f/8;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
int row = index[nNumber].x;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
int col = index[nNumber].y;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
float z = 0.0f;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
vertex[0].p = D3DXVECTOR4( rect.left, rect.bottom, z, 1 );
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
vertex[0].color = color;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
vertex[0].u = du*col;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
vertex[0].v = sdv + dv*row+dv;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
vertex[1].p = D3DXVECTOR4( rect.left, rect.top, z, 1 );
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
vertex[1].color = color;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
vertex[1].u = du*col;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
vertex[1].v = sdv + dv*row;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
vertex[2].p = D3DXVECTOR4( rect.right, rect.bottom, z, 1 );
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
vertex[2].color = color;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
vertex[2].u = du*col+du;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
vertex[2].v = sdv + dv*row+dv;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
vertex[3].p = D3DXVECTOR4( rect.right, rect.top, z, 1 );
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
vertex[3].color = color;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
vertex[3].u = du*col+du;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
vertex[3].v = sdv + dv*row;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
}
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
posted on 2010-07-20 15:01
风轻云淡 阅读(954)
评论(0) 编辑 收藏 引用 所属分类:
GameDevelop