本文整理汇总了C++中Collision::IsCollision方法的典型用法代码示例。如果您正苦于以下问题:C++ Collision::IsCollision方法的具体用法?C++ Collision::IsCollision怎么用?C++ Collision::IsCollision使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Collision
的用法示例。
在下文中一共展示了Collision::IsCollision方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
// Get the delta time //
float deltaTime = FpsCounter::GetDeltaTime();
//printf( "Currentfps - %f\n", FpsCounter::GetFps());
// Move the bitmap with the arrow keys //
Vec2D force;
if( key[KEY_LEFT] ) force.x -= 1;
if( key[KEY_RIGHT] ) force.x += 1;
if( key[KEY_UP] ) force.y -= 1;
if( key[KEY_DOWN] ) force.y += 1;
if( force.x && force.y )
force *= .7071;
force *= THRUST;
Vec2D accel = force / player.mass;
accel.y += GRAVITY;
//printf( "Force is %f,%f\n", force.x, force.y );
//printf( "Accel is %f,%f\n", accel.x, accel.y );
//printf( "DT is %f\n", deltaTime );
//printf( "PreVelocity is %+07.3f,%+07.3f\n", player.velocity.x, player.velocity.y );
player.velocity += accel*deltaTime;
//printf( "Velocity is %+07.3f,%+07.3f\n", player.velocity.x, player.velocity.y );
player.UpdatePosition( deltaTime );
//accel.x = FRand( -.1, .1 );
//accel.y = FRand( -.1, .1 );
accel.x = 0.0;
accel.y = GRAVITY;
enemy.velocity += accel * deltaTime;
enemy.UpdatePosition( deltaTime );
collision = player.GetCollision( wall, player.GetPlacement(), wall.GetPlacement());
if( collision.IsCollision())
{
Vec2D surfaceNormal = collision.GetSegment( OBJ_B ).GetNormal();
float speedAgainstSurface = -player.velocity * surfaceNormal;
player.velocity += 2 * speedAgainstSurface * surfaceNormal;
}
collision = enemy.GetCollision( wall, enemy.GetPlacement(), wall.GetPlacement());
if( collision.IsCollision())
{
Vec2D surfaceNormal = collision.GetSegment( OBJ_B ).GetNormal();
float speedAgainstSurface = -enemy.velocity * surfaceNormal;
enemy.velocity += 2 * speedAgainstSurface * surfaceNormal;
}
collision = player.GetCollision( enemy, player.GetPlacement(), enemy.GetPlacement());
if( collision.IsCollision())
{
Vec2D pp = player.velocity * player.mass;
Vec2D ep = enemy.velocity * enemy.mass;
Vec2D vcm = (pp + ep) / (player.mass + enemy.mass );
Vec2D pvf = -( player.velocity - vcm ) + vcm;
Vec2D evf = -( enemy.velocity - vcm ) + vcm;
player.velocity = pvf;
enemy.velocity = evf;
}
if( goal.Contains( player ))
{
allegro_message( "You went into the firey goal of death! You lose!" );
bExit = true;
}
if( goal.Contains( enemy ))
{
allegro_message( "You got the enemy into the firey goal of death! Congrats, you win!" );
bExit = true;
}
// RENDERING //
// Clear the screen to white //
Canvas::Fill( Rgba::BLACK );
// Draw the bitmap to the screen with the top-left coordinates //
player.Draw();
enemy.Draw();
Transforms::SetPosition( 0,0 );
goal.DrawOutline( Rgba::RED );
// Refresh the screen contents to show this frame //
Canvas::Refresh();
rest(0);
}
return 0;
}