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


C++ Collision::GetSegment方法代码示例

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


在下文中一共展示了Collision::GetSegment方法的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;
}
开发者ID:AntonLanghoff,项目名称:whitecatlib,代码行数:101,代码来源:main.cpp


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