Permalink
Browse files

Player slides against walls now. Try to fix vault. Reset particles wh…

…en switching maps.
  • Loading branch information...
etodd committed Jul 21, 2014
1 parent cbae9f5 commit ef84bed75d92fc042c6e7636403913ee9deb142c
Showing with 62 additions and 7 deletions.
  1. +16 −2 Lemma/Graphics/ParticleSystem.cs
  2. +1 −0 Lemma/Main.cs
  3. +40 −2 Lemma/Player/Character.cs
  4. +5 −3 Lemma/Player/Vault.cs
@@ -192,6 +192,20 @@ protected static ParticleSystem add(Main main, string type, ParticleSystem.Parti
return system;
}
+ public static void Reset()
+ {
+ if (ParticleSystem.systems != null)
+ {
+ foreach (ParticleSystem p in ParticleSystem.systems.Values)
+ {
+ p.firstActiveParticle = 0;
+ p.firstFreeParticle = 0;
+ p.firstNewParticle = 0;
+ p.firstRetiredParticle = 0;
+ }
+ }
+ }
+
private static void initialize(Main main)
{
ParticleSystem.systems = new Dictionary<string, ParticleSystem>();
@@ -245,7 +259,7 @@ private static void initialize(Main main)
{
TextureName = "Particles\\debug",
MaxParticles = 10000,
- Duration = TimeSpan.FromSeconds(1.0f),
+ Duration = TimeSpan.FromSeconds(10.0f),
MinHorizontalVelocity = 0.0f,
MaxHorizontalVelocity = 0.0f,
MinVerticalVelocity = 0.0f,
@@ -744,7 +758,7 @@ protected void retireActiveParticles()
break;
// Remember the time at which we retired this particle.
- this.particles[firstActiveParticle * 4].Time = this.drawCounter;
+ this.particles[this.firstActiveParticle * 4].Time = this.drawCounter;
// Move the particle from the active to the retired queue.
this.firstActiveParticle++;
View
@@ -257,6 +257,7 @@ public void ClearEntities(bool deleteEditor)
{
if (this.MapContent != null)
this.MapContent.Unload();
+ ParticleSystem.Reset();
this.MapContent = new ContentManager(this.Services);
this.MapContent.RootDirectory = this.Content.RootDirectory;
View
@@ -349,7 +349,7 @@ void IEndOfTimeStepUpdateable.Update(float dt)
RayCastResult rayHit;
Vector3 rayStart = supportLocation;
rayStart.Y = pos.Y + (this.Body.Height * 0.5f) - 1.0f;
- if (this.main.Space.RayCast(new Ray(rayStart, Vector3.Up), 1.0f, x => x.CollisionRules.Group != Character.CharacterGroup && x.CollisionRules.Group != Character.NoCollideGroup, out rayHit))
+ if (this.main.Space.RayCast(new Ray(rayStart, Vector3.Up), 1.0f, Character.raycastFilter, out rayHit))
{
offset.Normalize();
Vector2 velocity = new Vector2(this.Body.LinearVelocity.X, this.Body.LinearVelocity.Z);
@@ -487,6 +487,35 @@ private void support(Vector3 supportLocationVelocity, Vector3 supportNormal, flo
}
}
+ private static Func<BEPUphysics.BroadPhaseEntries.BroadPhaseEntry, bool> raycastFilter = a => a.CollisionRules.Group != Character.CharacterGroup && a.CollisionRules.Group != Character.NoCollideGroup;
+
+ private bool slide(ref Vector2 movement, Vector3 wallRay)
+ {
+ RayCastResult rayHit;
+ if (this.main.Space.RayCast(new Ray(this.Body.Position, wallRay), this.Radius + 0.25f, Character.raycastFilter, out rayHit)
+ || this.main.Space.RayCast(new Ray(this.Body.Position + new Vector3(0, 1, 0), wallRay), this.Radius + 0.25f, Character.raycastFilter, out rayHit)
+ || this.main.Space.RayCast(new Ray(this.Body.Position + new Vector3(0, -1, 0), wallRay), this.Radius + 0.25f, Character.raycastFilter, out rayHit))
+ {
+ Vector3 orthogonal = Vector3.Cross(rayHit.HitData.Normal, wallRay);
+ Vector3 newMovement3 = Vector3.Cross(rayHit.HitData.Normal, orthogonal);
+ Vector2 newMovement = new Vector2(newMovement3.X, newMovement3.Z);
+ newMovement.Normalize();
+ if (Vector2.Dot(newMovement, movement) < 0)
+ newMovement *= -1.0f;
+
+ if (Vector2.Dot(newMovement, movement) > 0.5f) // The new direction is similar to what we want. Go ahead.
+ {
+ newMovement *= movement.Length();
+ movement = newMovement;
+ return true;
+ }
+ else
+ return false; // New direction is too different. Continue in the old direction.
+ }
+ else
+ return false;
+ }
+
/// <summary>
/// Manages movement acceleration, deceleration, and sliding.
/// </summary>
@@ -501,7 +530,16 @@ private void handleHorizontalMotion(Vector3 supportLocationVelocity, Vector3 sup
// Identify a coordinate system that uses the support normal as Y.
// X is the axis point along the left (negative) and right (positive) relative to the movement direction.
// Z points forward (positive) and backward (negative) in the movement direction modified to be parallel to the surface.
- Vector3 horizontal = new Vector3(this.MovementDirection.Value.X, 0, this.MovementDirection.Value.Y);
+
+ Vector2 movement = this.MovementDirection;
+ if (!this.slide(ref movement, new Vector3(movement.X, 0, movement.Y)))
+ {
+ float angle = (float)Math.Atan2(movement.Y, movement.X);
+ if (!this.slide(ref movement, new Vector3((float)Math.Cos(angle + (float)Math.PI * 0.25f), 0, (float)Math.Sin(angle + (float)Math.PI * 0.25f))))
+ this.slide(ref movement, new Vector3((float)Math.Cos(angle - (float)Math.PI * 0.25f), 0, (float)Math.Sin(angle - (float)Math.PI * 0.25f)));
+ }
+
+ Vector3 horizontal = new Vector3(movement.X, 0, movement.Y);
Vector3 x = Vector3.Normalize(Vector3.Cross(horizontal, supportNormal));
Vector3 z = Vector3.Normalize(Vector3.Cross(supportNormal, x)) * horizontal.Length();
View
@@ -205,9 +205,9 @@ private void vault(Voxel map, Voxel.Coord coord)
float horizontalDistanceToCoord = this.forward.Length();
this.forward /= horizontalDistanceToCoord;
- if (horizontalDistanceToCoord < Character.DefaultRadius + 1.0f)
+ if (horizontalDistanceToCoord < Character.DefaultRadius + 1.2f)
{
- Vector3 pos = coordPosition + this.forward * (Character.DefaultRadius + 1.0f);
+ Vector3 pos = coordPosition + this.forward * (Character.DefaultRadius + 1.2f);
pos.Y = this.Position.Value.Y;
this.Position.Value = pos;
}
@@ -297,9 +297,11 @@ public void Update(float dt)
{
// We hit something above us.
delete = true;
+ this.model.Stop("Vault", "TopOut", "Mantle");
+ this.map = null;
}
else if (this.IsSupported || this.vaultTime > (this.isTopOut ? maxTopoutTime : maxVaultTime)
- || (this.FloorPosition.Value.Y > this.map.GetAbsolutePosition(this.coord).Y + (this.vaultOver ? 0.2f : 0.1f))) // Move forward
+ || (this.FloorPosition.Value.Y > this.map.GetAbsolutePosition(this.coord).Y + 0.2f)) // Move forward
{
// We've reached the top of the vault. Start moving forward.
// Max vault time ensures we never get stuck

0 comments on commit ef84bed

Please sign in to comment.