public void RevertVelocity() { velocity = -velocity; if (ViewDirection == SideDirections.Left) { ViewDirection = SideDirections.Right; } else { ViewDirection = SideDirections.Left; } }
public void Move(SideDirections direction) { if (player != null) { if (direction == SideDirections.Right) { Center = new Vector2(player.Center.X + player.SpriteRect.Width / 2 + SpriteRect.Width / 2 + gap, player.Center.Y); } if (direction == SideDirections.Left) { Center = new Vector2(player.Center.X - player.SpriteRect.Width / 2 - SpriteRect.Width / 2 - gap, player.Center.Y); } movement.ViewDirection = direction; } }
public Portal Teleport(BoxCollider portalCollider, SideDirections viewDirection, Vector2 velocity) { if (hasTeleported) { return(null); } Portal destinationPortal = SceneManager.GetDestinationPortal((Portal)portalCollider.GameObject); if (destinationPortal.Position == Vector2.Zero) { return(null); } float gap = 25f; // colliding from left if (!(Collider.Right < portalCollider.Left) && viewDirection == SideDirections.Right) { if (destinationPortal.ViewDirection == SideDirections.Right) { Position = new Vector2(destinationPortal.Collider.Right + velocity.X + gap, destinationPortal.Position.Y + destinationPortal.Collider.Height / 2 - Collider.Height / 2); } else if (destinationPortal.ViewDirection == SideDirections.Left) { Position = new Vector2(destinationPortal.Collider.Left - velocity.X - gap - Collider.Width, destinationPortal.Position.Y + destinationPortal.Collider.Height / 2 - Collider.Height / 2); velocity = -velocity; } hasTeleported = true; } //colliding from right else if (!(Collider.Left > portalCollider.Right) && viewDirection == SideDirections.Left) { if (destinationPortal.ViewDirection == SideDirections.Right) { Position = new Vector2(destinationPortal.Collider.Right - velocity.X + gap, destinationPortal.Position.Y + destinationPortal.Collider.Height / 2 - Collider.Height / 2); velocity = -velocity; } else if (destinationPortal.ViewDirection == SideDirections.Left) { Position = new Vector2(destinationPortal.Collider.Left + velocity.X - gap - Collider.Width, destinationPortal.Position.Y + destinationPortal.Collider.Height / 2 - Collider.Height / 2); } hasTeleported = true; } return(destinationPortal); }
// ProcessInput Options: public void Move(SideDirections direction) { ViewDirection = direction; switch (direction) { case SideDirections.Right: velocity.X = MoveForce; break; case SideDirections.Left: velocity.X = -MoveForce; break; case SideDirections.None: velocity.X = 0f; break; default: velocity.X = 0f; break; } }
private void OnKeyDown(InputEventArgs eventArgs) { switch (eventArgs.Key) { case Keys.D: if (canMoveRight) { velocity.X = moveForce; viewDirection = SideDirections.Right; state = States.Walk; canMoveLeft = false; } break; case Keys.A: if (canMoveLeft) { velocity.X = -moveForce; viewDirection = SideDirections.Left; state = States.Walk; canMoveRight = false; } break; default: state = States.Idle; break; } if (isGrounded && eventArgs.Key == (Keys.Space) && isGroundedTimer > jumpCooldown) { velocity.Y = -jumpForce; isJumping = true; isGrounded = false; isGroundedTimer = 0; state = States.Jump; } }
public void ResetVelocity() { velocity = Vector2.Zero; ViewDirection = SideDirections.None; }
private void OnCollisionEnter(BoxCollider other) { Console.WriteLine("chell hit " + other.GameObject.Name); if (!other.IsTrigger) { //colliding from above if (!(Collider.Bottom < other.Top) && lastPosition.Y + Collider.Height <= other.Top) { isGrounded = true; isJumping = false; state = States.Idle; accelerationMultipier = 0; if (Position.Y != other.GameObject.Position.Y - Collider.Height) { Position.Y = other.GameObject.Position.Y - Collider.Height; } velocity.Y = 0f; } // colliding from beneigh else if (!(Collider.Top >= other.Bottom) && lastPosition.Y > other.Bottom) { velocity.Y = 0f; Position.Y = other.Bottom + 1; } // colliding from left or right else if (Collider.CollidesWithLeftOf(other) || Collider.CollidesWithRightOf(other)) #region /*if (!(Collider.Right < other.Left) || !(Collider.Left > other.Right))*/ #endregion { velocity.X = 0f; correction.X = lastPosition.X - Position.X; if (correction.X < 0) { canMoveRight = false; } else if (correction.X > 0) { canMoveLeft = false; } LeftAndRightCollisions.Add(other); } } if (other.GameObject is Portal) { Portal destinationportal = Teleport(other, viewDirection, velocity); if (destinationportal != null) { viewDirection = destinationportal.ViewDirection; if (!Collider.AutoPositionUpdateIsEnabled) { if (viewDirection == SideDirections.Right) { Collider.X = (int)Position.X; } else if (viewDirection == SideDirections.Left) { Collider.X = (int)Position.X - colliderExtension; } } } } if (other.GameObject is WeightedCompanionCube) { cubeInReach = (WeightedCompanionCube)other.GameObject; cubeInReach.OnToggleHoldState += ToggleHoldState; } }