游戏编程--雪花效果

来源:互联网 发布:数控编程视频教学 编辑:程序博客网 时间:2024/04/29 04:54
void CMainPage::processParticle() {    VFLOAT rad = 0;    srand( (unsigned)time( NULL ) );          //初始化随机数    for(VINT32 i = 0; i < 1; ++i) { //1 is the snow num        VFLOAT k = rand() % PI; //rand a radius that the snow move, what follows next the function "cos"        VINT32 iSpeed =  rand()%2 + 1;        VFLOAT fX = m_pParticle[i]->getX().toFloat() - cos(k);        m_pParticle[i]->setX(fX);        VFLOAT fY = m_pParticle[i]->getY().toFloat() + iSpeed; //iSpeed is the rand speed        m_pParticle[i]->setY(fY);        if (fY >= 480) {            m_pParticle[i]->setY(-5);        }        if ((fX >= 242) /*|| (fY <= 0)*/) {            fX = -10 + rand()%450;            m_pParticle[i]->setX(fX);            m_pParticle[i]->setY(-5);        }    }}

0 0
原创粉丝点击