void Parachute::StartShooting() { if (open) { img->Finish(); open = false; closing = false; UseAmmoUnit(); } else { Weapon::StartShooting(); } }
void PolecatLauncher::Refresh() { WeaponLauncher::Refresh(); if (current_polecat) return; if (polecat_death_time && polecat_death_time + 2000 < GameTime::GetInstance()->Read()) { UseAmmoUnit(); polecat_death_time = 0; } }
void TuxLauncher::Refresh() { if (current_tux) { const LRMoveIntention * lr_move_intention = ActiveCharacter().GetLastLRMoveIntention(); if (lr_move_intention) { if (lr_move_intention->GetDirection() == DIRECTION_LEFT) current_tux->turn_left(); else current_tux->turn_right(); } } else { if (tux_death_time && tux_death_time + 2000 < GameTime::GetInstance()->Read()) { UseAmmoUnit(); tux_death_time = 0; } } }
bool Weapon::Shoot() { MSG_DEBUG("weapon.shoot", "Enough ammo ? %d", EnoughAmmo()); MSG_DEBUG("weapon.shoot", "Enough ammo unit ? %d", EnoughAmmoUnit()); MSG_DEBUG("weapon.shoot", "Use unit on 1st shoot ? %d", use_unit_on_first_shoot); if (!IsReady()) return false; MSG_DEBUG("weapon.shoot", "Enough ammo"); #ifdef DEBUG Point2i hand; ActiveCharacter().GetHandPosition(hand); MSG_DEBUG("weapon.shoot", "%s Shooting at position:%d,%d (hand: %d,%d)", ActiveCharacter().GetName().c_str(), ActiveCharacter().GetX(), ActiveCharacter().GetY(), hand.GetX(), hand.GetY()); ActiveCharacter().body->DebugState(); #endif if (!p_Shoot()) { MSG_DEBUG("weapon.shoot", "shoot has failed!!"); return false; } m_last_fire_time = Time::GetInstance()->Read(); MSG_DEBUG("weapon.shoot", "shoot!"); // Is this the first shoot for this ammo use ? if (ActiveTeam().ReadNbUnits() == m_initial_nb_unit_per_ammo) { UseAmmo(); } if (use_unit_on_first_shoot){ UseAmmoUnit(); } if (max_strength.IsNotZero()) ActiveCharacter().previous_strength = m_strength; Game::GetInstance()->SetCharacterChosen(true); return true; }
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; } } } } }
void Parachute::Refresh() { if (Game::GetInstance()->GetRemainingTime() <= 0) return; if (Game::GetInstance()->ReadState() != Game::PLAYING) return; Character& active = ActiveCharacter(); Double speed = active.GetSpeedXY().Norm(); if (active.FootsInVacuum() && speed.IsNotZero()) { // We are falling if (!open && (speed > GameMode::GetInstance()->safe_fall)) { // with a sufficient speed if (EnoughAmmo() && !m_used_this_turn) { // We have enough ammo => start opening the parachute if (!m_used_this_turn) { UseAmmo(); m_used_this_turn = true; } active.SetAirResistFactor(cfg().air_resist_factor); active.SetWindFactor(cfg().wind_factor); open = true; img->animation.SetPlayBackward(false); img->Start(); active.SetSpeedXY(Point2d(0,0)); active.SetMovement("parachute"); Camera::GetInstance()->FollowObject(&active); } } } else { // We are on the ground if (open) { // The parachute is opened active.SetMovement("walk"); if (!closing) { // We have just hit the ground. Start closing animation img->animation.SetPlayBackward(true); img->animation.SetShowOnFinish(SpriteAnimation::show_blank); img->Start(); closing = true; return; } else { // The parachute is closing if (img->IsFinished()) { // The animation is finished... We are done with the parachute open = false; closing = false; UseAmmoUnit(); } } } m_used_this_turn = false; } if (open) { active.UpdateLastMovingTime(); // If parachute is open => character can move a little to the left or to the right const LRMoveIntention * lr_move_intention = active.GetLastLRMoveIntention(); if (lr_move_intention) { LRDirection direction = lr_move_intention->GetDirection(); active.SetDirection(direction); if (direction == DIRECTION_LEFT) active.SetExternForce(-cfg().force_side_displacement, 0.0); else active.SetExternForce(cfg().force_side_displacement, 0.0); } } }