public void Update(float elapsed) { if (ScriptHelper.IsElapsed(m_updateDelay, 250)) { m_updateDelay = Game.TotalElapsedGameTime; var magnetPosition = GetMagnetPosition(); Magnet.SetWorldPosition(magnetPosition); MagnetJoint.SetWorldPosition(magnetPosition); PullJoint.SetForce(InflatedModifier); if (!Player.IsFalling && RandomHelper.Percentage(InflatedModifier)) { ScriptHelper.ExecuteSingleCommand(Player, PlayerCommandType.Fall); } if (m_deflateTimes.Any()) { var deflateInfo = m_deflateTimes.First(); if (Game.TotalElapsedGameTime >= deflateInfo.Key) { Deflate(deflateInfo.Value); m_deflateTimes.RemoveAt(0); } } } var velocity = Player.GetLinearVelocity(); if (Player.IsFalling && !m_oldIsFalling) { m_oldIsFalling = true; m_fallingTime = Game.TotalElapsedGameTime; var velocityDiff = MathExtension.Diff(velocity.Length(), m_oldLinearVelocity.Length()); //ScriptHelper.RunIn(() => Game.DrawText(velocityDiff.ToString(), //Player.GetWorldPosition() + Vector2.UnitY * 15), 1000); if (velocityDiff >= 4) { Player.SetLinearVelocity(velocity + Vector2.Normalize(velocity) * InflatedModifier * 70); } } if (!Player.IsFalling && m_oldIsFalling) { m_oldIsFalling = false; } m_oldLinearVelocity = velocity; }
private void UpdateRotation(float elapsed) { if (HasDamage(TurretDamage.RotorDamaged)) { return; } if (HasDamage(TurretDamage.ControllerDamaged) && ScriptHelper.IsElapsed(m_rndRotationTimeElapsed, m_rndRotationTime)) { m_rndRotationTimeElapsed = Game.TotalElapsedGameTime; m_rndRotationTime = RandomHelper.Between(800, 1500); m_targetAngle = NormalizeAngle(RandomHelper.Between(MinAngle, MaxAngle)); } if (MathExtension.Diff(Angle, m_targetAngle) > MathExtension.OneDeg) { Angle += Math.Sign(m_targetAngle - Angle) * MathExtension.OneDeg * elapsed / 30f; } }
private void CheckIfCollide() { var currentVec = Instance.GetLinearVelocity(); if (currentVec.Length() - m_lastVelocity.Length() <= -6 || MathExtension.Diff(Instance.GetAngle(), m_lastAngle) >= MathExtension.OneDeg * 3 || TotalDistanceTraveled >= 15 && currentVec.Length() <= 1) { TargetedObject = Game.GetObjectsByArea(Instance.GetAABB()) .Where(o => o.UniqueID != Instance.UniqueID && ScriptHelper.IsInteractiveObject(o)) .FirstOrDefault(); if (TargetedObject != null) { m_timeElasped = Game.TotalElapsedGameTime; TargetedPlayer = ScriptHelper.CastPlayer(TargetedObject); if (TargetedPlayer != null) { Instance.SetBodyType(BodyType.Static); m_relPlayerPosition = TargetedPlayer.GetWorldPosition() - Instance.GetWorldPosition(); } else { m_weldJoint = (IObjectWeldJoint)Game.CreateObject("WeldJoint"); m_weldJoint.SetWorldPosition(Instance.GetWorldPosition()); m_weldJoint.SetTargetObjects(new List <IObject>() { Instance, TargetedObject }); } } } m_lastVelocity = currentVec; m_lastAngle = Instance.GetAngle(); }