public bool Move(float deltaTime, Level level) { if (!pastPositions.Any()) return true; if (currentGtc >= pastPositions.Keys.Max()) return false; if ((level.CanMove(pastPositions[currentGtc], pastPositions[currentGtc + 1]))) { DecisionPoint decisionPoint = null; if (decisionPoints.ContainsKey(currentGtc)) decisionPoint = decisionPoints[currentGtc]; if (decisionPoint == null || decisionPoint.Condition()) { float delta = pastPositions[currentGtc + 1].X - pastPositions[currentGtc].X; if (delta < 0) Rotation = 1; if (delta > 0) Rotation = -1; Model.AnimationPlayer.Update(TimeSpan.FromSeconds(Math.Abs(9f * delta / 25f)), true, Matrix.Identity); currentFloatGtc += deltaTime * 25f; currentGtc = (int)currentFloatGtc; } } float a = 1f - (currentFloatGtc - currentGtc); Position = pastPositions[currentGtc] * a + pastPositions[Math.Min(currentGtc + 1, pastPositions.Keys.Max())] * (1 - a); return true; }
public void Move(float delta, Level level) { if (level.CanMove(Position, delta)) { Model.AnimationPlayer.Update(TimeSpan.FromSeconds(Math.Abs(delta)), true, Matrix.Identity); Position = Position + new Vector2(delta, 0); } level.FirePositionalTriggers(Position, delta); }
private void ResetWorld() { specialEffects = new List<SpecialEffect>(); level = new Level(specialEffects, models); }
public void Move(Vector2 acceleration, float dt, Level level) { Vector2 dragCoefficient = new Vector2(2.3f, 0.1f); Vector2 drag = new Vector2(dragCoefficient.X * Velocity.X * Math.Abs(Velocity.X), dragCoefficient.Y * Velocity.Y * Math.Abs(Velocity.Y)); if (IsGrounded) drag *= 1.75f; Velocity = Velocity + acceleration * dt - drag * dt; if (IsGrounded) Model.AnimationPlayer.Update(TimeSpan.FromSeconds(Math.Abs(Velocity.X * 0.66f * dt)), true, Matrix.Identity); if (Velocity.X < 0) Rotation = 1; if (Velocity.X > 0) Rotation = -1; if (Velocity.Length() < 0.50f) Velocity = Vector2.Zero; level.FirePositionalTriggers(Position, Velocity.X * dt); var v = level.GetFinalVelocity(GetRectangle(), Velocity * dt); // Reduce jiggle if (Math.Abs(v.Y) < 0.001f) v.Y = 0; if (Math.Abs(v.X) < 0.001f) v.X = 0; // Reduce jiggle if (Math.Abs(Velocity.Y) < 0.3f) Velocity = new Vector2(Velocity.X, 0); if (Math.Abs(Velocity.X) < 0.3f) Velocity = new Vector2(0, Velocity.Y); Position = Position + v; var crv = level.GetCollisionResolvingVector(GetRectangle()); Position = Position + crv; IsGrounded = level.IsGrounded(GetRectangle()) && !(Velocity.Y > 0); IsFalling = !IsGrounded && Velocity.Y < 0; }
public void Record(PresentPlayer present, Level level, int gtc) { if (pastPositions.ContainsKey(gtc)) pastPositions[gtc] = present.Position; else pastPositions.Add(gtc, present.Position); foreach (var decisionPoint in level.GetDecisionPoints()) { if (decisionPoints.ContainsValue(decisionPoint)) continue; if (Math.Abs(present.Position.X - decisionPoint.Position.X) < 0.1f) { if (decisionPoints.ContainsKey(gtc)) decisionPoints[gtc] = decisionPoint; else decisionPoints.Add(gtc, decisionPoint); } } }