protected void ManageInput() { if (!IsUnableToMove) { IsIdle = true; } // Interaction if (Engine.InputManager.IsKeyDown(Key.F) && !IsUnableToMove) { if (!IsInteracting) { IsMovingLeft = false; IsMovingRight = false; IsIdle = true; IsInteracting = true; Interact(); return; } else if (GameContext.Scene.CurrentInteration.Finished) { IsInteracting = false; InteractTarget = null; return; } } if (IsInteracting) { return; } // Movement if (Engine.InputManager.IsKeyHeld(Key.A) && !IsUnableToMove) { if (RunTimer.Progress == 0 && !IsMovingLeft && !IsMovingRight) { RunTimer.GoNormal(); Sprite.Reset(); } IsMovingLeft = true; IsMovingRight = false; IsIdle = false; IsFacingRight = false; } else { IsMovingLeft = false; if (!IsMovingLeft && !IsMovingRight) { RunTimer.GoInReverse(); RunTimer.End(); } } if (Engine.InputManager.IsKeyHeld(Key.D) && !IsUnableToMove) { if (RunTimer.Progress == 0 && !IsMovingLeft && !IsMovingRight) { RunTimer.GoNormal(); Sprite.Reset(); } IsMovingRight = true; IsMovingLeft = false; IsIdle = false; IsFacingRight = true; } else { IsMovingRight = false; if (!IsMovingLeft && !IsMovingRight) { RunTimer.GoInReverse(); RunTimer.End(); } } // Jumping if (Engine.InputManager.IsKeyHeld(Key.Space) && IsGrounded && !IsUnableToMove) { IsGrounded = false; IsJumping = true; JumpTimer.GoInReverse(); VelocityY = _jumpVelocity; } // Gravity Push if (Engine.InputManager.IsKeyHeld(Key.G) && IsGrounded && !IsUnableToMove) { IsIdle = false; IsMovingLeft = false; IsMovingRight = false; IsUnableToMove = true; IsGravityPushActive = true; Sprite.Reset(); } // Magic Flow if (Engine.InputManager.IsKeyHeld(Key.H) && !IsUnableToMove && !IsMagicFlowActive) { // Set CurrentMagicFlow CurrentMagicFlow = CollisionUtils.RectangleIntesectsWithMagicFlow(CollisionBox.ToRectangle()); if (CurrentMagicFlow == null) { return; } if (CurrentMagicFlow.TraverseFirstToLast) { // If traversing from first to last => start from Point A of the first segment CurrentMagicFlowSegmentIndex = 0; SetCollisionBoxX(CurrentMagicFlow.Segments[CurrentMagicFlowSegmentIndex].PointA.X - (CollisionBox.Width / 2)); SetCollisionBoxY(CurrentMagicFlow.Segments[CurrentMagicFlowSegmentIndex].PointA.Y - (CollisionBox.Height / 2)); } else { // If traversing from last to first => start from Point B of the last segment CurrentMagicFlowSegmentIndex = CurrentMagicFlow.Segments.Count - 1; SetCollisionBoxX(CurrentMagicFlow.Segments[CurrentMagicFlowSegmentIndex].PointB.X - (CollisionBox.Width / 2)); SetCollisionBoxY(CurrentMagicFlow.Segments[CurrentMagicFlowSegmentIndex].PointB.Y - (CollisionBox.Height / 2)); } // TODO: Reset timers IsIdle = false; IsMovingLeft = false; IsMovingRight = false; IsJumping = false; // Reset jump timer IsFalling = false; IsUnableToMove = true; // ? IsMagicFlowActive = true; Sprite.Reset(); } // Debug // Teleport to X if (Engine.InputManager.IsKeyHeld(Key.LeftControl)) { IsGrounded = true; IsFalling = false; IsJumping = false; JumpTimer.End(); SetCollisionBoxY(500); SetCollisionBoxX(700); } else if (Engine.InputManager.IsKeyHeld(Key.RightControl)) { IsGrounded = true; IsFalling = false; IsJumping = false; JumpTimer.End(); SetCollisionBoxY(5100); SetCollisionBoxX(550); } if (Engine.InputManager.IsKeyDown(Key.Q)) { CodeSwitch = !CodeSwitch; Console.WriteLine(CodeSwitch); } }
protected void ManageMovement() { if (IsUnableToMove) { return; } Room currentRoom = GameContext.Scene.LoadedRoom; float newVelocity = VelocityX * RunTimer.Progress; if (IsMovingLeft) { // Make sure movement is within the room borders if (CollisionBox.X > 0 + newVelocity) { Rectangle futurePosition = new Rectangle(CollisionBox.X - newVelocity, CollisionBox.Y, CollisionBox.Width, CollisionBox.Height); ManageHorizontalMovement(futurePosition); } else { SetCollisionBoxX(0); IsMovingLeft = false; IsIdle = true; } } if (IsMovingRight) { // Make sure movement is within the room borders if (CollisionBox.X + CollisionBox.Width < currentRoom.Size.X - newVelocity) { Rectangle futurePosition = new Rectangle(CollisionBox.X + newVelocity, CollisionBox.Y, CollisionBox.Width, CollisionBox.Height); ManageHorizontalMovement(futurePosition); } else { SetCollisionBoxX(currentRoom.Size.X - CollisionBox.Width); IsMovingRight = false; IsIdle = true; } } if (IsJumping) { if (JumpTimer.Finished && !IsFalling) { IsFalling = true; JumpTimer.GoNormal(); } if (IsFalling) { VelocityY = StartingVelocityY; } Rectangle futurePosition = new Rectangle(CollisionBox.X, CollisionBox.Y - (JumpTimer.Progress * VelocityY), CollisionBox.Width, CollisionBox.Height); Collision.LineSegment intersectedPlatform = CollisionUtils.IntersectsWithPlatforms(futurePosition); if (intersectedPlatform == null) { SetCollisionBoxY(CollisionBox.Y - JumpTimer.Progress * VelocityY); } else { IsJumping = false; IsFalling = false; IsGrounded = true; JumpTimer.End(); //Y = 580; } } else { VelocityY = StartingVelocityY; ApplyGravity(); } }