本文整理汇总了C++中Laser::Update方法的典型用法代码示例。如果您正苦于以下问题:C++ Laser::Update方法的具体用法?C++ Laser::Update怎么用?C++ Laser::Update使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Laser
的用法示例。
在下文中一共展示了Laser::Update方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Update
void Player::Update(const float time_step)
{
if(Keyboard::IsKeyDown((KeyCode)left_key))
{
//rotate left
rotation += (rot_accel * time_step);
}
if(Keyboard::IsKeyDown((KeyCode)right_key))
{
//rotate right
rotation -= (rot_accel * time_step);
}
if(Keyboard::IsKeyDown((KeyCode)thrust_key))
{
//increase thrust
thrust += thrust_accel * time_step;
}
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;
//.........这里部分代码省略.........