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


C++ CheckCollision函数代码示例

本文整理汇总了C++中CheckCollision函数的典型用法代码示例。如果您正苦于以下问题:C++ CheckCollision函数的具体用法?C++ CheckCollision怎么用?C++ CheckCollision使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: CheckCollision

iMovingObject* csBlobManager::CheckCollision (iMovingObject* b)
{
  int layer = b->GetLayer ();
  iBlobViewPort* vp = b->GetViewPort ();
  if (vp)
  {
    csBlobViewPort* viewport = static_cast<csBlobViewPort*> (vp);
    for (size_t i = 0 ; i < viewport->objects.GetSize () ; i++)
    {
      iMovingObject* o = viewport->objects.Get (i);
      if (o != b && o->GetLayer () == layer && CheckCollision (b, o))
        return o;
    }
  }
  else
  {
    for (size_t i = 0 ; i < movingobjects[layer].GetSize () ; i++)
    {
      iMovingObject* o = movingobjects[layer].Get (i);
      if (o != b && o->GetViewPort () == 0 && CheckCollision (b, o))
        return o;
    }
  }
  return 0;
}
开发者ID:GameLemur,项目名称:Crystal-Space,代码行数:25,代码来源:blobs.cpp

示例2: if

/* Checks if the ball hit a wall or a goal post. 
 * In case it did the ball will bounce off. 
 * The parameter is the future positions of the
 * center of the ball. It's used to check the collision
 * with the goal posts. */
void Game::WallHitCheck(){

	Point2d ball_pos = ball->GetObject()->axiscenter;
	// Collision with the ball
	if (ball_pos.x - BALL_CIRCLE_RAY <= Field::LEFTUCORNER.x + Field::LINE_WIDTH ||
		ball_pos.x + BALL_CIRCLE_RAY >= Field::RIGHTUCORNER.x){
			deltax *= -1;
			m_team_last = -1;
			m_player_last = -1;
	}
	else if (ball_pos.y + BALL_CIRCLE_RAY >= Field::RIGHTUCORNER.y ||
		ball_pos.y - BALL_CIRCLE_RAY <= Field::RIGHTLCORNER.y + Field::LINE_WIDTH){
			deltay *= -1;
			m_team_last = -1;
			m_player_last = -1;
	}

	Point2d ball_center(ball_pos.x + SPEED * deltax * m_dt, 
						ball_pos.y + SPEED * deltay * m_dt);
	// Collision with one of the goal posts
	if (CheckCollision(ball_center, Field::UP_MIDDLE_LEFT) > 0 || 
		CheckCollision(ball_center, Field::UP_MIDDLE_RIGHT) > 0 ||
		CheckCollision(ball_center, Field::BOTTOM_MIDDLE_LEFT) > 0 ||
		CheckCollision(ball_center, Field::BOTTOM_MIDDLE_RIGHT) > 0) {
			deltay *= -1;
			m_team_last = -1;
			m_player_last = -1;
	}
}
开发者ID:marius-avram,项目名称:Tema-EGC-1,代码行数:34,代码来源:Game.cpp

示例3: GetActorLocation

void AMobileEnemy::Tick(float DeltaSeconds) {
  DeltaSeconds = TimeManager::Instance()->GetDeltaTime(DeltaSeconds);
  m_lastPosition = GetActorLocation();
  m_nextPosition = m_lastPosition;
  EnemyAnimationMesh->bPauseAnims = TimeManager::Instance()->IsPaused();

  if (!m_player) {
    for (TActorIterator< APawn > ActorItr(GetWorld()); ActorItr; ++ActorItr) {
      if (ActorItr->ActorHasTag("Player")) {
        m_player = (APlayerOvi*)*ActorItr;
        m_jumpSpeed = m_player->JumpSpeed;
        m_accelerationJump = m_player->AccelerationJump;
        break;
      }
    }
  }
  m_tickCounter++;
  if (!HasTrigger || (HasTrigger && m_initMovement)) {
    CheckCollision();
    doMovement(DeltaSeconds);
    CalculateGravity(DeltaSeconds);
    CheckCollision();
    SetActorLocation(m_nextPosition);
  }
}
开发者ID:alfreSosa,项目名称:PC-TowardsTheLight,代码行数:25,代码来源:MobileEnemy.cpp

示例4: CollisionResult

int CollisionResult()
{
    // collision with bad shroom
    if ( CheckCollision(&g_hippy, &g_shroom) || CheckCollision(&g_hippy, &g_fireBall) )
    {
        g_lives--;
        if (g_lives < 0)
        {
            //ham_DeleteObj(g_hippy.sprite);
            //ham_DeleteObj(g_shroom.sprite);
            return 1;
        }
        else
        {
            // set life counter frame
            ham_UpdateObjGfx(g_lifeCount.sprite, (void *)&lives_bitmap[g_lifeCount.w * g_lifeCount.h * g_lives]);
            return -1;
        }
    }
    
    // collision with key shroom
    if ( CheckCollision(&g_hippy, &g_key) )
    {
        ham_DeleteObj(g_hippy.sprite);
        ham_DeleteObj(g_shroom.sprite);
        ham_DeleteObj(g_key.sprite);
        ham_DeleteObj(g_fireBall.sprite);
        return 3;
    }

    return 0;
}
开发者ID:yxrkt,项目名称:DigiPen,代码行数:32,代码来源:game.c

示例5: cos

void Animal::Move(World &world)
{
	if (m_isAlive)
	{
		m_vitesse.x = 0.05;
		m_vitesse.z = 0.05;

		if (m_ClockTarget.getElapsedTime().asSeconds() < m_timeNextTarget)
		{
			Vector3<float> deplacementVector = Vector3<float>(sin(m_HorizontalRot / 180 * PI), 0.f, cos(m_HorizontalRot / 180 * PI));
			deplacementVector.Normalize();

			//Avance en x
			m_pos.x += deplacementVector.x * m_vitesse.x;
			if (CheckCollision(world))
			{
				m_pos.x -= deplacementVector.x * m_vitesse.x;
				Jump();
			}
			//En z
			m_pos.z += deplacementVector.z * m_vitesse.z;
			if (CheckCollision(world))
			{
				m_pos.z -= deplacementVector.z * m_vitesse.z;
				Jump();
			}
		}
		else
		{
			m_HorizontalRot += rand() % 200 - 100;
			m_timeNextTarget = rand() % 10;
			m_ClockTarget.restart();
		}



		//Chute
		m_pos.y -= m_vitesse.y;

		//Si collision
		if (CheckCollision(world))
		{

			//Si on a touche le sol 
			if (m_vitesse.y > 0)
				m_isInAir = false;

			//annule
			m_pos.y += m_vitesse.y;
			m_vitesse.y = 0;
		}
		else
			m_isInAir = true;

		//Acceleration
		m_vitesse.y += 0.013f;

	}
}
开发者ID:Domix24,项目名称:Cube,代码行数:59,代码来源:animal.cpp

示例6:

void	CCollision::SpellCollision(CMap *MapPointer,CEntityManager *EntityPointer,CSpell *SpellPointer)
{
	if (MapPointer->m_spell.empty())
		return;

	for (int i = MapPointer->m_spell.size()-1; i >= 0; i--)
	{
		// check if player was hit by a spell
		if (CheckCollision((int)MapPointer->m_playerX,(int)MapPointer->m_playerY,(int)MapPointer->m_spell[i].x,(int)MapPointer->m_spell[i].y,TILE_SIZE))
		{
			// check to see if the spell was not created by player
			if (MapPointer->m_spell[i].parent != -1)
			{
				// spell casted by enemy
				int hp = EntityPointer->m_pPlayer->GetHP();
				int mp = EntityPointer->m_pPlayer->GetMP();

				SpellPointer->SpellHit(MapPointer->m_spell[i].imgID,MapPointer->m_spell[i].lvl,hp,mp);
				
				EntityPointer->m_pPlayer->SetHP(hp);
				EntityPointer->m_pPlayer->SetMP(mp);
				
				MapPointer->m_spell.erase(MapPointer->m_spell.begin()+i);

				continue;
			}
		}

		//checking if an enemy has been hit by a spell

		for (size_t j = 0; j < MapPointer->m_closeEnemyXY.size(); j++)
		{
			if (CheckCollision((int)MapPointer->m_closeEnemyXY[j].x,(int)MapPointer->m_closeEnemyXY[j].y,(int)MapPointer->m_spell[i].x,(int)MapPointer->m_spell[i].y,TILE_SIZE))
			{
				int hp = EntityPointer->m_VCloseEnemy[j].GetHP();
				int mp = EntityPointer->m_VCloseEnemy[j].GetMP();

				if (MapPointer->m_spell[i].parent == -1)
				{   // spell casted by player
					SpellPointer->SpellHit(MapPointer->m_spell[i].imgID,MapPointer->m_spell[i].lvl,hp,mp);
				}

				EntityPointer->m_VCloseEnemy[j].SetHP(hp);
				EntityPointer->m_VCloseEnemy[j].SetMP(mp);
				
				// enemies created on map must be created in the same order in EntityManager so that the same index can be used to access both
				MapPointer->m_spell.erase(MapPointer->m_spell.begin()+i);
				
				break;
			}
		}
	}
}
开发者ID:IvanTutavac,项目名称:DD_0.2,代码行数:53,代码来源:CCollision.cpp

示例7: PlayerMissileCollision

//handles collision for missiles and player
bool CollisionManager::PlayerMissileCollision(Player& player, EnemyMissile& missile, Explosions& explosion)
{
	for (unsigned int i = 0; i < missile.missiles.size(); i++)
	{
		if (CheckCollision(player.box_1, missile.missiles[i]->box) || CheckCollision(player.box_2, missile.missiles[i]->box))
		{
			explosion.ExplosionHandler(player.box.x, player.box.y - 20, 2);
			missile.missiles[i]->isAlive = false;
			return true;
		}
	}
	return false;
}
开发者ID:dvellucci,项目名称:2D-Space-Shooter,代码行数:14,代码来源:CollisionManager.cpp

示例8: EnemyBulletCollisions

bool CollisionManager::EnemyBulletCollisions(Enemy1Bullet& bullet, Player& player, Explosions& explosion)
{
	//loop through the enemy bullet vector to check if any hit the player
	//if the player is hit destroy the bullet and decrease player health by 1
	for (unsigned int i = 0; i < bullet.enemyBullets.size(); i++)
	{
		if (CheckCollision(bullet.enemyBullets[i]->box, player.box_1) || CheckCollision(bullet.enemyBullets[i]->box, player.box_2))
		{
			explosion.ExplosionHandler(player.box.x, player.box.y - 20, 2); //this will play an explosion on the player when it gets hit
			bullet.enemyBullets[i]->isAlive = false;
			return true;
		}
	}
	return false;
}
开发者ID:dvellucci,项目名称:2D-Space-Shooter,代码行数:15,代码来源:CollisionManager.cpp

示例9: GetIndexPosX

void CBaseGolem::Update(float fDT)
{
	CBaseEntity::Update(fDT);

	/*if( GetFlag_prev_MovementState() == FLAG_MOVESTATE_MOVING)
	{		
		if(this->GetFlag_MovementState() == FLAG_MOVESTATE_ATDESTINATION)
		{
		int objectID = MObjectManager::GetInstance()->FindLayer( this->m_nIdentificationNumber ).GetFlake( OBJECT_OBJECT ).GetInfoAtIndex( GetIndexPosX() , GetIndexPosY() ) ;
		IUnitInterface* object = (MObjectManager::GetInstance()->GetUnit(objectID)) ;
		
		CheckCollision( object , true );
		}
	}*/

	if(( GetDistanceLeft() <= 32 && GetDistanceLeft() >= 30 ) || (GetDistanceLeft() <= 16 && GetDistanceLeft() >= 14 ) )
		CSGD_FModManager::GetInstance()->PlaySound2D( m_nStepSoundID, CGamePlayState::GetInstance()->testVaribale, this->m_nIdentificationNumber) ;

	//UpdateAI();



	if( LastDistance > 0.0f && GetDistanceLeft() < 0.1f )
	{
		CheckCollision( 
			MObjectManager::GetInstance()->GetUnit( 
			MObjectManager::GetInstance()->FindLayer( m_nIdentificationNumber ).GetFlake( OBJECT_OBJECT ).GetInfoAtIndex( GetIndexPosX(), GetIndexPosY() ) ), true );
	}

	LastDistance = GetDistanceLeft();

}
开发者ID:Ethanthecrazy,项目名称:baf-labyrinth-game,代码行数:32,代码来源:CBaseGolem.cpp

示例10: Update

void GuiItem::Update(GuiElement* hover, GuiElement* focus)
{
	//If there's no dragged_item, when clicking over the item, it's freed from the inventory
	if (!(App->gui->dragged_item))
	{
		if (CheckCollision(App->input->GetMousePosition()))
		{
			//Feedback :D
			inventory->SetSlotsState(this, GREEN);

			mousehover = true;

			if (App->input->GetMouseButtonDown(SDL_BUTTON_LEFT) == KEY_DOWN)
			{
				inventory->FreeItem(this);

			}
		}
		else
			mousehover = false;
		
			
	}

	
	if (App->gui->dragged_item == this)
	{
		mousehover = false;
	}
}
开发者ID:joeyGumer,项目名称:Pixel_Mirror--Diablo_II,代码行数:30,代码来源:GuiItem.cpp

示例11: SetAnimation

void UNIT::Update(float deltaTime)
{
	//update unit animation time
	m_time += deltaTime * 0.8f * m_speed;

	//if the unit is moving...
	if(m_moving)
	{
		if(m_movePrc < 1.0f)m_movePrc += deltaTime * m_speed;
		if(m_movePrc > 1.0f)m_movePrc = 1.0f;
		
		//waypoint reached
		if(m_movePrc == 1.0f)
		{
			if(m_activeWP + 1 >= (int)m_path.size())		//goal reached
			{
				m_moving = false;
				SetAnimation("Still");
			}
			else if(!CheckCollision(m_path[m_activeWP + 1])) //Next Waypoint
			{			
				m_activeWP++;
				SetAnimation("Run");
				MoveUnit(m_path[m_activeWP]);
			}
		}

		//Interpolate position between m_lastWP and m_nextWP
		m_position = m_lastWP * (1.0f - m_movePrc) + m_nextWP * m_movePrc;
	}
}
开发者ID:Alriightyman,项目名称:RTS,代码行数:31,代码来源:unit.cpp

示例12: PlayerEnemyCollisions

bool CollisionManager::PlayerEnemyCollisions(EnemyShip1& enemy, Player& player, Explosions& explosion)
{
	//check if the enemy and player collide
	//if they do, destroy the enemy and decrease player health
	for (unsigned int i = 0; i < enemy.enemies.size(); i++)
	{
		if (CheckCollision(player.box_1, enemy.enemies[i]->box_1) || CheckCollision(player.box_1, enemy.enemies[i]->box_2) || CheckCollision(player.box_2, enemy.enemies[i]->box_1) || CheckCollision(player.box_2, enemy.enemies[i]->box_2))
		{
			explosion.ExplosionHandler(enemy.enemies[i]->box.x, enemy.enemies[i]->box.y, 1);//add an explosion when an enemy dies
			explosion.ExplosionHandler(player.box.x, player.box.y - 20, 2);
			enemy.enemies[i]->isAlive = false;
			return true;
		}
	}
	return false;
}
开发者ID:dvellucci,项目名称:2D-Space-Shooter,代码行数:16,代码来源:CollisionManager.cpp

示例13: CheckCollision

int CMonsterClubB1::DoAction(/*CScreen* scr, */IObjectManager* objMan)
{
	mYMove= (CGTimer::Time()-oldmove)*mSpeed;
	oldmove=CGTimer::Time();
	int i = CheckCollision(objMan);
	if(mJumpDirect==1)
	{	if (GetBit(i,2)==1)
	{
		mJumpDirect=0;
	}
	else
		mYPos=mYPos-mYMove;

	}
	if(mJumpDirect==0)
	{	if (GetBit(i,3)==1)
	{
		return -1;
	}
	else
		mYPos=mYPos+mYMove;

	}

	NextFrame();
	return 1;
}
开发者ID:Dr-Hydrolics,项目名称:mariogame,代码行数:27,代码来源:Monster.cpp

示例14: GetSelectedItem

// Update the skeleton transforms based on the dragger.
void IvObjectDragger::UpdateSkeleton()
{
    ItemPtr selectedItem = GetSelectedItem();
    if( !selectedItem ) {
        return;
    }
    RaveTransform<float> tbox;
    const float* q = _transformBox->rotation.getValue().getValue();
    tbox.rot = Vector(q[3], q[0], q[1], q[2]);
    SbVec3f v = _transformBox->translation.getValue();
    tbox.trans = Vector(v[0], v[1], v[2]);

    Transform told; told.trans = -_ab.pos;

    RaveTransform<float> tnew = tbox*told*_toffset;
    SetSoTransform(selectedItem->GetIvTransform(), tnew);

    KinBodyItemPtr pbody = boost::dynamic_pointer_cast<KinBodyItem>(selectedItem);
    if( !!pbody ) {
        pbody->UpdateFromIv();
        CheckCollision(_checkCollision);
    }
    // other motion handler calls
    _viewer.lock()->_UpdateCameraTransform(0);
}
开发者ID:AbuShaqra,项目名称:openrave,代码行数:26,代码来源:ivselector.cpp

示例15: Fade

void CPartSnowFlake::Think( float flTime )
{
	if( m_flBrightness < 130.0 && !m_bTouched )
		m_flBrightness += 4.5;

	Fade( flTime );
	Spin( flTime );

	if( m_flSpiralTime <= gEngfuncs.GetClientTime() )
	{
		m_bSpiral = !m_bSpiral;

		m_flSpiralTime = gEngfuncs.GetClientTime() + UTIL_RandomLong( 2, 4 );
	}
	else
	{
	}

	if( m_bSpiral && !m_bTouched )
	{
		const float flDelta = flTime - g_Environment.GetOldTime();

		const float flSpin = sin( flTime * 5.0 + reinterpret_cast<int>( this ) );
	
		m_vOrigin = m_vOrigin + m_vVelocity * flDelta;

		m_vOrigin.x += ( flSpin * flSpin ) * 0.3;
	}
	else
	{
		CalculateVelocity( flTime );
	}

	CheckCollision( flTime );
}
开发者ID:oskarlh,项目名称:HLEnhanced,代码行数:35,代码来源:CPartSnowFlake.cpp


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