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


C++ CEntity::OnCollision方法代码示例

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


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

示例1: OnLoop

void CApp::OnLoop()
{
	CFPS::FPSControl.OnLoop();
	
	for(int i=0; i<CEntity::EntityList.size(); i++)
	{
		if(!CEntity::EntityList[i]) continue;

		CEntity::EntityList[i]->OnLoop();
	}

	// handle collision events
	for(int i=0; i<CEntityCol::entityColList.size(); i++)
	{
		CEntity* entityA = CEntityCol::entityColList[i].entityA;
		CEntity* entityB = CEntityCol::entityColList[i].entityB;

		if(entityA == NULL || entityB == NULL) continue;

		// call 2nd only if desired (timesaving)
		if(entityA->OnCollision(entityB))
			entityB->OnCollision(entityA);
	}
	CEntityCol::entityColList.clear();
}
开发者ID:vincerp,项目名称:ballin-octo-dangerzone,代码行数:25,代码来源:CApp_OnLoop.cpp

示例2: OnLoop

void CAppStateGame::OnLoop() {
    for(int i = 0;i < CEntity::EntityList.size();i++) {
        if(!CEntity::EntityList[i]) continue;

        CEntity::EntityList[i]->OnLoop();

        if (CEntity::EntityList[i]->Type == ENTITY_TYPE_ENEMY) {
            if(!Player.Dead) {
                CEntity::EntityList[i]->Shoot(Player.X + (Player.Width / 2),Player.Y + (Player.Height / 2));
            }
        }
    }

    //Collision Events
    for(int i = 0;i < CEntityCol::EntityColList.size();i++) {
        CEntity* EntityA = CEntityCol::EntityColList[i].EntityA;
        CEntity* EntityB = CEntityCol::EntityColList[i].EntityB;

        if(EntityA == NULL || EntityB == NULL) continue;

        if(EntityA->Dead == true || EntityB->Dead == true) continue;

        if(EntityA->OnCollision(EntityB)) {
            EntityB->OnCollision(EntityA);
        }
    }

    CEntityCol::EntityColList.clear();

    if (Player.Dead) {
        WinMessage.boolMessage = false;
        CAppStateManager::SendMessage(APPSTATE_END, &WinMessage);
        CAppStateManager::SetActiveAppState(APPSTATE_END);
    }
 //   if (Archer.Dead) {
 //      WinMessage.boolMessage = true;
 //       CAppStateManager::SendMessage(APPSTATE_END,&WinMessage);
 //       CAppStateManager::SetActiveAppState(APPSTATE_END);
 //   }
    if(Player.Money > 0) {
        WinMessage.boolMessage = true;
        CAppStateManager::SendMessage(APPSTATE_END,&WinMessage);
        CAppStateManager::SetActiveAppState(APPSTATE_END);
    }
        for(std::vector<CEntity*>::iterator it = CEntity::EntityList.begin(); it != CEntity::EntityList.end();) {
        if(!(*it)) continue;
        if((*it)->Dead == true) {
                (*it)->OnCleanup();
                delete (*it);
                it = CEntity::EntityList.erase(it);
        }
        else {
                it++;
        }
    }

    char Buffer[255];
    sprintf(Buffer,"Player Health: %d  |||  Enemy Health: %d ||| Money: %d", Player.Health, Archer.Health, Player.Money);
    SDL_WM_SetCaption(Buffer,Buffer);
}
开发者ID:cannon10100,项目名称:SlimeGame,代码行数:60,代码来源:CAppStateGame.cpp

示例3: Loop

void CGame::Loop() 
{    
    // Run any Managed Events
    CEventsManager::EventsManager.Loop();
    
    // Run each item in entity list
    int size = CEntity::EntityList.size();
  
    for (int i = 0; i < size; i++) 
    {        
        if(!CEntity::EntityList[i]) continue;        
        CEntity::EntityList[i]->Loop();              
    }
  
    //Collision Events
    for(std::vector<CEntityCollision>::iterator it = CEntityCollision::EntityCollisionList.begin();it != CEntityCollision::EntityCollisionList.end(); ++it) 
    {
        if (it->Complete == false)
        {
            CEntity* EntityA = it->EntityA;
            CEntity* EntityB = it->EntityB;

            if(EntityA == NULL || EntityB == NULL) continue;

            if(EntityA->OnCollision(EntityB))
                EntityB->OnCollision(EntityA);

            // Remove this and it's pair from the list by marking them as Complete
            it->RemoveCollision(EntityA, EntityB);
        }
    }

    CEntityCollision::EntityCollisionList.clear();

    // Handle scoring & Timing
    CAreaScoring::AreaScoring.Loop();
    
    CLevel::Level.GetCurrentArea()->Loop();
   
    // Give some CPU back
    SDL_Delay(1);
}
开发者ID:MindGuerrillas,项目名称:MarioStylePlatformer,代码行数:42,代码来源:CGame_Loop.cpp

示例4: OnLoop

//-----------------------------------------------------------------------------
void CAppStateGame::OnLoop() {

	if( GameOver ) {
		if( !Input.HasFocus() ) {
			if( Input.State == UI_NORMAL ) {
				CHighScores HighScore;
				HighScore.OnInit();
				HighScore.Add(Input.GetValue(),Player->Points);
			}
			GameOver = false;
			CAppStateManager::SetActiveAppState(NextState);

			CSoundBank::SoundControl.Play(CSoundBank::MUSIC, "MenuMusic");

		}
		return;
	}

	//If the level should change
	//if( CCamera::CameraControl.GetX() >= LevelEndingPoint ) {
	//	OnLevelChange();
	//}

	// Spawn new entities
	//else if( LevelInfoIndex < Level.size() && 
	if( LevelInfoIndex < Level.size() &&
		(unsigned int)CCamera::CameraControl.GetX() >= Level.at(LevelInfoIndex).ActiveXPosition) {

		CAppStateGame::LevelInfo TmpInfo = Level.at(LevelInfoIndex);

		switch(TmpInfo.Type) { 
			case ENTITY_TYPE_ENEMY:
				debug("creating enemy of type: " + IntToString(TmpInfo.SubType));
				CFactory::Factory.CreateEnemy(TmpInfo.SubType, CCamera::CameraControl.GetX()+1000, TmpInfo.YPosition);
				break;
			case ENTITY_TYPE_ITEM:
				CFactory::Factory.CreateItem(TmpInfo.SubType, CCamera::CameraControl.GetX()+1000, TmpInfo.YPosition);
				break;
			case ENTITY_TYPE_SPECIAL_EFFECT:
				// NOTE: y-position is now indicating the ms duration for the slowmo effect

				if (TmpInfo.SubType == ENTITY_SUBTYPE_SPECIAL_EFFECT_SLOWMO_2X) {
					CFactory::Factory.CreateSlowMotion(LEVEL_SLOWMO_2X, TmpInfo.YPosition);
				}
				else if (TmpInfo.SubType == ENTITY_SUBTYPE_SPECIAL_EFFECT_SLOWMO_4X) {
					CFactory::Factory.CreateSlowMotion(LEVEL_SLOWMO_4X, TmpInfo.YPosition);
				}
				else if (TmpInfo.SubType == ENTITY_SUBTYPE_SPECIAL_EFFECT_SLOWMO_8X) {
					CFactory::Factory.CreateSlowMotion(LEVEL_SLOWMO_8X, TmpInfo.YPosition);
				}
				break;
			default:
				break;
		}

		LevelInfoIndex++;
	}

    //--------------------------------------------------------------------------
    // Entities
    //--------------------------------------------------------------------------
    for(unsigned int i = 0;i < CEntity::EntityList.size();i++) {
        if(!CEntity::EntityList[i]) continue;

        CEntity::EntityList[i]->OnLoop();
    }

    //Collision Events
    for(unsigned int i = 0;i < CEntityCol::EntityColList.size();i++) {
        CEntity* EntityA = CEntityCol::EntityColList[i].EntityA;
        CEntity* EntityB = CEntityCol::EntityColList[i].EntityB;

        if(EntityA == NULL || EntityB == NULL) continue;

		/* Pixel precise collision detection */

		// Create rectangle of the possible collision area
		SDL_Rect collisionRect = CEntity::Intersection(EntityA->GetBounds(), EntityB->GetBounds());
		
		// Check if there is even a possible collision
		if(collisionRect.w != 0 && collisionRect.h != 0 ) {
			// Check if there is/are actual pixel overlapping between
			// both entities. If there is...
			if(CEntity::CheckCollision(EntityA, EntityB)) {
				// Let both entities know of the collision
				EntityA->OnCollision(EntityB);
				EntityB->OnCollision(EntityA);
			}
		}
    }

    CEntityCol::EntityColList.clear();

	// Camera movement:
	// Make camera move wanted amount of pixels per second to right
	float moveX = CCamera::CameraControl.speed * CFPS::FPSControl.GetSpeedFactor();

	// If we are not in the boss area
	if ( (CCamera::CameraControl.GetX() + (int)moveX) < LEVEL_LENGTH) {
//.........这里部分代码省略.........
开发者ID:phautamaki,项目名称:Space-Invaders,代码行数:101,代码来源:CAppStateGame.cpp

示例5: OnLoop

//==============================================================================
void CApp::OnLoop() {
	count++;
	if (count == 5) {
		Samus.X = 50;
		Samus.Y = 50;
		Simon.X = 50;
		Simon.Y = 50;
		OnPosReset();	
	}	
	
    //--------------------------------------------------------------------------
    // Entities
    //--------------------------------------------------------------------------
    for(int i = 0;i < CEntity::EntityList.size();i++) {
        if(!CEntity::EntityList[i]) continue;

        CEntity::EntityList[i]->OnLoop();//call the loop function of each entity
    }

	//loop through all collision incidents
    for(int i = 0;i < CEntityCol::EntityColList.size();i++) {
       CEntity* EntityA = CEntityCol::EntityColList[i].EntityA;//load first entity
       CEntity* EntityB = CEntityCol::EntityColList[i].EntityB;//load second entity
 
       if(EntityA == NULL || EntityB == NULL) continue;//if there were no entitys colided with then keep going
 
       if(EntityA->OnCollision(EntityB)) {//load oncollision for entity A with b
           EntityB->OnCollision(EntityA);//load onCollision for entity b with a
       }
    }
 
    CEntityCol::EntityColList.clear();//clear the collision list

    CFPS::FPSControl.OnLoop();//loop to check the frames per second

    char Buffer[255];
    sprintf(Buffer, "%d", CFPS::FPSControl.GetFPS());
    SDL_WM_SetCaption(Buffer, Buffer);// set the caption of game


	if(metroid) {//if we are playing samus update the appropriate enemys on her current position
		//skeleton player tracking
		Alpha.playerPos = Samus.X;
		Alpha.yPlayerPos= Samus.Y;
		Bravo.playerPos = Samus.X;
		Bravo.yPlayerPos = Samus.Y;
		Charlie.playerPos = Samus.X;
		Charlie.yPlayerPos= Samus.Y;
		Delta.playerPos = Samus.X;
		Delta.yPlayerPos= Samus.Y;
		Echo.playerPos = Samus.X;
		Echo.yPlayerPos= Samus.Y;
		Foxtrot.playerPos = Samus.X;
		Foxtrot.yPlayerPos= Samus.Y;
		Golf.playerPos = Samus.X;
		Golf.yPlayerPos= Samus.Y;
		Hotel.playerPos = Samus.X;
		Hotel.yPlayerPos= Samus.Y;
		India.playerPos = Samus.X;
		India.yPlayerPos= Samus.Y;
		//dog player tracking
		Ramza.playerPos = Samus.X;
		Ramza.yPlayerPos= Samus.Y;
		Firion.playerPos = Samus.X;
		Firion.yPlayerPos = Samus.Y;
		Luneth.playerPos = Samus.X;
		Luneth.yPlayerPos= Samus.Y;
		Cecil.playerPos = Samus.X;
		Cecil.yPlayerPos= Samus.Y;
		Bartz.playerPos = Samus.X;
		Bartz.yPlayerPos= Samus.Y;
		Terra.playerPos = Samus.X;
		Terra.yPlayerPos= Samus.Y;
		Cloud.playerPos = Samus.X;
		Cloud.yPlayerPos= Samus.Y;
		Squall.playerPos = Samus.X;
		Squall.yPlayerPos= Samus.Y;
		Zidane.playerPos = Samus.X;
		Zidane.yPlayerPos= Samus.Y;
		Tidus.playerPos = Samus.X;
		Tidus.yPlayerPos= Samus.Y;
		Mog.playerPos = Samus.X;
		Mog.yPlayerPos = Samus.Y;
		Vaan.playerPos = Samus.X;
		Vaan.yPlayerPos = Samus.Y;
		Lightning.playerPos = Samus.X;
		Lightning.yPlayerPos= Samus.Y;

		if(Samus.Dead==true) {//if she is dead
			OnGameOver();//run onGameOver
		}
	}	
		
	if(castlevania) {//if we are playing simon update the appropriate enemys on his current position
		//skeleton player tracking
		Alpha.playerPos = Simon.X;
		Alpha.yPlayerPos= Simon.Y;
		Bravo.playerPos = Simon.X;
		Bravo.yPlayerPos = Simon.Y;
//.........这里部分代码省略.........
开发者ID:cbarron1,项目名称:Metrovania,代码行数:101,代码来源:CApp_OnLoop.cpp


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