Exemplo n.º 1
0
void Grapple::DetachNode()
{
  ASSERT(rope_nodes.size() >= 1);

#ifdef DEBUG
  { // for debugging only
    rope_node_t node;
    node = rope_nodes.back();
    MSG_DEBUG("grapple.node", "- %d,%d %s", node.pos.x, node.pos.y, Double2str(node.angle).c_str());
  }
#endif

  // remove last node
  rope_nodes.pop_back();

  m_fixation_point = rope_nodes.back().pos ;

  Point2i pos;
  ActiveCharacter().GetRelativeHandPosition(pos);

  ActiveCharacter().SetPhysFixationPointXY(m_fixation_point.x * METER_PER_PIXEL,
                                           m_fixation_point.y * METER_PER_PIXEL,
                                           pos.x * METER_PER_PIXEL,
                                           pos.y * METER_PER_PIXEL);
}
Exemplo n.º 2
0
void LowGrav::p_Deselect()
{
  use.Stop();
  ActiveCharacter().ResetConstants();
  ActiveCharacter().SetClothe("normal");
  ActiveCharacter().SetMovement("breathe");
  active = false;
}
Exemplo n.º 3
0
void Weapon::Deselect()
{
  ActiveTeam().crosshair.SetActive(false);
  ActiveCharacter().SetFiringAngle(0);
  ActiveCharacter().SetMovement("breathe");
  MSG_DEBUG("weapon.change", "Deselect %s", m_name.c_str());
  p_Deselect();
}
Exemplo n.º 4
0
bool LowGrav::p_Shoot()
{
  ActiveCharacter().SetGravityFactor(LOW_GRAVITY_FACTOR);
  ActiveCharacter().SetClothe("helmet");
  use.Play("default","weapon/lowgrav",-1);
  active = true;
  return true;
}
Exemplo n.º 5
0
void JetPack::p_Deselect()
{
  active = false;
  ActiveCharacter().SetExternForceXY(Point2d());
  StopFlying();
  ActiveCharacter().SetClothe("normal");
  ActiveCharacter().SetMovement("breathe");
}
Exemplo n.º 6
0
void Weapon::PrepareShoot()
{
  MSG_DEBUG("weapon.shoot", "Try to shoot with strength:%f, angle:%f",
            Double2str(m_strength).c_str(), Double2str(ActiveCharacter().GetFiringAngle()).c_str());
  StopLoading();

  ActiveCharacter().PrepareShoot();
  MSG_DEBUG("weapon.shoot", "End of shoot");
}
Exemplo n.º 7
0
void Grapple::Draw()
{
  int x, y;
  Double angle, prev_angle;
  Point2i handPos;

  struct CL_Quad {Sint16 x1,x2,x3,x4,y1,y2,y3,y4;} quad;

  Weapon::Draw();

  if (!attached) {
    return;
  }

  angle = ActiveCharacter().GetRopeAngle();
  prev_angle = angle;

  // Draw the rope.
  ActiveCharacter().GetHandPosition(handPos);
  x = handPos.x;
  y = handPos.y;

  quad.x1 = (int)round((Double)x - 2 * cos(angle));
  quad.y1 = (int)round((Double)y + 2 * sin(angle));
  quad.x2 = (int)round((Double)x + 2 * cos(angle));
  quad.y2 = (int)round((Double)y - 2 * sin(angle));

  for (std::list<rope_node_t>::reverse_iterator it = rope_nodes.rbegin();
       it != rope_nodes.rend(); it++)
    {
      quad.x3 = (int)round((Double)it->pos.x + 2 * cos(angle));
      quad.y3 = (int)round((Double)it->pos.y - 2 * sin(angle));
      quad.x4 = (int)round((Double)it->pos.x - 2 * cos(angle));
      quad.y4 = (int)round((Double)it->pos.y + 2 * sin(angle));

      Double dx = sin(angle) * (Double)m_node_sprite->GetHeight();
      Double dy = cos(angle) * (Double)m_node_sprite->GetHeight();
      int step = 0;
      int size = (quad.x1-quad.x4) * (quad.x1-quad.x4)
                +(quad.y1-quad.y4) * (quad.y1-quad.y4);
      size -= m_node_sprite->GetHeight();
      while( (step*dx*step*dx)+(step*dy*step*dy) < size ) {
  m_node_sprite->Draw(Point2i(quad.x4 + (int)((Double) step * dx),
            quad.y4 + (int)((Double) step * dy)));
        step++;
      }
      quad.x1 = quad.x4 ;
      quad.y1 = quad.y4 ;
      quad.x2 = quad.x3 ;
      quad.y2 = quad.y3 ;
      prev_angle = angle;
      angle = it->angle ;
    }

  m_hook_sprite->SetRotation_rad(-prev_angle);
  m_hook_sprite->Draw( rope_nodes.front().pos - m_hook_sprite->GetSize()/2);
}
Exemplo n.º 8
0
void Grapple::GoLeft()
{
  if (!go_left) {
    cable_sound.Play("default", "weapon/grapple_cable");
  }
  go_left = true ;
  ActiveCharacter().SetExternForce(-cfg().push_force,0);
  ActiveCharacter().SetDirection(DIRECTION_LEFT);
  ActiveCharacter().UpdatePosition() ;
}
Exemplo n.º 9
0
void Grapple::PrintDebugRope()
{
  std::cout << ActiveCharacter().GetX() << " " << ActiveCharacter().GetY() << " " << ActiveCharacter().GetRopeAngle() << std::endl;

  for (std::list<rope_node_t>::iterator it = rope_nodes.begin();
       it != rope_nodes.end();
       it++) {

    std::cout << it->pos.x << " " << it->pos.y << " " << it->angle << std::endl;
  }
}
Exemplo n.º 10
0
void Grapple::GoUp()
{
  if(Time::GetInstance()->Read()<last_mvt+DT_MVT)
    return;
  last_mvt = Time::GetInstance()->Read();

  delta_len = -0.1 ;
  ActiveCharacter().ChangePhysRopeSize (delta_len);
  ActiveCharacter().UpdatePosition();
  delta_len = 0 ;
}
Exemplo n.º 11
0
void Suicide::Refresh()
{
  // The suicide sound may play at different speed for different players,
  // that's why the explosion should not depend on the fact if the sound has finished playing or not.
  uint time_since_last_fire = Time::GetInstance()->Read() - m_last_fire_time;
  Character *player = &ActiveCharacter();
  if (m_last_fire_time > 0 && time_since_last_fire > SUICIDE_SOUND_DURATION_IN_MS && !player->IsDead()) {
    player->DisableDeathExplosion();
    player->body->MakeParticles(ActiveCharacter().GetPosition());
    player->SetEnergy(0, player); // Die!
    ApplyExplosion(player->GetCenter(), cfg());
  }
}
Exemplo n.º 12
0
void Grapple::GoDown()
{
  if(Time::GetInstance()->Read()<last_mvt+DT_MVT)
    return;
  last_mvt = Time::GetInstance()->Read();

  if (ActiveCharacter().GetRopeLength()*PIXEL_PER_METER >= (int)cfg().max_rope_length)
    return;

  delta_len = 0.1 ;
  ActiveCharacter().ChangePhysRopeSize (delta_len) ;
  ActiveCharacter().UpdatePosition() ;
  delta_len = 0 ;
}
Exemplo n.º 13
0
void Mine::Add(int x, int y)
{
  projectile->SetXY(Point2i(x, y));
  projectile->SetOverlappingObject(&ActiveCharacter());

  // add the character speed
  if(ActiveCharacter().GetDirection() == 1)
    projectile->SetSpeed(1.0, -QUARTER_PI);
  else
    projectile->SetSpeed(1.0, -THREE * QUARTER_PI);

  ObjectsList::GetRef().AddObject (projectile);
  projectile = NULL;
  ReloadLauncher();
}
Exemplo n.º 14
0
void Plane::Shoot(Double speed, const Point2i& target)
{
  MSG_DEBUG("weapon.shoot", "Plane Shoot");
  nb_dropped_bombs = 0;
  last_dropped_bomb = NULL;

  cible_x = target.x;
  SetY(0);
  distance_to_release = (int)(speed * sqrt(TWO * (GetY() + target.y)));

  Point2d speed_vector;
  if (ActiveCharacter().GetDirection() == DIRECTION_RIGHT) {
    image->SetFlipped(false);
    speed_vector.SetValues(speed, 0);
    SetX(ONE - Double(image->GetWidth()));
    //distance_to_release -= obus_dx;
   if (distance_to_release > cible_x)
     distance_to_release = 0;

  } else {
    image->SetFlipped(true);
    speed_vector.SetValues(-speed, 0) ;
    SetX(Double(GetWorld().GetWidth() - 1));
    //distance_to_release += obus_dx;
    if (distance_to_release > GetWorld().GetWidth()-cible_x - obus_dx)
      distance_to_release = 0;
  }

  SetSpeedXY(speed_vector);

  Camera::GetInstance()->FollowObject(this);

  ObjectsList::GetRef().AddObject(this);
}
Exemplo n.º 15
0
//-----------------------------------------------------------------------------
void Airhammer::p_Deselect()
{
  drill_sound.Stop();
  select_sound.Stop();
  ActiveCharacter().SetMovement("breathe");
  active = false;
}
Exemplo n.º 16
0
void Grapple::NotifyMove(bool collision)
{
  bool addNode = false;

  if (!attached)
    return;

  // Check if the character collide something.
  if (collision) {
      // Yes there has been a collision.
    if (delta_len.IsNotZero()) {
      // The character tryed to change the rope size.
      // There has been a collision, so we cancel the rope length change.
      ActiveCharacter().ChangePhysRopeSize (-delta_len);
      delta_len = 0;
    }
    return;
  }


  // While there is nodes to add, we add !
  while (TryAddNode())
    addNode = true;

  // If we have created nodes, we exit to avoid breaking what we
  // have just done !
  if (addNode)
    return;

  TryRemoveNodes();
}
Exemplo n.º 17
0
const Point2i Weapon::GetGunHolePosition() const
{
  Point2i pos;
  ActiveCharacter().GetHandPosition(pos);
  Point2i hole(pos + hole_delta * Point2i(ActiveCharacter().GetDirection(),1));
  Double dst = pos.Distance(hole);
  Double angle = pos.ComputeAngle(hole);

  if (ActiveCharacter().GetDirection() == DIRECTION_RIGHT)
    angle += ActiveCharacter().GetFiringAngle();
  else
    angle += ActiveCharacter().GetFiringAngle() - PI;

  return pos + Point2i(static_cast<int>(dst * cos(angle)),
                       static_cast<int>(dst * sin(angle)));
}
Exemplo n.º 18
0
void Grapple::TryRemoveNodes()
{
  std::list<rope_node_t>::reverse_iterator nodeit;

  int lg;
  Point2d V;
  Point2i handPos, contact_point;
  Double angle;

  ActiveCharacter().GetHandPosition(handPos);

  while (rope_nodes.size() > 1) {

    nodeit = rope_nodes.rbegin();
    ++nodeit;

    V.x = handPos.x - nodeit->pos.x;
    V.y = handPos.y - nodeit->pos.y;
    angle = V.ComputeAngle();
    lg = static_cast<int>(V.Norm());

    if (find_first_contact_point(nodeit->pos, angle, lg, SKIP_DST, contact_point))
      break;

    DetachNode();
  }
}
Exemplo n.º 19
0
void Weapon::StartShooting()
{
  if (ActiveCharacter().IsPreparingShoot())
    return;

  if (max_strength.IsNotZero() && IsReady())
    InitLoading();
}
Exemplo n.º 20
0
void Parachute::p_Deselect()
{
  Character &a = ActiveCharacter();
  // Fix for excessive damage being applied, as done for jetpack
  a.SetExternForceXY(Point2d());
  a.ResetConstants();
  a.SetMovement("breathe");
}
Exemplo n.º 21
0
bool Airhammer::p_Shoot()
{
  // initiate movement ;-)
  ActiveCharacter().SetRebounding(false);

  Point2i pos = Point2i(ActiveCharacter().GetX() + ActiveCharacter().GetWidth()/2 - impact.GetWidth()/2,
                        ActiveCharacter().GetTestRect().GetPositionY() +
                        ActiveCharacter().GetHeight()  -16);

  ParticleEngine::AddNow(pos + Point2i(impact.GetWidth()/4,9), 1, particle_AIR_HAMMER,
                         true, -THREE * QUARTER_PI, 5.0 + GameTime::GetInstance()->Read() % 5);
  ParticleEngine::AddNow(pos + Point2i(3*impact.GetWidth()/4,9), 1, particle_AIR_HAMMER,
                         true, -QUARTER_PI, 5.0 + GameTime::GetInstance()->Read() % 5);
  GetWorld().Dig(pos, impact);

  return true;
}
Exemplo n.º 22
0
void Grapple::DetachRope()
{
  ActiveCharacter().UnsetPhysFixationPoint();
  rope_nodes.clear();
  attached = false;

  cable_sound.Stop();
}
Exemplo n.º 23
0
bool Blowtorch::p_Shoot()
{
  Point2i hole = ActiveCharacter().GetCenter();

  Double angle = ActiveCharacter().GetFiringAngle();
  uint h = cfg().range;
  Double dx = cos(angle) * h;
  Double dy = sin(angle) * h;

  Point2i pos = Point2i(hole.x+(int)dx, hole.y+(int)dy);
  int char_height = ActiveCharacter().GetHeight();
  int char_width  = ActiveCharacter().GetWidth();
  int size = ((int)sqrt(Double(char_height * char_height + char_width * char_width)))/2;
  GetWorld().Dig(pos, size);
  JukeBox::GetInstance()->Play("default", "weapon/blowtorch");

  return true;
}
Exemplo n.º 24
0
void JetPack::StopFlying()
{
  if (!m_flying)
    return;

  ActiveCharacter().SetMovement("jetpack-nofire");
  flying_sound.Stop();
  m_flying = false;
}
Exemplo n.º 25
0
void WeaponMember::Draw(const Point2i & /*_pos*/,
                        int /*flip_center*/,
                        LRDirection /*direction*/)
{
  if (!ActiveCharacter().IsDead() && Game::END_TURN != Game::GetInstance()->ReadState()) {
    ActiveTeam().crosshair.Draw();
    ActiveTeam().AccessWeapon().Draw();
  }
}
Exemplo n.º 26
0
void Grapple::StopLeft()
{
  go_left = false ;

  if (go_left || go_right)
    return ;

  ActiveCharacter().SetExternForce(0,0);
}
Exemplo n.º 27
0
void JetPack::Refresh()
{
  if (active) {
    Point2d F(0.0, 0.0);
    const UDMoveIntention * ud_move_intention = ActiveCharacter().GetLastUDMoveIntention();
    if (ud_move_intention && ud_move_intention->GetDirection() == DIRECTION_UP) {
      F.y = -(ActiveCharacter().GetMass() * GameMode::GetInstance()->gravity + JETPACK_FORCE);
    }
    const LRMoveIntention * lr_move_intention = ActiveCharacter().GetLastLRMoveIntention();
    if (lr_move_intention && IsInAir()) {
      LRDirection direction = lr_move_intention->GetDirection();
      if (direction == DIRECTION_LEFT)
        F.x = -JETPACK_FORCE;
      else
        F.x = JETPACK_FORCE;
      ActiveCharacter().SetDirection(direction);
    }

    if (F.IsNull() && m_flying)
      StopFlying();
    else if (!F.IsNull() && !m_flying)
      StartFlying();

    ActiveCharacter().SetExternForceXY(F);

    if (!F.IsNull()) {
      // We are using fuel !!!
      uint current = GameTime::GetInstance()->Read() ;
      int64_t delta = current - m_last_fuel_down;

      while (delta >= DELTA_FUEL_DOWN) {
        if (EnoughAmmoUnit()) {
          UseAmmoUnit();
          m_last_fuel_down += DELTA_FUEL_DOWN ;
          delta -= DELTA_FUEL_DOWN ;
        } else {
          p_Deselect();
          break;
        }
      }

    }
  }
}
Exemplo n.º 28
0
bool Baseball::p_Shoot()
{

  Double angle = ActiveCharacter().GetFiringAngle();
  Double rayon = 0.0;
  bool end = false;

  JukeBox::GetInstance()->Play ("default","weapon/baseball");

  do
  {
    // Did we have finished the computation
    rayon += ONE;
    if (cfg().range < rayon)
    {
      rayon = cfg().range;
      end = true;
    }

    // Compute point coordinates
    Point2i relative_pos(static_cast<int>(rayon * cos(angle)),
                         static_cast<int>(rayon * sin(angle)) );

    Point2i hand_position;
    ActiveCharacter().GetHandPosition(hand_position);
    Point2i pos_to_check = hand_position + relative_pos;

    FOR_ALL_LIVING_CHARACTERS(team, character)
    if (&(*character) != &ActiveCharacter())
    {
      // Did we touch somebody ?
      if( character->Contain(pos_to_check) )
      {
        // Apply damage (*ver).SetEnergyDelta (-cfg().damage);
        character->SetSpeed(cfg().strength / character->GetMass(), angle);
        character->SetMovement("fly");
        Camera::GetInstance()->FollowObject(&(*character));
        return true;
      }
    }
  } while (!end);

  return true;
}
Exemplo n.º 29
0
bool Syringe::p_Shoot ()
{
  Double angle = ActiveCharacter().GetFiringAngle();
  Double radius = 0.0;
  bool end = false;

  JukeBox::GetInstance()->Play ("default","weapon/syringe_shoot");

  Character* player = &ActiveCharacter();
  do {
    // Did we have finished the computation
    radius += ONE;
    if (cfg().range < radius) {
      radius = cfg().range;
      end = true;
    }

    // Compute point coordinates
    Point2i relative_pos(static_cast<int>(radius * cos(angle)),
                         static_cast<int>(radius * sin(angle)) );
    Point2i hand_position;
    ActiveCharacter().GetHandPosition(hand_position);
    Point2i pos_to_check = hand_position + relative_pos;

    FOR_ALL_LIVING_CHARACTERS(team, character) {
      if (&(*character) != player) {
        // Did we touch somebody ?
        if (character->Contain(pos_to_check)) {
          // Apply damage (*ver).SetEnergyDelta (-cfg().damage);
          if (!player->GetTeam().IsSameAs(character->GetTeam()) || !player->IsDiseased())
            character->SetDiseaseDamage(player, cfg().damage, cfg().turns);
          else {
            // The syringe can cure if applied to a teammate!
            character->Cure();
          }
          end = true;
        }
      }
    }
  } while (!end);

  return true;
}
Exemplo n.º 30
0
void Weapon::StopShooting()
{
  if (max_strength.IsNotZero() && !IsLoading())
    /* User has probably exceed the max_strength */
    return;

  if (!ActiveCharacter().IsPreparingShoot()) {
    PrepareShoot();
  }
}