本文整理汇总了C++中CGameObject::AddComponent方法的典型用法代码示例。如果您正苦于以下问题:C++ CGameObject::AddComponent方法的具体用法?C++ CGameObject::AddComponent怎么用?C++ CGameObject::AddComponent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CGameObject
的用法示例。
在下文中一共展示了CGameObject::AddComponent方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CGameObject
CGameObject *CServiceGame::AddGridEntity(Grid* pGrid, glm::vec2& pos, GridEntity* pGEnt, IComponent* pComp)
{
CGameObject *pGo = new CGameObject();
pGo->AddComponent( pComp );
pGo->AddComponent( pGEnt );
pGo->Transform()->SetPos( glm::vec3(pos.x * Grid::SCALE, 0, pos.y * Grid::SCALE) );
pGo->Transform()->SetScale( Grid::SCALE / 2 );
g_vpGameObjects.push_back(pGo);
pGrid->SetGObject((int)pos.x, (int)pos.y, pGEnt);
return pGo;
}
示例2: InitializeGame
void CDemoGame::InitializeGame()
{
/* Setting a window to 0, 0, 0, 0 makes it default to the full window. The name is entirely for your own
reference later, should you want to display it as a title or the like. */
m_Window = new CVirtualWindow("Demo Window");
// An example shader.
m_Shader = new CDemoShader();
// Tell the window that we want to use this shader.
m_Window->UseShader(m_Shader);
// TODO: Delete this
CGameObject* gameObject = new CGameObject();
CSimpleSprite* simpleSprite = new CSimpleSprite(gameObject);
simpleSprite->SetName("Test Sprite");
simpleSprite->SetSprite(chtype('O' | A_BOLD | COLOR_PAIR(CE_Colour_YK)));
gameObject->AddComponent(simpleSprite);
}
示例3: Start
//-------------------------------------
// Called when the service is registered in the kernel
// rv - return true on succes,
// when false is returned then the service gets deleted
bool CServiceGame::Start()
{
Fab_LogWrite(FLOG_LVL_INFO, FLOG_ID_APP, "Game Service: Starting" );
SendMsg(SM_INPUT, this);
SendMsg(SM_RENDERER, this);
SMsgTimer msg(TimerCallback);
Fab_KernelSendMessage(&msg);
// just quit when the renderer or input wasn't filled in
if(m_pInput == nullptr || m_pRenderer == nullptr)
return false;
m_pRenderer->SetVSync(true);
// make needed object accesable for user
Fab_GlobalAccessorAddObject("Input", m_pInput);
m_pContent = Fab_ContentCreateManager(m_pRenderer);
if( !m_pContent->StartLoading() )
{
Fab_LogWrite(FLOG_LVL_ERROR, FLOG_ID_APP, "Game Service: Starting content loading failed." );
return false;
}
IShader *pShader = m_pContent->LoadShader("Shaders/SimpleShader");
pShader->Apply();
pShader->SetVarVec3( pShader->GetVarId("LightPosition_worldspace"), glm::vec3(0, 100, 0));
pShader->SetVarF1( pShader->GetVarId("LightPower"), 1.0f);
pShader->SetVarVec4( pShader->GetVarId("LightColor"), glm::vec4(1.0f, 1.0f, 1.0f, 1.0f));
IImage *pImage = m_pContent->LoadImage("Textures/CarDiffuseMap.png"),
*pImageFloor = m_pContent->LoadImage("Textures/FloorDif.png"),
*pImageWall = m_pContent->LoadImage("Textures/WallDif.png"),
*pImageFinish = m_pContent->LoadImage("Textures/FinishDif.png"),
*pImageWater = m_pContent->LoadImage("Textures/WaterDif.png"),
*pImagePlayer = m_pContent->LoadImage("Textures/PlayerDif.png"),
*pImageBug01 = m_pContent->LoadImage("Textures/Bug01Dif.png");
g_pMatDefault = Fab_MatCreateDifTexture(pShader, pImage);
g_pMatGround = Fab_MatCreateDifTexture(pShader, pImageFloor);
g_pMatWall = Fab_MatCreateDifTexture(pShader, pImageWall);
g_pMatFinish = Fab_MatCreateDifTexture(pShader, pImageFinish);
g_pMatWater = Fab_MatCreateDifTexture(pShader, pImageWater);
g_pMatPlayer = Fab_MatCreateDifTexture(pShader, pImagePlayer);
g_pMatBug01 = Fab_MatCreateDifTexture(pShader, pImageBug01);
CGameObject *pGo = new CGameObject();
pGo->Init();
CCompCamera* pCam = new CCompCamera();
pGo->AddComponent( pCam );
pGo->Transform()->SetPos( glm::vec3(0, 1 * Grid::SCALE, 0) );
pGo->Transform()->SetRot( glm::vec3(glm::radians(-90.0f), 0, 0) );
g_vpGameObjects.push_back(pGo);
Fab_GlobalAccessorAddObject("Camera", pGo);
g_pCam = pCam;
LoadLevel("level.lvl");
for (CGameObject* go : g_vpGameObjects)
go->Init();
m_pContent->EndLoading();
Fab_LogWrite(FLOG_LVL_INFO, FLOG_ID_APP, "Game Service: Started" );
return true;
}
示例4: LoadLevel
void CServiceGame::LoadLevel(const std::string& sFile)
{
int w = 0,
h = 1; // start at 1 because last line doesn't need an \n
int tw = 0;
//read file twice
// 1. read and count the grid size
std::ifstream is(sFile); // open file
while (is.good()) // loop while extraction from file is possible
{
char c = (char)is.get(); // get character from file
if (is.good())
{
// check which character i have
std::cout << c;
if ( c != '\n' )
++tw;
else
{
if( w < tw )
w = tw;
tw = 0;
++h;
}
}
}
std::cout << "\n\nw: " << w << " - h: " << h << "\n";
// return to start of the file and read again
is.clear();
is.seekg(0, std::ios::beg);
// 2. read and load in objects
Grid *pGrid = new Grid(w, h);
Fab_GlobalAccessorAddObject("Grid", pGrid);
glm::vec2 vPos(0, 0);
while (is.good()) // loop while extraction from file is possible
{
char c = (char)is.get(); // get character from file
if (is.good())
{
// check which character i have
switch(c)
{
case 'g':
AddGridEntity(pGrid, vPos, new Floor(), new CCompModel( m_pContent->LoadMesh("Meshes/floor.obj"), g_pMatGround ) );
break;
case 'm':
AddGridEntity(pGrid, vPos, new MovingFloor(), new CCompModel( m_pContent->LoadMesh("Meshes/floor.obj"), g_pMatGround ) );
break;
case 'v':
AddGridEntity(pGrid, vPos, new CollapseFloor(1), new CCompModel( m_pContent->LoadMesh("Meshes/floor.obj"), g_pMatDefault ) );
break;
case '~':
AddGridEntity(pGrid, vPos, new Water(), new CCompModel( m_pContent->LoadMesh("Meshes/floor.obj"), g_pMatWater ) );
break;
case 'w':
AddGridEntity(pGrid, vPos, new Wall(), new CCompModel( m_pContent->LoadMesh("Meshes/wall.obj"), g_pMatWall ) );
break;
case 'e':
AddGridEntity(pGrid, vPos, new Exit(), new CCompModel( m_pContent->LoadMesh("Meshes/floor.obj"), g_pMatFinish ) );
break;
case 'b':
AddGridEntity(pGrid, vPos, new Bomb(), new CCompModel( m_pContent->LoadMesh("Meshes/floor.obj"), g_pMatDefault ) );
break;
case 'c':
{
CGameObject *pGO = AddGridEntity(pGrid, vPos, new Candy(), new CCompModel( m_pContent->LoadMesh("Meshes/candy.obj"), g_pMatDefault ) );
pGO->AddComponent(new CCompModel( m_pContent->LoadMesh("Meshes/floor.obj"), g_pMatGround ));
break;
}
case 'p':
{
// first add a floor
AddGridEntity(pGrid, vPos, new Floor(), new CCompModel( m_pContent->LoadMesh("Meshes/floor.obj"), g_pMatGround ) );
//then add player
CGameObject *pGo = new CGameObject();
Entity *pEnt = new Player();
pEnt->SetRespawn(vPos);
pEnt->SetGridPos(vPos);
pGo->AddComponent( pEnt );
pGo->AddComponent( new CCompModel( m_pContent->LoadMesh("Meshes/Player.obj"), g_pMatPlayer ) );
pGo->Transform()->SetScale( 0.5f );
g_vpGameObjects.push_back(pGo);
Fab_GlobalAccessorAddObject("Player", pEnt);
break;
}
// 1D enemys
case '2':
case '4':
case '6':
case '8':
{
//.........这里部分代码省略.........