您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ CheckCollision函数代码示例

51自学网 2021-06-01 20:10:18
  C++
这篇教程C++ CheckCollision函数代码示例写得很实用,希望能帮到您。

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

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


示例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,


示例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,


示例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,


示例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,


示例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,


示例7: PlayerMissileCollision

//handles collision for missiles and playerbool 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,


示例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,


示例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,


示例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,


示例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,


示例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,


示例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,


示例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,


示例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,


示例16: GetRTCPSourceData

int RTPSources::GetRTCPSourceData(uint32_t ssrc, const RTPAddress *senderaddress, RTPInternalSourceData **srcdat2, bool *newsource){    int status;    bool created;    RTPInternalSourceData *srcdat;    *srcdat2 = 0;    if ((status = ObtainSourceDataInstance(ssrc, &srcdat, &created)) < 0)        return status;    if (created)    {        if ((status = srcdat->SetRTCPDataAddress(senderaddress)) < 0)            return status;    }    else // got a previously existing source    {        if (CheckCollision(srcdat, senderaddress, false))            return 0; // ignore packet on collision    }    *srcdat2 = srcdat;    *newsource = created;    return 0;}
开发者ID:sigysmund,项目名称:sdrangel,代码行数:27,


示例17: UpdateContent

void UpdateContent(LevelContent* m_content,SDL_Rect camera){	for (unsigned int i = 0; i < m_content->ennemies.size(); ++i)	{		m_content->ennemies.at(i).Update(m_content->tileMap);		for (unsigned int j = 0; j < m_content->bullets.size(); ++j)		{			if (CheckCollision(m_content->ennemies.at(i).GetRect(),				m_content->bullets.at(j).GetRect()))			{				m_content->bullets.erase(m_content->bullets.begin() + j);				m_content->ennemies.erase(m_content->ennemies.begin() + i);				break;			}		}	}	for (unsigned int i = 0; i < m_content->items.size(); ++i)	{		if (isOutScreen(camera, m_content->items.at(i).GetRect()))			m_content->items.erase(m_content->items.begin() + i);		else			m_content->items.at(i).Update(m_content->tileMap);		}		for (unsigned int j = 0; j < m_content->bullets.size(); ++j)	{		m_content->bullets.at(j).Update(m_content->tileMap);		if (m_content->bullets.at(j).isEnd() || isOutScreen(camera, m_content->bullets.at(j).GetRect()))			m_content->bullets.erase(m_content->bullets.begin() + j);	}	}
开发者ID:Clever-Boy,项目名称:SDLMarioBros,代码行数:32,


示例18: if

/** /param fDeltaTime: time since last Update */void Player::Update(shoot::f32 fDeltaTime){	super::Update(fDeltaTime);	bool bRightPressed = shoot::InputManager::Instance()->IsKeyPressed(shoot::InputManager::KT_Right);	bool bLeftPressed = shoot::InputManager::Instance()->IsKeyPressed(shoot::InputManager::KT_Left);		if(bRightPressed)	{		m_vVelocity = m_vSlidingDirection*m_fAcceleration;			}	else if(bLeftPressed)	{		m_vVelocity = m_vSlidingDirection*-m_fAcceleration;	}			bool bWasInTheAir = IsInTheAir();	if(bWasInTheAir)	{		m_vVelocity.Y += m_fGravity;	}		if(IsInTheAir() || (bRightPressed || bLeftPressed))	{		CheckCollision(m_vPosition, m_vVelocity, m_vPosition, m_vVelocity);		if(bWasInTheAir && !IsInTheAir())		{			shoot::Print("*** bWasInTheAir && !IsInTheAir()/n");		}		m_vPosition += m_vVelocity;	}	}
开发者ID:aminere,项目名称:VLADHeavyStrikePublic,代码行数:35,


示例19: Goto

void UNIT::Goto(INTPOINT mp){	if(m_pTerrain == NULL)return;	//Clear old path	m_path.clear();	m_activeWP = 0;	if(m_moving)		//If unit is currently moving	{		//Finish the active waypoint 		m_path.push_back(m_mappos);		std::vector<INTPOINT> tmpPath = m_pTerrain->GetPath(m_mappos, mp);		//add new path		for(int i=0;i<(int)tmpPath.size();i++)			m_path.push_back(tmpPath[i]);	}	else		//Create new path from scratch...	{		m_path = m_pTerrain->GetPath(m_mappos, mp);				if(m_path.size() > 0)		//if a path was found		{			m_moving = true;			//Check that the next tile is free			if(!CheckCollision(m_path[m_activeWP]))			{				MoveUnit(m_path[m_activeWP]);				SetAnimation("Run");							}		}	}}
开发者ID:Alriightyman,项目名称:RTS,代码行数:35,


示例20: HandleDown

void BlockControl::HandleDown(const Uint8 *state, float frame_time, std::vector<Square> board_squares){		if (!CheckCollision(current_block.block_squares, Block::DOWN, board_squares))	{		if (state[SDL_SCANCODE_DOWN])		{						velocity = 120;		}		if (!state[SDL_SCANCODE_DOWN])		{			if (velocity == 120)			{				velocity = 60;			}		}	}}
开发者ID:Ben2917,项目名称:PuzzleGame,代码行数:28,


示例21:

/** * Moves the current piece to the left. */void TetraminoesManager::InnerData::MoveLeft() {    int aux = pieceX;    pieceX--;    if(CheckCollision()) {        pieceX = aux;    }}
开发者ID:gorkinovich,项目名称:GAGC,代码行数:11,


示例22: Move

void EnemyBase::Update(){    if(isAlive)    {        Move();        CheckCollision();    }}
开发者ID:gwulfers88,项目名称:2DShooterGame_Final,代码行数:8,


万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。