public bool CheckCollisionBottom(GameObject pRectangle)
        {
            if (!_hitboxNew.Intersects(pRectangle.HitBox)) return false;

            if (CollisionSpecialBlock(pRectangle)) return true;

            if (_hitboxNew.Top < pRectangle.HitBox.Bottom)
            {
                _position.Y = pRectangle.HitBox.Bottom;
                _hitboxNew.Y = (int)_position.Y;
                _speedVelocity.Y = 0;
                Direction &= ~HEnum._direction.Up;
                isJump = false;
                jumpPlatform = false;
                if (Typ == HEnum.GeometryTyp.Viereck)
                {
                    _speedVelocity.Y = 0;
                    SnapOnGrid();
                    _typSettings.Rotation = 0;
                }
                return true;
            }
            return false;
        }
        public bool CheckCollisionTop(GameObject pRectangle)
        {
            if (!_hitboxNew.Intersects(pRectangle.HitBox))
            {
                return false;
            } 

            if (CollisionSpecialBlock(pRectangle)) return true;

            if (_hitboxNew.Bottom > pRectangle.HitBox.Top)
            {
                //Make the player being dragged along by moving platforms
                if(pRectangle.Move.MoveSpeed != null)
                    if (pRectangle.Move.MoveSpeed != Vector2.Zero)
                    {
                        //Calculate the needed speed per frame. 60 is the FPS and 48 the grid size in pixels
                        float platformSpeed = pRectangle.Move.MoveSpeed.X / 60 * 48;

                        //only adjust the X speed if the platform is moving horizontally
                        if (pRectangle.Move.MoveStart.X != pRectangle.Move.MoveEnd.X)
                        {
                            //as long as the player is not moving, make him move at the same speed as the platform
                            if(!HKeyboard.isMoveLeft && !HKeyboard.isMoveRight)
                            {
                                this._speedVelocity.X = platformSpeed;
                            }
                        }
                        else if (pRectangle.Move.MoveStart.Y < pRectangle.Move.MoveEnd.Y)
                        {
                            //if the platform is moving down adjust the players position, otherwise it messes with the ability to jump
                            this._position.Y -= platformSpeed;
                            //this._speedVelocity.Y = platformSpeed;
                        }
                    }
                _position.Y = pRectangle.HitBox.Top - _hitbox.Height;
                _hitboxNew.Y = (int)_position.Y;
                _speedVelocity.Y = 0;
                Direction &= ~HEnum._direction.Down;
                _hasContact = true;
                isJump = false;
                jumpPlatform = false;
                jumpPlatformRight = false;
                if (Typ == HEnum.GeometryTyp.Viereck)
                {
                    _speedVelocity.Y = 0;
                    SnapOnGrid();
                }
                return true;
            }
            return false;
        }
        public bool CheckCollisionRight(GameObject pRectangle)
        {
            if (!_hitboxNew.Intersects(pRectangle.HitBox)) return false;

            if (CollisionSpecialBlock(pRectangle)) return true;

            if (_hitboxNew.Left < pRectangle.HitBox.Right)
            {
                _position.X = pRectangle.HitBox.Right;
                _hitboxNew.X = (int)_position.X;
                _speedVelocity.X = 0;
                    Direction &= ~HEnum._direction.Left;
                _typSettings.Rotation = 0;
                return true;
            }
            jumpPlatformRight = false;
            return false;
        }
        public void JumpPixel()
        {
            float jumpValueCurrentFrame = 0;
            float jumpValueLastFrame = 0;

            if (jumpPlatform)
            {
                jumpValueCurrentFrame = -(int)(-_ascendSpeed * Math.Pow((_jumpTimeY - Math.Sqrt(_heightLimitPlatform / _ascendSpeed)), 2) + _heightLimitPlatform);
                jumpValueLastFrame = -(int)(-_ascendSpeed * Math.Pow(((_jumpTimeY - 1) - Math.Sqrt(_heightLimitPlatform / _ascendSpeed)), 2) + _heightLimitPlatform);

                _speedVelocity.Y = jumpValueCurrentFrame - jumpValueLastFrame;

                //subtract 1 flrom the heightLimit because the jump formula never reaches the value given as limit
                if (Math.Abs(jumpValueCurrentFrame) >= _heightLimitPlatform - 1)
                {
                    this.jumpPlatform = false;
                }
            }
            if (jumpPlatformRight)
            {
                jumpValueCurrentFrame = (int)(-_ascendSpeed * Math.Pow((_jumpTimeX - Math.Sqrt(_heightLimitPlatform / _ascendSpeed)), 2) + _heightLimitPlatform);
                jumpValueLastFrame = (int)(-_ascendSpeed * Math.Pow(((_jumpTimeX - 1) - Math.Sqrt(_heightLimitPlatform / _ascendSpeed)), 2) + _heightLimitPlatform);
                _speedVelocity.X = jumpValueCurrentFrame - jumpValueLastFrame;

                //subtract 1 from the heightLimit because the jump formula never reaches the value given as limit
                if (Math.Abs(jumpValueCurrentFrame) >= _heightLimitPlatform - 1)
                {
                    this.jumpPlatformRight = false;
                }
            }

            if (jumpPlatformLeft)
            {
                jumpValueCurrentFrame = -(int)(-_ascendSpeed * Math.Pow((_jumpTimeX - Math.Sqrt(_heightLimitPlatform / _ascendSpeed)), 2) + _heightLimitPlatform);
                jumpValueLastFrame = -(int)(-_ascendSpeed * Math.Pow(((_jumpTimeX - 1) - Math.Sqrt(_heightLimitPlatform / _ascendSpeed)), 2) + _heightLimitPlatform);
                _speedVelocity.X = jumpValueCurrentFrame - jumpValueLastFrame;

                //subtract 1 from the heightLimit because the jump formula never reaches the value given as limit
                if (Math.Abs(jumpValueCurrentFrame) >= _heightLimitPlatform - 1)
                {
                    this.jumpPlatformLeft = false;
                }
            }

            if (isJump)
            {
                _speedVelocity.Y = -(int)(-_ascendSpeed * Math.Pow((_jumpTimeY - Math.Sqrt(_heightLimit / _ascendSpeed)), 2) + _heightLimit);
                _speedVelocity.Y -= -(int)(-_ascendSpeed * Math.Pow(((_jumpTimeY - 1) - Math.Sqrt(_heightLimit / _ascendSpeed)), 2) + _heightLimit);
                Direction |= HEnum._direction.Up;
            }

            _hitboxNew.Y = (int)_speedVelocity.Y + _hitboxNew.Y;
            _hitboxNew.X = (int)_speedVelocity.X + _hitboxNew.X;

            if (_speedVelocity.Y == 0 && (isJump || jumpPlatform))
            {
                isJump = false;
            }
        }
        public void MovePixel()
        {
            KeyboardState k = Keyboard.GetState();

            Direction = HEnum._direction.None;

            //makes the player stop ascending when the jump button is released
            if (
                !k.IsKeyDown(Keys.Space) 
                && !HKeyboard.gsCurrent.IsButtonDown(Buttons.A)
                && !HKeyboard.gsCurrent.IsButtonDown(Buttons.B)
                && !HKeyboard.gsCurrent.IsButtonDown(Buttons.X)
                && !HKeyboard.gsCurrent.IsButtonDown(Buttons.Y)
                && !HKeyboard.gsCurrent.IsButtonDown(Buttons.RightStick)
                && !HKeyboard.gsCurrent.IsButtonDown(Buttons.LeftStick)
                )
            {
                this.isJump = false;
            }

            if (_hasContact)
                _doubleJump = false;

            ApplyGravity(_gravity);

            if (!isJump && !jumpPlatform && !jumpPlatformRight && !jumpPlatformLeft)
            {
                _jumpTimeY = 0;
                _jumpTimeX = 0;
            }
            if (isJump || jumpPlatform)
            {
                _jumpTimeY++;
            }
            if (jumpPlatformRight || jumpPlatformLeft)
            {
                _jumpTimeX++;
            }

            switch (Typ)
            {
                case HEnum.GeometryTyp.Viereck: if (!_hasContact && !isJump)
                    {
                        if ((k.IsKeyDown(Keys.Left) || HKeyboard.gamePadLeft) && _position.X > 0)
                            Direction |= HEnum._direction.Left;
                        else if ((k.IsKeyDown(Keys.Right) || HKeyboard.gamePadRight) && _position.X < GameSettings.LevelWidth - _hitbox.Width - 4)
                            Direction |= HEnum._direction.Right;
                        else
                            Direction = Direction ^ HEnum._direction.None;
                    }
                break;

                case HEnum.GeometryTyp.Strich:
                {
                    if ((k.IsKeyDown(Keys.Left) || HKeyboard.gamePadLeft) && _position.X > 0)
                    {
                        Direction |= HEnum._direction.Left;
                        animDirection = SpriteEffects.FlipHorizontally;
                    }
                    else if ((k.IsKeyDown(Keys.Right) || HKeyboard.gamePadRight) && _position.X < GameSettings.LevelWidth - _hitbox.Width - 4)
                    {
                        Direction |= HEnum._direction.Right;
                        animDirection = SpriteEffects.None;
                    }
                    else
                        Direction = Direction ^ HEnum._direction.None;
                    break;
                }

                case HEnum.GeometryTyp.Sechseck:
                {
                    if ((k.IsKeyDown(Keys.Left) || HKeyboard.gamePadLeft) && _position.X > 0)
                        Direction |= HEnum._direction.Left;
                    else if ((k.IsKeyDown(Keys.Right) || HKeyboard.gamePadRight) && _position.X < GameSettings.LevelWidth - _hitbox.Width - 4)
                        Direction |= HEnum._direction.Right;
                    else
                        Direction = Direction ^ HEnum._direction.None;
                    break;
                }
            }

            if (Typ.HasFlag(HEnum.GeometryTyp.Viereck) && isJump)
            {
                if ((k.IsKeyDown(Keys.Left) || HKeyboard.gamePadLeft) && _position.X > 0)
                    Direction |= HEnum._direction.Left;
                else if ((k.IsKeyDown(Keys.Right) || HKeyboard.gamePadRight) && _position.X < GameSettings.LevelWidth - _hitbox.Width - 4)
                    Direction |= HEnum._direction.Right;
                else
                    Direction = Direction ^ HEnum._direction.None;
            }
            else if (Typ.HasFlag(HEnum.GeometryTyp.Strich) || Typ.HasFlag(HEnum.GeometryTyp.Sechseck) && !Typ.HasFlag(HEnum.GeometryTyp.Viereck))
            {
                if ((k.IsKeyDown(Keys.Left) || HKeyboard.gamePadLeft) && _position.X > 0 && !jumpPlatformRight)
                    Direction |= HEnum._direction.Left;
                else if ((k.IsKeyDown(Keys.Right) || HKeyboard.gamePadRight) && _position.X < GameSettings.LevelWidth - _hitbox.Width - 4)
                    Direction |= HEnum._direction.Right;
                else
                    Direction = Direction ^ HEnum._direction.None;
            }

            if (isJump || jumpPlatform || jumpPlatformRight || jumpPlatformLeft)
            {
                JumpPixel();
            }

            if (Direction.HasFlag(HEnum._direction.None) && !jumpPlatformRight && !jumpPlatformLeft)
            {
                if (_speedVelocity.X > _friction)
                    _speedVelocity.X -= _friction;
                else if (_speedVelocity.X < -_friction)
                    _speedVelocity.X += _friction;
            }

            if (Direction.HasFlag(HEnum._direction.Left))
            {
                if (_speedVelocity.X - _acceleration > -_maxSpeed)
                    _speedVelocity.X += -_acceleration;
                else if(!jumpPlatformLeft && !jumpPlatformRight)
                    _speedVelocity.X = -_maxSpeed;
            }

            if (Direction.HasFlag(HEnum._direction.Right))
            {
                if (_speedVelocity.X + _acceleration < _maxSpeed)
                    _speedVelocity.X += _acceleration;
                else if(!jumpPlatformRight && !jumpPlatformLeft)
                    _speedVelocity.X = _maxSpeed;
            }

            UpdateIdle();

            if (Math.Abs(_speedVelocity.X) <= _friction && !Direction.HasFlag(HEnum._direction.Left) && !Direction.HasFlag(HEnum._direction.Right))
                _speedVelocity.X = 0;

            if (Direction.HasFlag(HEnum._direction.None))
            {
                if (_speedVelocity.X > 0)
                    Direction |= HEnum._direction.Right;
                else if (_speedVelocity.X < 0)
                    Direction |= HEnum._direction.Left;
            }

            if(Typ == HEnum.GeometryTyp.Strich || Typ == HEnum.GeometryTyp.Sechseck || Typ == HEnum.GeometryTyp.Kreis)
                _typSettings.Rotate(Direction, PlayerTyp);

            if (_position.X < 0 && Direction.HasFlag(HEnum._direction.Left))
            {
                _position.X = 0;
                _speedVelocity.X = 0;
            }
            else if (_position.X > GameSettings.LevelWidth - _hitbox.Width)
            {
                _position.X = GameSettings.LevelWidth - _hitbox.Width;
                _speedVelocity.X = 0;
            }

            if (_position.Y < 0)
                _position.Y = 0;
            else if (_position.Y > GameSettings.LevelHeight - _hitbox.Height)
                _position.Y = GameSettings.LevelHeight - _hitbox.Height;

            _hitboxNew.X = (int)_position.X + (int)_speedVelocity.X;
            _hitboxNew.Y = (int)_position.Y + (int)_speedVelocity.Y;

            //_hasContactLastFrame = _hasContact;
            _hasContact = false;

            this.Direction = HEnum._direction.None;

            if (this._speedVelocity.X > 0)
            {
                this.Direction |= HEnum._direction.Right;
            }
            else if (this._speedVelocity.X < 0)
            {
                this.Direction |= HEnum._direction.Left;
            }

            if (this._speedVelocity.Y > 0)
            {
                this.Direction |= HEnum._direction.Down;
            }
            else if (this._speedVelocity.Y < 0)
            {
                this.Direction |= HEnum._direction.Up;
            }
        }
        public void MoveRaster()
        {
            KeyboardState k = Keyboard.GetState();

            Direction = HEnum._direction.None;

            if (!isJump)
            {
                _position.X = (int)_position.X;

                if (_position.X % 48 != 0)
                {
                    if (Direction == HEnum._direction.Right)
                    {
                        _position.X++;
                        _hitboxNew.X++;
                        _typSettings.Rotation = 0;
                        _speedVelocity.X = 0;
                    }
                    else if (Direction == HEnum._direction.Left)
                    {
                        _position.X--;
                        _hitboxNew.X--;
                        _typSettings.Rotation = 0;
                        _speedVelocity.X = 0;
                    }
                }
                else if (_position.X % 48 == 0)
                {
                    _speedVelocity.X = 0;
                    //_hitbox.X = (int)_position.X;
                }
            }

            if (!isJump)
            {
                _jumpTimeY = 0;
                ApplyGravity(_gravity);
            }
            else if (isJump && !jumpPlatform)
            {
                _jumpTimeY++;
                Direction = HEnum._direction.Up;
            }
            else if (jumpPlatform)
            {
                _jumpTimeY++;
                Direction = HEnum._direction.Up;
            }

            if(Direction.HasFlag(HEnum._direction.None))
            {
                if (_typSettings.Rotation < 0 && _typSettings.Rotation > -45)
                    Direction |= HEnum._direction.Right;
                else if (_typSettings.Rotation <= -45)
                    Direction |= HEnum._direction.Left;
                else if (_typSettings.Rotation > 0 && _typSettings.Rotation < 45)
                    Direction |= HEnum._direction.Left;
                else if (_typSettings.Rotation >= 45)
                    Direction |= HEnum._direction.Right;

                if (_speedVelocity.X > _friction)
                    _speedVelocity.X -= _friction;
                else if (_speedVelocity.X < -_friction)
                    _speedVelocity.X += _friction;
            }


            if ((k.IsKeyDown(Keys.Left) || HKeyboard.gamePadLeft) && _position.X > 0 && !isJump && _hasContact)
            {
                if (Direction.HasFlag(HEnum._direction.Right))
                    Direction &= ~HEnum._direction.Right;
                Direction |= HEnum._direction.Left;
            }

            if ((k.IsKeyDown(Keys.Right) || HKeyboard.gamePadRight) && _position.X > 0 && !isJump && _hasContact)
            {
                if (Direction.HasFlag(HEnum._direction.Left))
                    Direction &= ~HEnum._direction.Left;
                Direction |= HEnum._direction.Right;
            }

            if (Direction.HasFlag(HEnum._direction.Left))
            {
                if (_typSettings.Rotation > 0)
                {
                    _origin = new Vector2(96, 96);
                    _typSettings.Rotate(HEnum._direction.Left, PlayerTyp);
                    _hitboxNew.X = (int)(_position.X + 0.02f * 48 * _typSettings.Rotation);
                }
                else
                {
                    _origin = new Vector2(0, 96);
                    _typSettings.Rotate(HEnum._direction.Left, PlayerTyp);
                    _hitboxNew.X = (int)(_position.X + 0.02f * 48 * _typSettings.Rotation);
                }

                if (_typSettings.Rotation <= -90)
                {
                    _position.X -= 96;
                    _hitboxNew.X = (int)_position.X;
                    _sumoSpriteId++;
                    if (_sumoSpriteId == 4)
                        _sumoSpriteId = 0;
                    _typSettings.Rotation = 0;
                }
            }

            if (Direction.HasFlag(HEnum._direction.Right))
            {
                if (_typSettings.Rotation < 0)
                {
                    _origin = new Vector2(0, 96);
                    _typSettings.Rotate(HEnum._direction.Right, PlayerTyp);
                    _hitboxNew.X = (int)(_position.X + 0.02f * 48 * _typSettings.Rotation);
                    _hitbox = HitboxNew;
                }
                else
                {
                    _origin = new Vector2(96, 96);
                    _typSettings.Rotate(HEnum._direction.Right, PlayerTyp);
                    _hitboxNew.X = (int)(_position.X + 0.02f * 48 * _typSettings.Rotation);
                    _hitbox = HitboxNew;
                }

                if (_typSettings.Rotation >= 90)
                {
                    _position.X += 96;
                    _hitboxNew.X = (int)_position.X;
                    
                    _sumoSpriteId--;
                    if (_sumoSpriteId == -1)
                        _sumoSpriteId = 3;
                    _typSettings.Rotation = 0;
                }
            }

            UpdateIdle();

            if (Direction.HasFlag(HEnum._direction.Up))
            {
                JumpQuaderUp();
            }
            _hasContact = false;
        }
        // ***********************************************************
        // Gravity Normal
        // ***********************************************************
        public void ApplyGravity(float pGravity)
        {
            if (!isJump)
            {
                if (_speedVelocity.Y < _maxGravity)
                    _speedVelocity.Y += _gravity;
                else
                    _speedVelocity.Y = _maxGravity;

                if (_speedVelocity.Y < 1.0f)
                    _speedVelocity.Y = 1.0f;

                _hitboxNew.Y = _hitbox.Y + (int)_speedVelocity.Y;
                //_hitboxNew.Y = (int)_speedVelocity.Y;
                Direction |= HEnum._direction.Down;
            }
        }
        /// <summary>
        /// Sets the enum values for the player according to the current directional vector.
        /// </summary>
        private void setMovingDirections()
        {
            this.Direction = HEnum._direction.None;

            if (this._speedVelocity.X > 0)
            {
                this.Direction |= HEnum._direction.Right;
            }
            else if (this._speedVelocity.X < 0)
            {
                this.Direction |= HEnum._direction.Left;
            }

            if (this._speedVelocity.Y > 0)
            {
                this.Direction |= HEnum._direction.Down;
            }
            else if (this._speedVelocity.Y < 0)
            {
                this.Direction |= HEnum._direction.Up;
            }
        }