Exemple #1
0
 public void Stop()
 {
     _currFrame        = 0;
     _currentAnimation = ContentManager.PlayerAnimation.Idle;
     _frameTime        = 0;
     _currentYVelocity = 0;
     _currentXVelocity = 0;
 }
Exemple #2
0
        public void Update()
        {
            if (_frameTime >= _maxFrameTime)
            {
                if (_currFrame < ContentManager.Instance.PlayerBodyAnimations[_currentAnimation].Length - 1)
                {
                    _currFrame++;
                }
                else
                {
                    _currFrame = 0;
                }

                _frameTime = 0;
            }
            else
            {
                _frameTime++;
            }

            var newPosition = Position;

            newPosition.X += _currentXVelocity;
            newPosition.Y += _currentYVelocity;

            if (newPosition.X != Position.X || newPosition.Y != Position.Y)
            {
                if (newPosition.Y != Position.Y)
                {
                    Rectangle collideRect = Bounds;

                    if (newPosition.Y < Position.Y)
                    {
                        collideRect = new Rectangle((Bounds.X),
                                                    (int)Math.Floor(Bounds.Y + _currentYVelocity), Bounds.Width, Bounds.Height);
                    }
                    else
                    {
                        collideRect = new Rectangle((Bounds.X),
                                                    (int)Math.Ceiling(Bounds.Y + _currentYVelocity), Bounds.Width, Bounds.Height);
                    }

                    if (GameManager.Instance.GameScreen.CanMove(collideRect))
                    {
                        Position.Y = newPosition.Y;
                    }
                    else
                    {
                        _currentYVelocity = 0;
                    }
                }

                if (newPosition.X != Position.X)
                {
                    Rectangle collideRect = Bounds;

                    if (newPosition.X < Position.X)
                    {
                        collideRect = new Rectangle((int)Math.Floor(Bounds.X + _currentXVelocity),
                                                    (int)(Bounds.Y), Bounds.Width, Bounds.Height);
                    }
                    else
                    {
                        collideRect = new Rectangle((int)Math.Ceiling(Bounds.X + _currentXVelocity),
                                                    (int)(Bounds.Y), Bounds.Width, Bounds.Height);
                    }

                    if (GameManager.Instance.GameScreen.CanMove(collideRect))
                    {
                        Position.X = newPosition.X;
                    }
                    else
                    {
                        _currentXVelocity = 0;
                    }
                }
            }

            _currentXVelocity *= _friction;
            _currentYVelocity *= _friction;

            if (Math.Abs(_currentXVelocity) < .3f || GameManager.Instance.UsingObject != null)
            {
                _currentXVelocity = 0;
            }

            if (Math.Abs(_currentYVelocity) < 0.3f || GameManager.Instance.UsingObject != null)
            {
                _currentYVelocity = 0;
            }

            if (_currentXVelocity != 0 || _currentYVelocity != 0)
            {
                if (_currentAnimation != ContentManager.PlayerAnimation.Walk)
                {
                    _currentAnimation = ContentManager.PlayerAnimation.Walk;
                    _currFrame        = 0;
                    _frameTime        = 0;
                }
            }
            else
            {
                if (_currentAnimation != ContentManager.PlayerAnimation.Idle)
                {
                    _currFrame        = 0;
                    _frameTime        = 0;
                    _currentAnimation = ContentManager.PlayerAnimation.Idle;
                }
            }

            if (GameManager.Instance.UsingObject == null)
            {
                CheckMovement();
            }

            StatUpdate();
        }