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


C++ CGameObject::AddChild方法代码示例

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


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

示例1: Firework_Manager_Input

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++;

//.........这里部分代码省略.........
开发者ID:dreadlocked,项目名称:go-engine,代码行数:101,代码来源:fireworks.cpp


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