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


C++ Map::GetBoundingBoxFromSegment方法代码示例

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


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

示例1: CheckCollision

void NPC::CheckCollision(float fSeconds, Map& map, Character& character) {
	// Check collision
	SRect bb = GetBoundingBox();
	SRect newbb = bb + SVector2(mVelocity.x, 0.0f);
	SRect rightbb = map.GetBoundingBoxFromSegment(newbb.GetRightSegment(),
			*this, character);
	SRect leftbb = map.GetBoundingBoxFromSegment(newbb.GetLeftSegment(), *this,
			character);

	// Right collision
	if (mVelocity.x > 0.0f && rightbb.IsValid()) {
		mNPCData.mPosition.x += static_cast<int>(rightbb.min.x - bb.max.x)
				- 1.0f;
	}
	// Left collision
	else if (mVelocity.x < 0.0f && leftbb.IsValid()) {
		mNPCData.mPosition.x += static_cast<int>(leftbb.max.x - bb.min.x)
				+ 1.0f;
	} else {
		mNPCData.mPosition.x += static_cast<int>(mVelocity.x);
	}

	// Check collision
	newbb = bb + SVector2(0.0f, mVelocity.y);
	SRect bottombb = map.GetBoundingBoxFromSegment(newbb.GetBottomSegment(),
			*this, character);
	SRect topbb = map.GetBoundingBoxFromSegment(newbb.GetTopSegment(), *this,
			character);

	// Bottom collision
	if (mVelocity.y > 0.0f && bottombb.IsValid()) {
		mNPCData.mPosition.y += static_cast<int>(bottombb.min.y - bb.max.y)
				- 1.0f;
		mVelocity.y = 0.0f;
		Graphics_DebugRect(newbb + sOffset, 0xff00ff);
		Graphics_DebugRect(bottombb + sOffset, 0xff0000);
	}

	// Top collision
	else if (mVelocity.y < 0.0f && topbb.IsValid()) {
		mNPCData.mPosition.y += static_cast<int>(topbb.max.y - bb.min.y) + 1.0f;
		mVelocity.y = 0.0f;
		Graphics_DebugRect(newbb + sOffset, 0xff00ff);
		Graphics_DebugRect(topbb + sOffset, 0xff0000);
	} else {
		mNPCData.mPosition.y += static_cast<int>(mVelocity.y);
	}
}
开发者ID:pandaforks,项目名称:Mirage--,代码行数:48,代码来源:NPC.cpp

示例2: Update

void Character::Update(float deltaTime, const Map& map)
{
	const float kSpeed = 500.0f;

	//Check horizontal movement
	if (Input_IsKeyDown(Keys::RIGHT))
	{
		mVelocity.x = kSpeed * deltaTime;
	}
	else if (Input_IsKeyDown(Keys::LEFT))
	{
		mVelocity.x = -kSpeed * deltaTime;
	}
	else
	{
		mVelocity.x = 0.0f;
	}

	// Check collision
	SRect bb = GetBoundingBox();
	SRect newbb = bb + SVector2(mVelocity.x, 0.0f);
	SRect rightbb = map.GetBoundingBoxFromSegment(newbb.GetRightSegment());
	SRect leftbb = map.GetBoundingBoxFromSegment(newbb.GetLeftSegment());

	// Right collision
	if (mVelocity.x > 0.0f && rightbb.IsValid())
	{
		mPosition.x += (int)(rightbb.min.x - bb.max.x) - 1.0f;
	}
	// Left collision
	else if (mVelocity.x < 0.0f && leftbb.IsValid())
	{
		mPosition.x += (int)(leftbb.max.x - bb.min.x) + 1.0f;
	}
	else
	{
		mPosition.x += (int)mVelocity.x;
	}


	//Check vertical movement
	//if (Input_IsKeyDown(Keys::DOWN))
	//{
	//	mVelocity.y = kSpeed * deltaTime;
	//}
	//else if (Input_IsKeyDown(Keys::UP))
	//{
	//	mVelocity.y = -kSpeed * deltaTime;
	//}
	//else
	//{
	//	mVelocity.y = 0.0f;
	//}

	if(!mJumping && Input_IsKeyPressed(Keys::UP))
	{
		mVelocity.y = -30.0f;
		mJumping = true;
	}
	else
	{
		mVelocity.y += 100.0f * deltaTime;
	}

	mVelocity.y = Min(mVelocity.y, 30.0f);

	// Check collision
	newbb =  bb + SVector2(0.0f, mVelocity.y);
	SRect bottombb = map.GetBoundingBoxFromSegment(newbb.GetBottomSegment());
	SRect topbb = map.GetBoundingBoxFromSegment(newbb.GetTopSegment());

	// Bottom collision
	if(mVelocity.y > 0.0f && bottombb.IsValid())
	{
		mPosition.y += (int)(bottombb.min.y - bb.max.y) - 1.0f;
		mVelocity.y = 0.0f;
		mJumping = false;
	}
	// Top collision
	else if(mVelocity.y < 0.0f && topbb.IsValid())
	{
		mPosition.y += (int)(topbb.max.y - bb.min.y) + 1.0f;
		mVelocity.y = 0.0f;
	}
	else
	{
		mPosition.y += (int)mVelocity.y;
	}



}
开发者ID:bretthuff22,项目名称:Breaker,代码行数:92,代码来源:Character.cpp


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