Пример #1
0
// Return an angle between kMinProjectileAngularVelocity and
// kMaxProjectileAngularVelocity, in degrees. Returned angle has equal
// probibility of being positive and negative.
mathfu::vec3 PlayerComponent::RandomProjectileAngularVelocity() const {
  const mathfu::vec3 random(mathfu::Random<float>(), mathfu::Random<float>(),
                            mathfu::Random<float>());
  auto angle = mathfu::Lerp(
      LoadVec3(config_->projectile_min_angular_velocity()),
      LoadVec3(config_->projectile_max_angular_velocity()), random);
  const mathfu::vec3 sign(RandomSign(), RandomSign(), RandomSign());
  return angle * sign;
}
Пример #2
0
bool Hi::Load(File* f)
{
  if (!f->GetInteger(&m_score))
  {
    return false;
  }

  if (!f->GetInteger(&m_level))
  {
    return false;
  }

  if (!f->GetInteger(&m_depth))
  {
    return false;
  }

  if (!f->GetDataLine(&m_nick))
  {
    return false;
  }
  m_nick = DecodeStr(m_nick);
  
  if (!LoadVec3(f, &m_pos))
  {
    return false;
  }

  return true;
}
Пример #3
0
void WorldRenderer::CreateShadowMap(const corgi::CameraInterface& camera,
                                    fplbase::Renderer& renderer, World* world) {
  float shadow_map_resolution = static_cast<float>(
        world->config->rendering_config()->shadow_map_resolution());
  float shadow_map_zoom = world->config->rendering_config()->shadow_map_zoom();
  float shadow_map_offset =
      world->config->rendering_config()->shadow_map_offset();
  vec3 light_position =
      LoadVec3(world->config->rendering_config()->light_position());
  SetLightPosition(light_position);
  light_camera_.set_viewport_angle(kShadowMapViewportAngle / shadow_map_zoom);
  light_camera_.set_viewport_resolution(
      vec2(shadow_map_resolution, shadow_map_resolution));
  vec3 light_camera_focus =
      camera.position() + camera.facing() * shadow_map_offset;
  light_camera_focus.z() = 0;
  vec3 light_facing = light_camera_focus - light_camera_.position();
  light_camera_.set_facing(light_facing.Normalized());

  // Shadow map needs to be cleared to near-white, since that's
  // the maximum (furthest) depth.
  shadow_map_.SetAsRenderTarget();
  renderer.ClearFrameBuffer(kShadowMapClearColor);
  renderer.SetCulling(fplbase::Renderer::kCullBack);

  depth_shader_->Set(renderer);
  // Generate the shadow map:
  // TODO - modify this so that shadowcast is its own render pass
  for (int pass = 0; pass < corgi::RenderPass_Count; pass++) {
    world->render_mesh_component.RenderPass(pass, light_camera_,
                                            renderer, depth_shader_);
  }
}
Пример #4
0
bool Block::Load(File* f)
{
  if (!GameObject::Load(f))
  {
    return false;
  }

  // Load position
  if (!LoadVec3(f, &m_pos))
  {
    f->ReportError("Expected block position");
    return false;
  }
//  m_pos = m_pos * m_mat;

  if (!LoadMeshResource(f))
  {
    f->ReportError("Failed to load block mesh");
    return false;
  }

  if (!LoadShadow(f))
  {
    return false;
  }

  return true;
}
Пример #5
0
bool Treasure::Load(File* f)
{
  static int id = TREASURE_START_ID;
  SetId(id++);

  Vec3f pos;
  if (!LoadVec3(f, &pos))
  {
    f->ReportError("Expected position");
    return false;
  }
  SetPos(pos);

  std::string tex;
  if (!f->GetDataLine(&tex))
  {
    f->ReportError("Expected texture filename");
    return false;
  }
  Vec2i cells;
  if (!LoadVec2(f, &cells))
  {
    f->ReportError("Expected num cells Vec2");
    return false;
  }

  if (!f->GetInteger(&m_points))
  {
    f->ReportError("Expected num points");
    return false;
  }

  // Only if player has not collected treasure in the current room
  //  before!
  Player* p = GetLocalPlayer();
  // Create scene node if no local player yet OR player exists and there is no treasure key for this room 
  if (!p || !(p->Exists(MakeTreasureKey())))
  {
    // Size depends on points value
    float size = XSIZE * (float)m_points / 500.0f;
    SpriteNode* sn = new SpriteNode(tex, cells.x, cells.y, size * 0.5f, size * 0.5f);

    SetSceneNode(sn);
    sn->GetSprite()->SetCellRange(0, cells.x * cells.y);
    sn->GetSprite()->SetCell(0);

    m_glow = new SpriteNode("flare.png", 1, 1, size, size);
    sn->AddChild(m_glow.GetPtr());

    File f;
    if (!f.OpenRead("fighteffect.txt"))
    {
      f.ReportError("Failed to load effect");
      Assert(0);
    }
    m_sparkle = new AttackEffect;
    if (!m_sparkle->Load(&f))
    {
      f.ReportError("Failed to load effect");
      Assert(0);
    }
    sn->AddChild(m_sparkle.GetPtr());
  }

  return true;
}
Пример #6
0
void SimpleMovementComponent::AddFromRawData(corgi::EntityRef& entity,
                                             const void* raw_data) {
  auto simple_movement_def = static_cast<const SimpleMovementDef*>(raw_data);
  SimpleMovementData* simple_movement_data = AddEntity(entity);
  simple_movement_data->velocity = LoadVec3(simple_movement_def->velocity());
}
Пример #7
0
bool Baddie::Load(File* f)
{
  static int id = BADDDIE_START_ID;
  SetId(id++);

  Vec3f pos;
  if (!LoadVec3(f, &pos))
  {
    f->ReportError("Expected position");
    return false;
  }
  SetPos(pos);

  std::string tex;
  if (!f->GetDataLine(&tex))
  {
    f->ReportError("Expected texture filename");
    return false;
  }
  Vec2i cells;
  if (!LoadVec2(f, &cells))
  {
    f->ReportError("Expected num cells Vec2");
    return false;
  }
  
  if (!LoadVec2(f, &m_size))
  {
    f->ReportError("Expected size Vec2");
    return false;
  }

  BaddieNode* bn = new BaddieNode(this, tex, cells.x, cells.y, m_size.x * 0.5f, m_size.y * 0.5f);
  // By default we just cycle through all cells
  bn->GetSprite()->SetCellRange(0, cells.x * cells.y);
  SetSceneNode(bn);

  if (!f->GetInteger(&m_damage))
  {
    f->ReportError("Expected damage");
    return false;
  }

  if (!f->GetInteger(&m_maxHealth))
  {
    f->ReportError("Expected max health");
    return false;
  }

  if (m_maxHealth == -1)
  {
    m_maxHealth = 1;
    m_isDestructible = false;
  }

  m_health = m_maxHealth;

  if (!f->GetInteger(&m_points))
  {
    f->ReportError("Expected num points");
    return false;
  }

  if (!f->GetDataLine(&m_attackString))
  {
    f->ReportError("Expected baddie attack string");
    return false;
  }

  std::string bb;
  if (!f->GetDataLine(&bb))
  {
    f->ReportError("Expected baddie behaviour type");
    return false;
  }

  m_bb = TheBBFactory::Instance()->Create(bb);
  
  if (m_bb)
  {
    m_bb->SetBaddie(this);

    if (!m_bb->Load(f))
    {
      f->ReportError("Failed to load baddie behaviour");
      return false;
    }
  }

  /*
  if (!m_shadow->Load(f))
  {
    return false;
  }
  */

  // Particle effect when attacked, etc.
  File fight;
  if (!fight.OpenRead("fighteffect.txt"))
  {
    fight.ReportError("Failed to load effect");
    return false;
  }

  m_effect = new AttackEffect;
  if (!m_effect->Load(&fight))
  {
    fight.ReportError("Failed to load effect");
    return false;
  }
  m_effect->SetVisible(true);

  m_sceneNode->AddChild(m_effect.GetPtr());

  return true;
}