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 CheckCollisionBottomRight(GameObject pRectangle) { if (!_hitboxNew.Intersects(pRectangle.HitBox)) return false; if (_hitboxNew.Top < pRectangle.HitBox.Bottom && _hitboxNew.Right > pRectangle.HitBox.Left) { int distanceX = _hitboxNew.Right - pRectangle.HitBox.Left; int distanceY = pRectangle.HitBox.Bottom - _hitboxNew.Top; if (distanceX < distanceY) { CheckCollisionLeft(pRectangle); CheckCollisionBottom(pRectangle); } else { CheckCollisionBottom(pRectangle); CheckCollisionLeft(pRectangle); } } return true; }
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 bool CollisionSpecialBlock(GameObject pObject) { if (pObject.CanKill && (pObject.GetType() == typeof(HBlock) || pObject.GetType() == typeof(HSpike))) { isDeath = true; return true; } if (pObject.GetType() == typeof(HEnemy)) { if (Typ == HEnum.GeometryTyp.Viereck) { HEnemy e = (HEnemy)pObject; e.IsDead = true; } else isDeath = true; return true; } if (pObject.GetType() == typeof(HBlock)) { HBlock b = (HBlock)pObject; if (b.IsDestructible && !b.IsSwitchable) { b.ActiveDestruct = true; } } if (pObject.GetType() == typeof(HUpgrade)) { HUpgrade u = (HUpgrade)pObject; _actUpgradeStage = u.UpgradeId; SwitchForm(_actUpgradeStage); u.Collected = true; HKeyboard.GamePadVibration(0.5f, 0.5f, 500); return true; } if (pObject.GetType() == typeof(HCollectable)) { HCollectable c = (HCollectable)pObject; c.Collected = true; HKeyboard.GamePadVibration(0.5f, 0.5f, 500); return true; } if (pObject.GetType() == typeof(HSwitch)) { HSwitch s = (HSwitch)pObject; s.StartAction = true; return true; } if (pObject.GetType() == typeof(HJump)) { HJump j = (HJump)pObject; if (j.Degrees == 0) { jumpPlatform = true; JumpTimeY = 0; } else if (j.Degrees == 90) { jumpPlatformRight = true; jumpPlatformLeft = false; JumpTimeX = 0; } else if (j.Degrees == 270) { jumpPlatformLeft = true; jumpPlatformRight = false; JumpTimeX = 0; } return true; } return false; }
public bool CheckIdleCollision(GameObject pObject) { if (!_hitboxNew.Intersects(pObject.HitBox)) return false; float left = Math.Abs(pObject.HitBox.Width / 2 - (_hitboxNew.Right - pObject.HitBox.X + pObject.HitBox.Width / 2)); float right = Math.Abs(pObject.HitBox.Width / 2 - (_hitboxNew.Left - pObject.HitBox.X + pObject.HitBox.Width / 2)); if (left < right) CheckCollisionLeft(pObject); else CheckCollisionRight(pObject); return true; }
public bool CheckCollision(GameObject pEntity) { bool isCollision = false; if (Direction.HasFlag(HEnum._direction.Up ^ HEnum._direction.Right)) isCollision = CheckCollisionBottomRight(pEntity); if (Direction.HasFlag(HEnum._direction.Up ^ HEnum._direction.Left)) isCollision = CheckCollisionBottomLeft(pEntity); if (Direction.HasFlag(HEnum._direction.Down ^ HEnum._direction.Right)) isCollision = CheckCollisionTopRight(pEntity); if (Direction.HasFlag(HEnum._direction.Down ^ HEnum._direction.Left)) isCollision = CheckCollisionTopLeft(pEntity); if (Direction.HasFlag(HEnum._direction.Down)) isCollision = CheckCollisionTop(pEntity); if (Direction.HasFlag(HEnum._direction.Up)) isCollision = CheckCollisionBottom(pEntity); if (Direction.HasFlag(HEnum._direction.Right)) isCollision = CheckCollisionLeft(pEntity); if (Direction.HasFlag(HEnum._direction.Left)) isCollision = CheckCollisionRight(pEntity); //if (Direction == HEnum._direction.None) //{ // isCollision = CheckIdleCollision(pEntity); //} return isCollision; }
public bool CheckCollisionTopLeft(GameObject pRectangle) { if (!_hitboxNew.Intersects(pRectangle.HitBox)) return false; if (_hitboxNew.Bottom > pRectangle.HitBox.Top && _hitboxNew.Left < pRectangle.HitBox.Right) { int distanceX = pRectangle.HitBox.Right - _hitboxNew.Left ; // -3 ist für den Y abstand der fehlerhaft berechnet wird; int distanceY = _hitboxNew.Bottom - pRectangle.HitBox.Top; // (int)_gravity - 1; if (distanceX < distanceY) { CheckCollisionRight(pRectangle); //CheckCollisionTop(pRectangle); } else if (distanceX > distanceY) { CheckCollisionTop(pRectangle); //CheckCollisionRight(pRectangle); } //_hasContact = true; } return true; }
public bool CheckCollisionTopRight(GameObject pRectangle) { if (!_hitboxNew.Intersects(pRectangle.HitBox)) return false; if (_hitboxNew.Bottom > pRectangle.HitBox.Top && _hitboxNew.Right > pRectangle.HitBox.Left) { int distanceX = _hitboxNew.Right- pRectangle.HitBox.Left ; int distanceY = _hitboxNew.Bottom - pRectangle.HitBox.Top; //(int)_gravity - 1; if (distanceX < distanceY) { CheckCollisionLeft(pRectangle); //CheckCollisionTop(pRectangle); } else if (distanceX > distanceY) { CheckCollisionTop(pRectangle); //CheckCollisionLeft(pRectangle); } } return true; }