2D爆炸特效

Explode.h

 1 #ifndef _EXPLODE_H_
 2 #define _EXPLODE_H_
 3 
 4 #include "Game.h"
 5 #include <vector>
 6 
 7 extern LPDIRECT3DTEXTURE9 g_texture;
 8 
 9 //爆炸类
10 class CExplode
11 {
12 public:
13     //爆炸帧结构体
14     typedef struct tagExplodeFrame
15     {
16         tagExplodeFrame(int nTotalFrame,int nScreenWidth,int nScreenHeight)
17         {
18             nCurFrame = 0;
19             nStartTime = 0;
20             nDestX = rand()%nScreenWidth;
21             nDestY = rand()%nScreenHeight;
22         }
23         int                    nCurFrame;        //当前播放帧
24         int                    nDestX;            //屏幕坐标X
25         int                    nDestY;            //屏幕坐标Y
26         int                    nTotalFrame;    //总帧数
27         int                    nCols;            //纹理序列帧列数
28         int                    nFrameW;        //每一帧的宽度
29         int                    nFrameH;        //每一帧的高度
30         int                    nStartTime;        //开始播放的时间
31 
32         void SetFrameWidth( int nWidth)
33         {
34             nFrameW = nWidth;
35         }
36         
37         void SetFrameHeight( int nHeight)
38         {
39             nFrameH = nHeight;
40         }
41         
42         void SetTextureCols( int col)
43         {
44             nCols = col;
45         }
46         void Show()
47         {
48             //这里就是播放序列帧
49             CGame::getSingleton().Animate(nCurFrame,0,17,nStartTime,80);
50             CGame::getSingleton().DrawFrame(g_texture,nDestX,nDestY,nCurFrame,nFrameW,nFrameH,nCols);
51             //nDestY++;    //每一帧爆炸位置下移
52         }
53 
54     }ExplodeFrame;
55 
56 public:
57     CExplode()
58     {
59         n_StartTime = GetTickCount();
60         srand((UINT)timeGetTime());
61     }
62     ~CExplode()
63     {
64 
65     }
66     
67     VOID ShowExplode();
68 
69 private:
70     std::vector<ExplodeFrame>        m_ExplodeFrame;
71     DWORD                            n_StartTime;        //爆炸开始时间
72 };
73 
74 
75 #endif

Explode.cpp

 1 #include "Explode.h"
 2 
 3 VOID CExplode::ShowExplode()
 4 {
 5     //遍历爆炸帧表
 6     if ( !m_ExplodeFrame.empty())
 7     {
 8         std::vector<ExplodeFrame>::iterator ExplodeIter = m_ExplodeFrame.begin();
 9         while(ExplodeIter != m_ExplodeFrame.end())
10         {
11             ExplodeFrame& frame = (*ExplodeIter);
12             frame.Show();
13             if (frame.nCurFrame == frame.nTotalFrame)    //播完一帧就从表里移除
14             {
15                 ExplodeIter = m_ExplodeFrame.erase(ExplodeIter);
16             }
17             else
18             {
19                 ++ExplodeIter;
20             }
21         }
22     }
23 
24     //每隔150ms 加入5个爆炸点
25     if (GetTickCount() - n_StartTime > 150)
26     {
27         for( int i = 0; i< 5; ++i)
28         {
29             ExplodeFrame frame(17,800,600);
30             frame.SetFrameHeight(24);
31             frame.SetFrameWidth(32);
32             frame.SetTextureCols(17);
33 
34             m_ExplodeFrame.push_back(frame);
35             n_StartTime = GetTickCount();
36         }
37 
38         n_StartTime = GetTickCount();
39     }
40 }

posted on 2012-12-06 00:39 让知识沉淀 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/3dhunter/archive/2012/12/06/2804248.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值