public void Move(List <Rectangle> platforms) { PossibilityMove.RecalculatePossibilitys(this, platforms); var newX = GoAbility.RecalculateX(this, PossibilityMove); var newY = JumpAbility.RecalculateY(this, PossibilityMove); Location = new Rectangle(new Point(newX, newY), Location.Size); }
public Player(Point startLocation) { PossibilityMove = new PossibilityMove(); var PlayerSize = PlayerImages.standFrames[0].Size; Location = new Rectangle(startLocation, PlayerSize); CurrentTypeMovement = MoveType.Stand; JumpAbility = new JumpAndFall(); GoAbility = new RightAndLeft(); }
public int RecalculateX(Player player, PossibilityMove possibility) { if (player.CurrentTypeMovement == MoveType.Stand) { return(player.Location.Left); } if (player.CurrentTypeMovement == MoveType.Right) { return(possibility.RightWall.HasValue ? possibility.RightWall.Value.Left - player.Location.Width : player.Location.Left + Config.PlayerGoDelta); } if (player.CurrentTypeMovement == MoveType.Left) { return(possibility.LeftWall.HasValue ? possibility.LeftWall.Value.Right : player.Location.Left - Config.PlayerGoDelta); } return(player.Location.Left); }
public int RecalculateY(Player player, PossibilityMove possibility) { if (possibility.Floor.HasValue && IsFalling) { IsFalling = IsJumping = false; CurrentJumpHeight = 0; JumpCount = 0; return(possibility.Floor.Value.Top - player.Location.Height); } if (CurrentJumpHeight >= Config.MaxJumpHeight) { CurrentJumpHeight = 0; IsJumping = false; IsFalling = true; } if (!possibility.Floor.HasValue && !IsJumping) { IsFalling = true; } if (IsJumping) { if (possibility.Ceiling.HasValue) { IsFalling = true; IsJumping = false; CurrentJumpHeight = 0; return(possibility.Ceiling.Value.Bottom); } CurrentJumpHeight += Config.PlayerJumpDelta;; return(player.Location.Top - Config.PlayerJumpDelta);; } if (IsFalling) { return(player.Location.Top + Config.PlayerJumpDelta); } ; return(player.Location.Top); }