当前位置: 首页>>代码示例>>C++>>正文


C++ CBullet::IsAlive方法代码示例

本文整理汇总了C++中CBullet::IsAlive方法的典型用法代码示例。如果您正苦于以下问题:C++ CBullet::IsAlive方法的具体用法?C++ CBullet::IsAlive怎么用?C++ CBullet::IsAlive使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CBullet的用法示例。


在下文中一共展示了CBullet::IsAlive方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: OnCollision

void CSoldier::OnCollision(float deltaTime, std::vector<CGameObject*>* listObjectCollision)
{
    float normalX = 0;
    float normalY = 0;
    float moveX = 0.0f;
    float moveY = 0.0f;
    float timeCollision;

    for (std::vector<CBullet*>::iterator it = CPoolingObject::GetInstance()->m_listBulletOfObject.begin(); it != CPoolingObject::GetInstance()->m_listBulletOfObject.end();)
    {
        CBullet* obj = *it;
        timeCollision = CCollision::GetInstance()->Collision(obj, this, normalX, normalY, moveX, moveY, deltaTime);
        if((timeCollision > 0.0f && timeCollision < 1.0f) || timeCollision == 2.0f)
        {
            if(obj->IsAlive() && obj->GetLayer() == LAYER::PLAYER)
            {
                // Gan trang thai die cho doi tuong
                this->m_stateCurrent = SOLDIER_STATE::S_IS_DIE;
                // Xoa vien dan ra khoi d.s
                it = CPoolingObject::GetInstance()->m_listBulletOfObject.erase(it);
                //Load sound die
                ManageAudio::GetInstance()->playSound(TypeAudio::ENEMY_DEAD_SFX);
                // Tang diem cua contra len
                CContra::GetInstance()->IncreateScore(500);
            }
            else
                ++it;
        }
        else
        {
            ++it;
        }
    }

    if (this->m_stateCurrent != SOLDIER_STATE::S_IS_DIE)
    {
            //Kiem tra va cham voi ground
        bool checkColWithGround = false;
        // xet va cham vs ground
        for (std::vector<CGameObject*>::iterator it = listObjectCollision->begin(); it != listObjectCollision->end(); it++)
        {
            CGameObject* obj = *it;
            //Lay thoi gian va cham
            //Neu doi tuong la ground va dang va cham
            if(((obj->GetIDType() == 15 && obj->GetID() == 1) || (obj->GetIDType() == 15 && obj->GetID() == 8) || (obj->GetIDType() == 16 && obj->GetID() == 1)) && !checkColWithGround)
            {
                timeCollision = CCollision::GetInstance()->Collision(this, obj, normalX, normalY, moveX, moveY, deltaTime);
                if((timeCollision > 0.0f && timeCollision < 1.0f) || timeCollision == 2.0f)
                {
                    if(normalY > 0)
                    {

                        checkColWithGround = true;
                        if (this->m_stateCurrent == SOLDIER_STATE::S_IS_JUMP)
                        {
                            if (this->m_vy < -200.0f)
                            {
                                this->m_stateCurrent = SOLDIER_STATE::S_IS_JOGGING;
                                if( timeCollision == 2.0f)
                                {
                                    //this->m_isJumping = false;
                                    this->m_pos.y += moveY;
                                    this->m_vy = 0;
                                    this->m_a = 0;
                                }
                            }
                        }
                        else
                        {
                            this->m_stateCurrent = SOLDIER_STATE::S_IS_JOGGING;
                            if( timeCollision == 2.0f)
                            {
                                //this->m_isJumping = false;
                                this->m_pos.y += moveY;
                                this->m_vy = 0;
                                this->m_a = 0;
                            }
                        }
                    }
                }
            }
        }

        if(!checkColWithGround)
        {
            this->m_a = -700.0f;
            
            if (this->m_jump)
            {
                if(this->m_vy == 0.0f)
                    this->m_vy = this->m_vyDefault;
                this->m_stateCurrent = SOLDIER_STATE::S_IS_JUMP;
            }
            else
            {
                // Soldier quay dau nguoc lai.
                this->m_left = !this->m_left;
                this->m_countRepeat ++;
                if (m_countRepeat > 2)
                {
//.........这里部分代码省略.........
开发者ID:doanhtdpl,项目名称:game-con-tra,代码行数:101,代码来源:CSoldier.cpp


注:本文中的CBullet::IsAlive方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。