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;
            }
            public Info(IPlayer player)
            {
                Player = player;
                var magnetPosition = GetMagnetPosition();

                PullJoint   = (IObjectPullJoint)Game.CreateObject("PullJoint");
                Magnet      = Game.CreateObject("InvisibleBlockSmall");
                MagnetJoint = (IObjectTargetObjectJoint)Game.CreateObject("TargetObjectJoint");

                Magnet.SetCollisionFilter(Constants.NoCollision);
                Magnet.SetWorldPosition(magnetPosition);
                MagnetJoint.SetWorldPosition(magnetPosition);
                MagnetJoint.SetTargetObject(Magnet);

                PullJoint.SetWorldPosition(Player.GetWorldPosition());
                PullJoint.SetTargetObject(Player);
                PullJoint.SetTargetObjectJoint(MagnetJoint);
                PullJoint.SetForce(0);
            }
示例#3
0
 public void Attract(MagnetJoint magnet)
 {
     this.magnet = magnet;
 }
 public void Remove()
 {
     PullJoint.Remove();
     MagnetJoint.Remove();
     Magnet.Remove();
 }