Пример #1
0
        public void Update(GameTime gameTime, CollisionLayer collisionLayer)
        {
            base.Update(gameTime);

            if (Destination != Vector2.Zero.MinValue())
            {
                var dirX = Destination.X > Position.X ? 1 : -1;
                var dirY = Destination.Y > Position.Y ? 1 : -1;

                if (Vector2.Distance(Position, Destination) > Speed)
                {
                    var velocity = Vector2.Subtract(Destination, Position);
                    velocity.Normalize();

                    var vector           = velocity * Speed;
                    var originalPosition = Position;
                    Position += vector;
                    Position  = new Vector2((int)Position.X, (int)Position.Y);

                    while (collisionLayer.Intersects(GroundBounds))
                    {
                        Position -= vector;
                        Position  = new Vector2((int)Position.X, (int)Position.Y);
                        if (Position.X > ArchaicGame.ScreenWidth || Position.Y > ArchaicGame.ScreenHeight)
                        {
                            Position = originalPosition;
                        }
                    }
                }
                else
                {
                    Destination = Position;
                }

                _animations.ChangeAnimation(dirX == 1 ? PlayerAnimationNames.WalkRight : PlayerAnimationNames.WalkLeft);

                if (Position.X < 0)
                {
                    Position    = Position.SetX(0);
                    Destination = Destination.SetX(0);
                }
                if (Position.Y < Horizon)
                {
                    Position    = Position.SetY(Horizon);
                    Destination = Destination.SetY(Horizon);
                }

                if (Position.X + Size.X >= ArchaicGame.ScreenWidth)
                {
                    Position    = Position.SetX(ArchaicGame.ScreenWidth - Size.X);
                    Destination = Destination.SetX(ArchaicGame.ScreenWidth - Size.X);
                }
                if (Position.Y + Size.Y >= ArchaicGame.ScreenHeight)
                {
                    Position    = Position.SetY(ArchaicGame.ScreenHeight - Size.Y);
                    Destination = Destination.SetY(ArchaicGame.ScreenHeight - Size.Y);
                }

                if ((int)Position.X == (int)Destination.X && (int)Position.Y == (int)Destination.Y)
                {
                    Destination = Vector2.Zero.MinValue();
                    _animations.ChangeAnimation(dirX == 1 ? PlayerAnimationNames.IdleRight : PlayerAnimationNames.IdleLeft);
                }
            }

            _animations.Update(gameTime);

            _scale = (Position.Y / ArchaicGame.ScreenHeight) * 4f;
        }
Пример #2
0
 public void Update(GameTime time)
 {
     animations.Update(time);
 }