本文整理汇总了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++;
}
}
示例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();
}