本文整理匯總了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;
}
示例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;
}
}
示例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);
}
}
示例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;
}
示例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;
}
}
示例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;
}
}
}
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}
}
示例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;
}
}
示例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;
}
示例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;
}
示例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);
}
示例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 );
}