コード例 #1
0
ファイル: CServiceGame.cpp プロジェクト: depuits/Fabian
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
0
ファイル: gameObjects.cpp プロジェクト: dreadlocked/go-engine
bool SetGameObjects_Instance2()
{
  CGameObject* camara_main = gGameObjects["camara_main"];
  camara_main->Camera()->skybox_texture = "skybox2";

  CGameObject* hada1 = gGameObjects.Add("hada1");

  hada1->Transform()->SetScale(0.1f, 0.1f, 0.1f);
  hada1->Transform()->Translate(0.f, 0.f, 10.f);
  hada1->Transform()->Rotate(0.f, 90.f, 0.f);

  hada1->MeshRender()->mesh_name = "mdl_hada1";
  hada1->MeshRender()->material_name = "texture_mdl_hada1";
  hada1->MeshRender()->color(1.0, 0.9f, 0.9f, 1.f);


  // Efecto sencillo de lluvia.
  CGameObject* lluvia = gGameObjects.Add("lluvia");
  lluvia->Transform()->Translate(0.f, 50.f, 0.f);
  lluvia->ParticleEmitter()->direction(0.2f, -1.f, 0.f);
  lluvia->ParticleEmitter()->angle_spread = 360.f;
  lluvia->ParticleEmitter()->max_particles = 6000;
  lluvia->ParticleEmitter()->particles_per_second = 500;
  lluvia->ParticleEmitter()->start_max_life_time = 20.f;
  lluvia->ParticleEmitter()->start_max_life_time = 10.f;
  lluvia->ParticleEmitter()->start_max_scale = 0.1f;
  lluvia->ParticleEmitter()->start_min_scale = 0.05f;
  lluvia->ParticleEmitter()->start_max_vel = lluvia->ParticleEmitter()->start_min_vel = 1.f;
  lluvia->ParticleEmitter()->start_max_base_radius = 50.f;
  lluvia->ParticleEmitter()->start_min_base_radius = 0.f;
  lluvia->ParticleEmitter()->material_name = "raindrop";
  lluvia->ParticleEmitter()->Start();

  gEngine.SetNextInstance("level1");

  return true;
}
コード例 #3
0
ファイル: fireworks.cpp プロジェクト: dreadlocked/go-engine
void Firework_Manager_Input(CGameObject* gameObject)
{
  //if(event.type == SDL_KEYDOWN && event.key.keysym.scancode == SDL_SCANCODE_SPACE)
  vector<GO_InputClasses::CJoystick> joys = gUserInput.GetJoysticks();

  if(pressed and (joys.size() > 0 and joys[0].buttons.size() > 9 and joys[0].buttons[9].State() == Input::button_unpressed))
  {
    pressed = false;
  }
  if(gUserInput.jump() == Input::key_keydown or (joys.size() > 0 and joys[0].buttons.size() > 9 and joys[0].buttons[9].State() == Input::button_pressed and !pressed))
  {
    pressed = true; // joystick

    //std::string random_string = generate_random_alphanumeric_string(5);
    ostringstream oss;
    oss << number_of_fireworks;
    string value = oss.str();

    float timeout = gMath.random(1.f, 3.f);
    gSystem_Data_Storage.SetFloat("firework_timeout_"+value, timeout);
    gSystem_Data_Storage.SetFloat("firework_timer_"+value, gTime.GetTicks_s());

    CGameObject* firework = gGameObjects.Add("firework_"+value);
    CGameObject* explosion = gGameObjects.Add("firework_explosion_"+value);
    CGameObject* trail = gGameObjects.Add("firework_trail_"+value);

    firework->AddChild(explosion);
    firework->AddChild(trail);

    firework->Preserve(true);

    firework->Transform()->position = gMath.random_point(vector3f(50, 0, 0), vector3f(-25, 0, 0));

      // Explosion
    explosion->ParticleEmitter()->material_name = "sprite1";
    explosion->ParticleEmitter()->max_particles = gData.GetInt("firework_explosion_particles");
    explosion->ParticleEmitter()->particles_per_second = 0;
    explosion->ParticleEmitter()->angle_spread = 360;
    explosion->ParticleEmitter()->gravity(0, -5.f, 0);
    explosion->ParticleEmitter()->start_max_life_time = gMath.random(1.5f, 3.f);
    explosion->ParticleEmitter()->start_min_life_time = 1.f;

    GLfloat r = gMath.random(0.5, 1.f);
    GLfloat g = gMath.random(0.5, 1.f);
    GLfloat b = gMath.random(0.5, 1.f);

    explosion->ParticleEmitter()->start_min_color(r, g, b, 1.f);
    explosion->ParticleEmitter()->start_max_color(r, g, b, 1.f);

    r = gMath.random(0.f, 1.f);
    g = gMath.random(0.f, 1.f);
    b = gMath.random(0.f, 1.f);

    explosion->ParticleEmitter()->color_adder(r, g, b, 0.f);
    //explosion->particleEmitter()->color_adder(0, 0, 0, -0.1f);

    explosion->AudioSource()->SetSound("firework_explosion");
    explosion->AudioSource()->volume = 1.f;
    //explosion->AudioSource()->loop = true;
    explosion->AudioSource()->max_distance = 200.f;
    //explosion->AudioSource()->everywhere = false;
    //explosion->AudioSource()->Bind();

      // Trail
    trail->ParticleEmitter()->material_name = "smoke1";
    trail->ParticleEmitter()->max_particles = 500;
    trail->ParticleEmitter()->particles_per_second = 500;
    trail->ParticleEmitter()->angle_spread = 10;
    trail->ParticleEmitter()->direction(0, -1.f, 0);
    trail->ParticleEmitter()->gravity(0, 0.f, 0);

    trail->ParticleEmitter()->start_max_vel = 0.f;
    trail->ParticleEmitter()->start_min_vel = 0.f;

    trail->ParticleEmitter()->start_min_scale = 0.75f;
    trail->ParticleEmitter()->start_max_scale = 1.f;

    trail->ParticleEmitter()->start_min_color(1.f, 0.5f, 0.12f, 0.5f);
    trail->ParticleEmitter()->start_max_color(1.f, 0.5f, 0.12f, 0.8f);
    trail->ParticleEmitter()->min_color(0.12f, 0.12f, 0.12f, 0.f);
    trail->ParticleEmitter()->color_adder(-4.f, -2.f, 0.f, -1.f);

    trail->ParticleEmitter()->start_max_vel = 0.5f;
    trail->ParticleEmitter()->start_min_vel = 0.f;
    trail->ParticleEmitter()->start_max_life_time = 0.05f;
    trail->ParticleEmitter()->start_min_life_time = 0.85f;

    trail->ParticleEmitter()->Start();

    trail->AudioSource()->SetSound("firework_trail");
    trail->AudioSource()->volume = 0.6f;
    trail->AudioSource()->max_distance = 100.f;
    trail->AudioSource()->Bind();
    trail->AudioSource()->Play();

    fireworks_value.push_back(number_of_fireworks);
    exploded.push_back(false);
    fireworks.push_back(firework);
    number_of_fireworks++;

    //exploded.resize(number_of_fireworks);
    //exploded[exploded.size()-1] = false;
    //gGameObjects["camara_main"]->Camera()->SetTarget(firework->GetName());
  }
}
コード例 #4
0
ファイル: CServiceGame.cpp プロジェクト: depuits/Fabian
//-------------------------------------
// 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;
}
コード例 #5
0
ファイル: CServiceGame.cpp プロジェクト: depuits/Fabian
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':
				{
					glm::vec2 dir;
					switch(c)
					{
					case '2':
						dir = glm::vec2(0, 1);
						break;
					case '4':
						dir = glm::vec2(-1, 0);
						break;
					case '6':
						dir = glm::vec2(1, 0);
						break;
					case '8':
						dir = glm::vec2(0, -1);
						break;
					}

					// first add a floor
					AddGridEntity(pGrid, vPos, new Floor(), new CCompModel( m_pContent->LoadMesh("Meshes/floor.obj"),  g_pMatGround ) );

					//then add enemy
					CGameObject *pGo = new CGameObject();
					Entity *pEnt = new Enemy1D(dir);
					pEnt->SetRespawn(vPos);
					pEnt->SetGridPos(vPos);

					pGo->AddComponent( pEnt );
					pGo->AddComponent( new CCompModel( m_pContent->LoadMesh("Meshes/Bug01.obj"),  g_pMatBug01 ) );
					pGo->Transform()->SetScale( 0.5f );
					g_vpGameObjects.push_back(pGo);
					break;
				}

				// Rot enemys
				// CW
			case 's':
			case 'q':
			case 'd':
			case 'z':

			case 'k':
			case 'j':
			case 'l':
			case 'i':
				{
					glm::vec2 dir;
					char rotDir = 0;
					switch(c)
					{
					case 's':
						dir = glm::vec2(0, 1);
						rotDir = EnemyRot::CW;
						break;
					case 'q':
						dir = glm::vec2(-1, 0);
						rotDir = EnemyRot::CW;
						break;
					case 'd':
						dir = glm::vec2(1, 0);
						rotDir = EnemyRot::CW;
						break;
					case 'z':
						dir = glm::vec2(0, -1);
						rotDir = EnemyRot::CW;
						break;

					case 'k':
						dir = glm::vec2(0, 1);
						rotDir = EnemyRot::CCW;
						break;
					case 'j':
						dir = glm::vec2(-1, 0);
						rotDir = EnemyRot::CCW;
						break;
					case 'l':
						dir = glm::vec2(1, 0);
						rotDir = EnemyRot::CCW;
						break;
					case 'i':
						dir = glm::vec2(0, -1);
						rotDir = EnemyRot::CCW;
						break;
					}

					// first add a floor
					AddGridEntity(pGrid, vPos, new Floor(), new CCompModel( m_pContent->LoadMesh("Meshes/floor.obj"),  g_pMatGround ) );

					//then add enemy
					CGameObject *pGo = new CGameObject();
					Entity *pEnt = new EnemyRot(dir, rotDir);
					pEnt->SetRespawn(vPos);
					pEnt->SetGridPos(vPos);

					pGo->AddComponent( pEnt );
					pGo->AddComponent( new CCompModel( m_pContent->LoadMesh("Meshes/car.obj"),  g_pMatDefault ) );
					pGo->Transform()->SetScale( 0.5f );
					g_vpGameObjects.push_back(pGo);
					break;
				}
			}

			//progress when filled
			if ( c != '\n' )
				++vPos.x;
			else
			{
				vPos.x = 0;
				++vPos.y;
			}
		}
	}

	is.close();                // close file
}