private void ApplySelfKnockback(InputComponent input, int knockback, Vector2 cursorDelta) { if (input.Bindings.TryGetValue(typeof(MovementComponent), out var binding)) { MovementComponent movement = binding as MovementComponent; movement.Speed.SetVector2(new Coord2(-cursorDelta).ChangePolarLength(knockback).Cartesian); } }
private void MovementLogic(InputComponent input) { if (input.Bindings.TryGetValue(typeof(MovementComponent), out var binding)) { MovementComponent movement = binding as MovementComponent; movement.Acceleration.Cartesian.X = input.MovementDirection.X * movement.AccelerationBase; movement.Acceleration.Cartesian.Y = input.MovementDirection.Y * movement.AccelerationBase; } }
private static void SetMovementVariables(BlinkComponent blink, MovementComponent movement, InputComponent input, GameTime gameTime) { blink.MovementDurationTimer.SetTimer(gameTime, blink.BlinkMovementDurationInMilliseconds); blink.MovementDirection = input.MovementDirection; blink.MovementExitSpeed = movement.Speed; SetMovementVariablesForBindings(blink); blink.CurrentEntityState.Blinking = true; }
private static void RotateFromMovementVector(DrawComponent component) { if (component.Bindings.TryGetValue(typeof(MovementComponent), out var binding)) { MovementComponent movement = binding as MovementComponent; if (!movement.IsMoving) { return; } component.Rotation = (float)movement.Speed.Polar.Angle; } }
private void ApplyKnockback(ProjectileComponent actor, BindableComponent target) { if (actor.Bindings.TryGetValue(typeof(MovementComponent), out var actorBinding)) { if (target.Bindings.TryGetValue(typeof(MovementComponent), out var targetBinding)) { MovementComponent actorMovement = actorBinding as MovementComponent; MovementComponent targetMovement = targetBinding as MovementComponent; targetMovement.Speed.SetVector2(new Coord2(actorMovement.Speed.Cartesian).ChangePolarLength(actor.Knockback).Cartesian); } } }
private void HandleDeadComponent(MovementComponent movement) { if (movement.CurrentEntityState.Dead) { movement.Acceleration.ChangeX(0); movement.Acceleration.ChangeY(0); if (!movement.IsMoving) { movement.Deactivate(); } } }
private static bool ExecuteMovementBlink(BlinkComponent blink, InputComponent input, GameTime gameTime) { if (blink.Bindings.TryGetValue(typeof(MovementComponent), out var movementBinding)) { MovementComponent movement = movementBinding as MovementComponent; if (!input.MovementDirection.Equals(Vector2.Zero)) { SetMovementVariables(blink, movement, input, gameTime); SetMovementBlinkSpeed(blink, movement); return(true); } } return(false); }
private static void MaintainMovementBlink(BlinkComponent blink) //TODO Think about this, kinda wanna reorganize the blink logic in general { if (blink.Bindings.TryGetValue(typeof(MovementComponent), out var movementBinding)) { MovementComponent movement = movementBinding as MovementComponent; if (!blink.MovementDurationTimer.Over) { SetMovementBlinkSpeed(blink, movement); } else if (blink.MovementDurationTimer.Over && !blink.PreviousTimerOver) { ExitMovementBlink(blink, movement); } blink.PreviousTimerOver = blink.MovementDurationTimer.Over; } }
private static void ExitMovementBlink(BlinkComponent blink, MovementComponent movement) { movement.Speed = blink.MovementExitSpeed; if (blink.Bindings.TryGetValue(typeof(CollisionComponent), out var collisionBinding)) { CollisionComponent collision = collisionBinding as CollisionComponent; collision.IsPhasing = false; } if (blink.Bindings.TryGetValue(typeof(DrawComponent), out var drawBinding)) { DrawComponent draw = drawBinding as DrawComponent; if (draw.Tint == Color.Cyan) { draw.Tint = Color.White; } } blink.CurrentEntityState.Blinking = false; }
private static void AccelerateUntilMaxSpeed(MovementComponent movement, GameTime gameTime) { if (movement.MaxSpeed != 0.0f) //has a max speed { double delta = movement.MaxSpeed - movement.Speed.Polar.Length; if (delta >= 0) { movement.Speed.AddVector2(movement.Acceleration.Cartesian * (float)gameTime.ElapsedGameTime.TotalSeconds); } else { double previousLength = movement.Speed.Polar.Length; movement.Speed.AddVector2(movement.Acceleration.Cartesian * (float)gameTime.ElapsedGameTime.TotalSeconds); movement.Speed.ChangePolarLength(previousLength); } } }
private static void ApplyInertia(MovementComponent movement, GameTime gameTime) { if (movement.RootType == EntityType.Hero) { Functions_DebugWriter.WriteLine(movement.Acceleration.Cartesian.ToString()); } if (movement.Speed.Polar.Length > 0 && (movement.FrictionWhileAccelerating || movement.Acceleration.Cartesian.Equals(Vector2.Zero) || movement.Speed.Polar.Length > movement.MaxSpeed)) { if (movement.Speed.Polar.Length - movement.Friction * (float)gameTime.ElapsedGameTime.TotalSeconds < 0) { movement.Speed.ChangePolarLength(0); } else { movement.Speed.ChangePolarLength(movement.Speed.Polar.Length - (movement.Friction * ((float)gameTime.ElapsedGameTime.TotalSeconds))); } } }
private void SetMovementStates(MovementComponent movement) { if (movement.CurrentEntityState == null || !movement.CurrentEntityState.ReadyToChange) { return; } StateComponent stateComponent = movement.CurrentEntityState; if (movement.IsMoving) { stateComponent.TryToSetState(EntityState.Moving); if (stateComponent.CurrentState == EntityState.Moving) { double PI = Math.PI; double Angle = movement.Speed.Polar.Angle; if (Angle < PI / 2 && Angle > -PI / 2) { stateComponent.Orientation = Direction.Right; } if (Angle >= PI / 2 || Angle <= -PI / 2) { stateComponent.Orientation = Direction.Left; } /* * if (Angle <= PI / 4 && Angle >= -PI / 4) stateComponent.Direction = Direction.Right; * if (Angle > PI / 4 && Angle < 3 * PI / 4) stateComponent.Direction = Direction.Down; * if (Angle < -PI / 4 && Angle > 3 * -PI / 4) stateComponent.Direction = Direction.Up; * if (Angle >= 3 * PI / 4 || Angle <= 3 * -PI / 4) stateComponent.Direction = Direction.Left; */ } } else { if (stateComponent.CurrentState == EntityState.Moving) { stateComponent.Clear(); } } }
public Pair(CollisionComponent collision, MovementComponent movement) { Collision = collision; Movement = movement; }
private static void SetMovementBlinkSpeed(BlinkComponent blink, MovementComponent movement) { movement.Speed.SetVector2(new Coord2(blink.MovementDirection).ChangePolarLength(blink.BlinkMovementSpeed).Cartesian); }
private static void ApplySpeed(MovementComponent movement, GameTime gameTime) { movement.OldPosition.X = movement.Position.X; movement.OldPosition.Y = movement.Position.Y; movement.Position.Add(movement.Speed.Cartesian * (float)gameTime.ElapsedGameTime.TotalSeconds); }