public void UpdatePosition(Core.KeyStates keyState, List <RigidShape> sceneStaticShapes) { if (keyState.Shift && !IsInDash && CanDash) { Dash(keyState, sceneStaticShapes); } else if (!IsInDash) { CreateVelocity(keyState, RegularSpeed); } MoveBy(Velocity); }
private void CreateVelocity(Core.KeyStates keyState, int speed) { var delta = Vector.ZeroVector; if (keyState.W) { delta.Y -= speed; } if (keyState.S) { delta.Y += speed; } if (keyState.A) { delta.X -= speed; } if (keyState.D) { delta.X += speed; } Velocity = delta.Normalize() * speed; }
private void Dash(Core.KeyStates keyState, List <RigidShape> sceneStaticShapes) { CreateVelocity(keyState, DashSpeed); if (Equals(Velocity, Vector.ZeroVector)) { return; } var firstPosition = Position + Velocity.Normalize() * (Radius - 1); var closestPenetrationTime = float.PositiveInfinity; foreach (var shape in sceneStaticShapes) { var penetrationTimes = DynamicCollisionDetector.AreCollideWithStatic(firstPosition, Velocity, shape); if (penetrationTimes == null) { continue; } if (penetrationTimes[0] < 1 && penetrationTimes[0] < closestPenetrationTime && penetrationTimes[0] > 0) { closestPenetrationTime = penetrationTimes[0]; } } if (closestPenetrationTime < 1) { Velocity *= closestPenetrationTime; } ticksFromLastDash = 0; dashCount++; if (dashCount == 3) { dashCount = 1; } }