Example #1
0
        public override void Update(float delta)
        {
#if !EDITOR
            if (Player.Instance.PlayerState != PlayerState.Dead)
            {
                #region Disallow grabbing under certain conditions

                UpIs upIs = Camera.Instance.GetUpIs();

                if (_orientation == Direction.Vertical && (upIs == UpIs.Left || upIs == UpIs.Right))
                {
                    return;
                }
                else if (_orientation == Direction.Horizontal && (upIs == UpIs.Up || upIs == UpIs.Down))
                {
                    return;
                }

                #endregion

                if (_inRange)
                {
                    if (!_grabbed)
                    {
                        if (InputManager.Instance.Grab(true) || InputManager.Instance.MoveUp(false) || InputManager.Instance.MoveDown(false))
                        {
                            ConnectPlayer();
                        }
                    }
                    else
                    {
                        if (InputManager.Instance.Grab(true))
                        {
                            DisconnectPlayer();
                        }
                    }
                }
            }
            else
            {
                if (_grabbed)
                {
                    DisconnectPlayer();
                }
            }

            //  Just a quick error grab.
            if (_grabbed && Player.Instance.PlayerState != PlayerState.Climbing)
            {
                DisconnectPlayer();
            }
#endif
        }
Example #2
0
        protected override bool Body_OnCollision(Fixture fixtureA, Fixture fixtureB, Contact contact)
        {
            //  We only care for fixtureB if it's part of the player.
            if (Player.Instance.CheckBodyBox(fixtureB))
            {
                //  Check if the touching list contains B.
                if (!_touchingFixtures.Contains(fixtureB))
                {
                    _touchingFixtures.Add(fixtureB);

                    #region World-Door Orientation Check

                    UpIs upIs = Camera.Instance.GetUpIs();

                    if (!_triggered)
                    {
                        if (upIs == UpIs.Up &&
                            _orientation == Orientation.Up)
                        {
                            ChangeTriggered(true);
                        }
                        else if (upIs == UpIs.Down &&
                                 _orientation == Orientation.Down)
                        {
                            ChangeTriggered(true);
                        }
                        else if (upIs == UpIs.Left &&
                                 _orientation == Orientation.Right)
                        {
                            ChangeTriggered(true);
                        }
                        else if (upIs == UpIs.Right &&
                                 _orientation == Orientation.Left)
                        {
                            ChangeTriggered(true);
                        }
                    }
                    #endregion
                }

                //  FixtureB was the player and it's been acted on.
                return(true);
            }

            //  It wasn't the player, so ignore it.
            return(false);
        }
        /// <summary>
        /// Change the presolve for the world so that it can understand when a collision
        /// should occur ahead of time for one sided platforms.
        /// </summary>
        /// <param name="contact"></param>
        /// <param name="oldManifold"></param>
        protected void PreSolve(Contact contact, ref Manifold oldManifold)
        {
#if EDITOR
#else
            //  Get both collision bodies.
            Fixture fixtureA = contact.FixtureA;    //  A = Surface
            Fixture fixtureB = contact.FixtureB;    //  B = Player

            if (fixtureA == this.Body.FixtureList[0] || fixtureB == this.Body.FixtureList[0])
            {
                Player instance = Player.Instance;

                //  We only want a contact with the player
                //  As it's not the player, disable the contact
                contact.Enabled = false;

                if (instance.PlayerState == PlayerState.Climbing)
                {
                    return;
                }

                if (instance.CheckWheelFixture(fixtureB))
                {
                    UpIs upIs = Camera.Instance.GetUpIs();

                    //  If the centre of the player wheel is above (depending on the orientation
                    //  and the world rotation) to the top point (1/2 w/h depending on ^) and the
                    //  radius of the wheel + a small bounding number.
                    switch (_orientation)
                    {
                    case Orientation.Up:
                        if (instance.GetWheelBody().Position.Y < top - radius * Settings.LinearSlop)
                        {
                            if (_orientationDependant)
                            {
                                if (upIs == UpIs.Up)
                                {
                                    contact.Enabled = true;
                                }
                            }
                            else
                            {
                                contact.Enabled = true;
                            }
                        }
                        break;

                    case Orientation.Down:
                        if (instance.GetWheelBody().Position.Y > top - radius * Settings.LinearSlop)
                        {
                            if (_orientationDependant)
                            {
                                if (upIs == UpIs.Down)
                                {
                                    contact.Enabled = true;
                                }
                            }
                            else
                            {
                                contact.Enabled = true;
                            }

                            contact.Enabled = true;
                        }
                        break;

                    case Orientation.Left:
                        if (instance.GetWheelBody().Position.X > top - radius * Settings.LinearSlop)
                        {
                            if (_orientationDependant)
                            {
                                if (upIs == UpIs.Left)
                                {
                                    contact.Enabled = true;
                                }
                            }
                            else
                            {
                                contact.Enabled = true;
                            }

                            contact.Enabled = true;
                        }
                        break;

                    case Orientation.Right:
                        if (instance.GetWheelBody().Position.X < top + radius * Settings.LinearSlop)
                        {
                            if (_orientationDependant)
                            {
                                if (upIs == UpIs.Right)
                                {
                                    contact.Enabled = true;
                                }
                            }
                            else
                            {
                                contact.Enabled = true;
                            }

                            contact.Enabled = true;
                        }
                        break;
                    }
                }
            }
#endif
        }
Example #4
0
        void HandleAir(float delta)
        {
            Vector2 bodyPos  = ConvertUnits.ToDisplayUnits(_mainBody.Position);
            float   distance = SpinAssist.ModifyVectorByUp(bodyPos - _lastSafePosition).Y;

            if (_inAir && (Math.Abs(distance) > 550) && !_deadlyFall)
            {
                _deadlyFall = true;
                AudioManager.Instance.PlayCue("Harland_Falling", true);
            }

            if (_playerState != Characters.PlayerState.Falling)
            {
                if (CurrentAnimation.Completed)
                {
                    this.PlayerState = PlayerState.Falling;
                }
            }

            if (InputManager.Instance.MoveLeft(false))
            {
                UpIs  upIs       = Camera.Instance.GetUpIs();
                float speedLimit = 25;

                this._wheelBody.ApplyForce(SpinAssist.ModifyVectorByUp(new Vector2(-_midAirForce, 0)));

                if (upIs == UpIs.Up || upIs == UpIs.Down)
                {
                    this._wheelBody.LinearVelocity = new Vector2(
                        MathHelper.Clamp(_wheelBody.LinearVelocity.X, -speedLimit, speedLimit),
                        _wheelBody.LinearVelocity.Y);
                }
                else
                {
                    this._wheelBody.LinearVelocity = new Vector2(
                        _wheelBody.LinearVelocity.X,
                        MathHelper.Clamp(_wheelBody.LinearVelocity.Y, -speedLimit, speedLimit));
                }

                this._lookingDirection = SpriteEffects.FlipHorizontally;
            }
            else if (InputManager.Instance.MoveRight(false))
            {
                UpIs  upIs       = Camera.Instance.GetUpIs();
                float speedLimit = 25;

                this._wheelBody.ApplyForce(SpinAssist.ModifyVectorByUp(new Vector2(_midAirForce, 0)));

                if (upIs == UpIs.Up || upIs == UpIs.Down)
                {
                    this._wheelBody.LinearVelocity = new Vector2(
                        MathHelper.Clamp(_wheelBody.LinearVelocity.X, -speedLimit, speedLimit),
                        _wheelBody.LinearVelocity.Y);
                }
                else
                {
                    this._wheelBody.LinearVelocity = new Vector2(
                        _wheelBody.LinearVelocity.X,
                        MathHelper.Clamp(_wheelBody.LinearVelocity.Y, -speedLimit, speedLimit));
                }

                this._lookingDirection = SpriteEffects.None;
            }
        }
Example #5
0
 public void SetUpIs(UpIs val)
 {
     this._upIs = val;
     this.changeGravity();
 }