Exemplo n.º 1
0
        public override void HandleCollisionWithObject(Vector2 currentObjectOffset, CollisionBox collidingBox, GameObject otherObject,
                                                       Vector2 otherObjectOffset, CollisionBox otherCollidingBox)
        {
            _rebounded = false; // don't know if we need this here

            if (otherObject is TerrainObject)
            {
                var somethingNew = false;

                var directions = collidingBox.GetCollisionDirections(currentObjectOffset, otherCollidingBox, otherObjectOffset);
                var onTheFloor = false;

                var reboundDistance = otherCollidingBox.ReboundInShallowest(otherObjectOffset, collidingBox, currentObjectOffset);

                _totalReboundDistance += reboundDistance;
                _position             += reboundDistance;
                _rebounded             = true;

                if (directions.Contains(Directions.Up))
                {
                    _velocityPerFrame.Y = 0;
                }
                else if (directions.Contains(Directions.Down))
                {
                    _velocityPerFrame.Y = 0;
                    onTheFloor          = true;

                    if (_state == CharacterStates.Jump)
                    {
                        somethingNew = true;
                        ExecuteLand();
                    }

                    if (_velocityPerFrame.X != 0)
                    {
                        DecayXVelocity(((TerrainObject)otherObject).Friction);
                    }
                    else
                    if (_state != CharacterStates.Recoil && _okStand && _state != CharacterStates.Attack)     // this isn't going to work but just do this for now
                    {
                        // need to find some good way to get to stand without relying on velocity magnitude
                        _state = CharacterStates.Stand;
                        SetStandingAnimation();
                    }
                }

                if (directions.Contains(Directions.Left))
                {
                    _velocityPerFrame.X = 0;

                    if (onTheFloor)
                    {
                        if (_state == CharacterStates.Walk)
                        {
                            somethingNew = true;
                            BeginPush(Directions.Left);
                        }
                    }
                }
                else if (directions.Contains(Directions.Right))
                {
                    _velocityPerFrame.X = 0;

                    if (onTheFloor)
                    {
                        if (_state == CharacterStates.Walk)
                        {
                            somethingNew = true;
                            BeginPush(Directions.Right);
                        }
                    }
                }

                if (!somethingNew)
                {
                    ContinueCurrentExecution();
                }
            }
        }