Example #1
0
        private void HandleInput(GameTime gameTime)
        {
            GamePadState currentPad = Moxy.CurrentPadStates[PadIndex];

            Vector2 moveVector = currentPad.ThumbSticks.Left;
            if (moveVector.Length() > 0)
                moveVector.Normalize();

            moveVector.Y *= -1;

            if (lastMovement == Vector2.Zero && moveVector != Vector2.Zero)
                Animation = "Walk";
            else if (moveVector == Vector2.Zero)
                Animation = "Idle";

            Health = MathHelper.Clamp(Health, 0, MaxHealth);

            var playerMoveEventArgs = new PlayerMovementEventArgs
            {
                NewLocation = this.Location + moveVector * Speed * (float)gameTime.ElapsedGameTime.TotalMilliseconds,
                Handled = false,
                //Player = this,
                CurrentLocation = this.Location
            };

            if (OnMovement != null)
                OnMovement(this, playerMoveEventArgs);

            if (!playerMoveEventArgs.Handled)
                base.Location += moveVector * Speed * (float)gameTime.ElapsedGameTime.TotalMilliseconds;
            else
                base.Location = playerMoveEventArgs.NewLocation;

            if (moveVector.Length() != 0)
                base.Rotation = (float)Math.Atan2 (moveVector.Y, moveVector.X);

            lastMovement = moveVector;
            oldPad = currentPad;
        }
Example #2
0
        private void HandleMovement(GameTime gameTime, Vector2 moveVector)
        {
            var playerMoveEventArgs = new PlayerMovementEventArgs
            {
                CurrentLocation = Location,
                NewLocation = Location +(moveVector * Speed * (float)gameTime.ElapsedGameTime.TotalMilliseconds),
                Player = this,
                Handled = false
            };

            if (OnMovement != null)
                OnMovement (this, playerMoveEventArgs);

            base.Location = !playerMoveEventArgs.Handled
                ? Location + moveVector * Speed * (float)gameTime.ElapsedGameTime.TotalMilliseconds
                : playerMoveEventArgs.NewLocation;

            if (moveVector.Length () != 0)
                base.Rotation = (float)Math.Atan2 (moveVector.Y, moveVector.X);
        }
Example #3
0
        private void Player_OnMovement(object sender, PlayerMovementEventArgs e)
        {
            var collisionRect = e.Player.Collision;
            collisionRect.X = (int) e.NewLocation.X;
            collisionRect.Y = (int) e.NewLocation.Y;

            if (map.CheckCollision(collisionRect))
            {
                e.Handled = true;
                e.NewLocation = e.CurrentLocation;
            }
            // TODO: Add distance limiting
            // TODO: Add collision here
        }