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


C++ Laser::GetPosition方法代码示例

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


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

示例1: CheckLaserAsteroidCollisions

void Player::CheckLaserAsteroidCollisions(std::list<Asteroid*>* asteroids)
{
    std::list<Asteroid*>::iterator a_iter = asteroids->begin();
    std::list<Asteroid*> a_tbd;
    std::list<Laser*> l_tbd;

    while(a_iter != asteroids->end())
    {
        Asteroid *ast = a_iter._Ptr->_Myval;
        std::list<Laser*>::iterator l_iter = lasers.begin();

        while(l_iter != lasers.end())
        {
            Laser *las = l_iter._Ptr->_Myval;

            if(ast->GetBSphere().Contains(las->GetPosition()))
            {
                //The laser is inside the asteroid bsphere
                a_tbd.push_back(ast);
                l_tbd.push_back(las);
                AddScore(ast->GetBSphere().GetRadius());
            }
            l_iter++;
        }
        a_iter++;
    }

    //Do the deletions
    std::list<Laser*>::iterator l_iter = l_tbd.begin();
    while(l_iter != l_tbd.end())
    {
        lasers.remove(l_iter._Ptr->_Myval);
        l_iter++;
    }
    a_iter = a_tbd.begin();
    while(a_iter != a_tbd.end())
    {
        asteroids->remove(a_iter._Ptr->_Myval);
        a_iter++;
    }
}
开发者ID:russdaygh,项目名称:SpaceshipsInSpace,代码行数:41,代码来源:Player.cpp

示例2: Update


//.........这里部分代码省略.........
    else
    {
        thrust = 0;
    }

    if(thrust < 0)
    {
        thrust = 0;
    }
    else if(thrust > MAX_THRUST)
    {
        thrust = MAX_THRUST;
    }

    if(Keyboard::IsKeyDown((KeyCode)fire_key))
    {
        //fire a laser
        curr_laser_time -= time_step;
        if(curr_laser_time < 0)
        {
            FireLaser();
            curr_laser_time = LASER_RECHARGE_TIME;
        }
    }

    using RustyLib::Matrix44;

    Matrix44 *rot_mat = Matrix44::CreateRotationZ(rotation);

    acceleration = (*rot_mat * Vector3::INV_Y_AXIS());

    acceleration *= thrust;

    velocity += acceleration;

    float curr_vel = velocity.Magnitude();

    if(curr_vel > MAX_VELOCITY)
    {
        curr_vel = MAX_VELOCITY;
    }

    velocity.Normalise();

    velocity *= curr_vel;

    GameObject::Update(time_step);

    //Do some collision detection
    b_sphere.SetPosition(position);

    //First check whether player is on screen still
    if(! play_region.Contains(b_sphere) )
    {
        //Player needs moving
        Vector3 min = play_region.GetMin();
        Vector3 max = play_region.GetMax();

        if(position.x < min.x - b_sphere.GetRadius())
        {
            position.x = max.x + (b_sphere.GetRadius()-1.0f);
        }
        if(position.x > max.x + b_sphere.GetRadius())
        {
            position.x = min.x - (b_sphere.GetRadius()+1.0f);
        }
        if(position.y < min.y - b_sphere.GetRadius())
        {
            position.y = max.y + (b_sphere.GetRadius()-1.0f);
        }
        if(position.y > max.y + b_sphere.GetRadius())
        {
            position.y = min.y - (b_sphere.GetRadius()+1.0f);
        }
        b_sphere.SetPosition(position);
    }

    std::list<Laser*>::iterator iter = lasers.begin();
    std::list<Laser*> tbd;//lasers to be deleted
    int ct = 0;
    while(iter != lasers.end())
    {
        Laser* l = iter._Ptr->_Myval;
        l->Update(time_step);
        if(!play_region.Contains(l->GetPosition()))
        {
            //laser has left screen
            tbd.push_back(l);
        }
        iter++;
        ct++;
    }
    iter = tbd.begin();
    while(iter != tbd.end())
    {
        lasers.remove(iter._Ptr->_Myval);
        iter++;
    }
    tbd.clear();
}
开发者ID:russdaygh,项目名称:SpaceshipsInSpace,代码行数:101,代码来源:Player.cpp


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