public CollisionType GetRotatedFace(FaceOrientation face) { FaceOrientation index = FezMath.OrientationFromPhi(FezMath.ToPhi(face) - this.Phi); CollisionType collisionType = this.Trile.Faces[index]; if (collisionType == CollisionType.TopOnly) { TrileEmplacement emplacement = this.Emplacement; ++emplacement.Y; Vector3 mask = FezMath.GetMask(FezMath.AsAxis(face)); TrileInstance trileInstance; if (TrileInstance.LevelManager.Triles.TryGetValue(emplacement, out trileInstance) && trileInstance.Enabled && !trileInstance.IsMovingGroup && (trileInstance.Trile.Geometry == null || !trileInstance.Trile.Geometry.Empty || trileInstance.Trile.Faces[index] != CollisionType.None) && (!trileInstance.Trile.Immaterial && trileInstance.Trile.Faces[index] != CollisionType.Immaterial && (!trileInstance.Trile.Thin && !ActorTypeExtensions.IsPickable(trileInstance.Trile.ActorSettings.Type)) && (((double)trileInstance.Trile.Size.Y == 1.0 || trileInstance.ForceTopMaybe) && FezMath.AlmostEqual(FezMath.Dot(trileInstance.Center, mask), FezMath.Dot(this.Center, mask))))) { collisionType = CollisionType.None; } } return(collisionType); }
public override void Update(GameTime gameTime) { if (this.CameraManager.Viewpoint == Viewpoint.Perspective || this.GameState.InMap || (this.GameState.Paused || this.GameState.Loading) || this.watchers.Count == 0) { return; } Vector3 vector3_1 = FezMath.RightVector(this.CameraManager.Viewpoint); Vector3 vector3_2 = FezMath.Abs(vector3_1); Vector3 vector3_3 = FezMath.ForwardVector(this.CameraManager.Viewpoint); foreach (TrileInstance index in this.watchers.Keys) { WatchersHost.WatcherState watcherState = this.watchers[index]; Vector3 vector3_4 = index.PhysicsState.Center + vector3_2 * -5f / 16f + Vector3.UnitY * -2f / 16f - 0.5f * vector3_3; watcherState.Eyes.Groups[0].Position = vector3_4 + watcherState.EyeOffset; watcherState.Eyes.Groups[1].Position = vector3_4 + vector3_2 * 9f / 16f + watcherState.EyeOffset; watcherState.Eyes.Groups[0].Enabled = true; watcherState.Eyes.Groups[1].Enabled = true; } if (!this.CameraManager.ActionRunning || !this.CameraManager.ViewTransitionReached) { return; } Vector3 center1 = this.PlayerManager.Center; BoundingBox box = FezMath.Enclose(center1 - this.PlayerManager.Size / 2f, center1 + this.PlayerManager.Size / 2f); Vector3 vector3_5 = vector3_1 * 8f; Vector3 vector3_6 = vector3_3 * this.LevelManager.Size; Vector3 vector3_7 = Vector3.Up * 8f; this.lastCrushDirections.Clear(); bool flag1 = false; foreach (TrileInstance index in this.watchers.Keys) { WatchersHost.WatcherState watcherState1 = this.watchers[index]; Vector3 vector1 = FezMath.Sign(center1 - index.Position) * vector3_2; Vector3 vector3_4 = FezMath.Sign(center1 - index.Position) * Vector3.UnitY; BoundingBox boundingBox1 = (double)Vector3.Dot(vector1, vector3_1) > 0.0 ? FezMath.Enclose(index.Position + Vector3.UnitY * 0.05f - vector3_6, index.Position + vector3_5 + vector3_6 + new Vector3(0.9f)) : FezMath.Enclose(index.Position + Vector3.UnitY * 0.05f - vector3_6 - vector3_5, index.Position + vector3_6 + new Vector3(0.9f)); BoundingBox boundingBox2 = FezMath.Enclose(index.Position + Vector3.UnitY * 0.05f - vector3_7 - vector3_6, index.Position + vector3_7 + new Vector3(0.9f) + vector3_6); switch (watcherState1.Action) { case WatchersHost.WatcherAction.Idle: bool flag2 = boundingBox1.Intersects(box); bool flag3 = boundingBox2.Intersects(box); watcherState1.EyeOffset = !flag2 ? (!flag3 ? Vector3.Lerp(watcherState1.EyeOffset, Vector3.Zero, 0.1f) : Vector3.Lerp(watcherState1.EyeOffset, vector3_4 * 1f / 16f, 0.25f)) : Vector3.Lerp(watcherState1.EyeOffset, vector1 * 1f / 16f, 0.25f); watcherState1.CrushDirection = flag2 ? vector1 : (flag3 ? vector3_4 : Vector3.Zero); watcherState1.Eyes.Material.Opacity = 1f; WatchersHost.WatcherState watcherState2; if (this.LevelManager.NearestTrile(index.Position + new Vector3(0.5f)).Deep == index && (flag2 || flag3) && (!FezMath.In <ActionType>(this.PlayerManager.Action, ActionType.GrabCornerLedge, ActionType.Suffering, ActionType.Dying, (IEqualityComparer <ActionType>)ActionTypeComparer.Default) && (watcherState2 = this.HasPair(index)) != null)) { watcherState1.Action = WatchersHost.WatcherAction.Spotted; watcherState2.StartTime = watcherState1.StartTime = gameTime.TotalGameTime; if (!watcherState1.SkipNextSound) { SoundEffectExtensions.EmitAt(this.seeSound, index.Center); watcherState2.SkipNextSound = true; break; } else { break; } } else { break; } case WatchersHost.WatcherAction.Spotted: watcherState1.EyeOffset = Vector3.Lerp(watcherState1.EyeOffset, watcherState1.CrushDirection * 1f / 16f, 0.25f); if ((gameTime.TotalGameTime - watcherState1.StartTime).TotalSeconds > 1.0) { watcherState1.Action = WatchersHost.WatcherAction.Crushing; watcherState1.StartTime = gameTime.TotalGameTime; index.PhysicsState.Velocity = watcherState1.OriginalCenter - index.Center; this.PhysicsManager.Update((ISimplePhysicsEntity)index.PhysicsState, true, false); index.PhysicsState.UpdateInstance(); this.LevelManager.UpdateInstance(index); watcherState1.MoveEmitter = watcherState1.SkipNextSound ? (SoundEmitter)null : SoundEffectExtensions.EmitAt(this.moveSound, index.Center); break; } else { Vector3 vector3_8 = watcherState1.CrushDirection * RandomHelper.Unit() * 0.5f / 16f; index.PhysicsState.Sticky = true; index.PhysicsState.Velocity = watcherState1.OriginalCenter + vector3_8 - index.Center; this.PhysicsManager.Update((ISimplePhysicsEntity)index.PhysicsState, true, false); index.PhysicsState.UpdateInstance(); this.LevelManager.UpdateInstance(index); break; } case WatchersHost.WatcherAction.Crushing: if (index.PhysicsState.Sticky) { index.PhysicsState.Sticky = false; index.PhysicsState.Velocity = Vector3.Zero; } watcherState1.EyeOffset = watcherState1.CrushDirection * 1f / 16f; Vector3 vector3_9 = watcherState1.CrushDirection * (float)gameTime.ElapsedGameTime.TotalSeconds * 15f; Vector3 vector3_10 = Vector3.Lerp(index.PhysicsState.Velocity, vector3_9, 0.025f); index.PhysicsState.Velocity = vector3_10 * watcherState1.CrashAttenuation; if (FezMath.VisibleAxis(this.CameraManager.Viewpoint) != FezMath.AsAxis(FezMath.OrientationFromDirection(watcherState1.CrushDirection))) { this.PhysicsManager.Update((ISimplePhysicsEntity)index.PhysicsState, false, false); } Vector3 vector3_11 = vector3_10 * watcherState1.CrashAttenuation - index.PhysicsState.Velocity; if (watcherState1.MoveEmitter != null) { watcherState1.MoveEmitter.Position = index.Center; } index.PhysicsState.UpdateInstance(); this.LevelManager.UpdateInstance(index); this.PlayerManager.ForceOverlapsDetermination(); bool flag4 = this.PlayerManager.HeldInstance == index || this.PlayerManager.WallCollision.FarHigh.Destination == index || (this.PlayerManager.WallCollision.NearLow.Destination == index || this.PlayerManager.Ground.NearLow == index) || this.PlayerManager.Ground.FarHigh == index; if (!flag4) { foreach (PointCollision pointCollision in this.PlayerManager.CornerCollision) { if (pointCollision.Instances.Deep == index) { flag4 = true; break; } } } if (flag1 && flag4 && this.lastCrushDirections.Contains(-watcherState1.CrushDirection)) { this.PlayerManager.Position = index.Center + Vector3.One / 2f * watcherState1.CrushDirection + -FezMath.SideMask(this.CameraManager.Viewpoint) * FezMath.Abs(watcherState1.CrushDirection) * 1.5f / 16f; this.PlayerManager.Velocity = Vector3.Zero; this.PlayerManager.Action = (double)watcherState1.CrushDirection.Y == 0.0 ? ActionType.CrushHorizontal : ActionType.CrushVertical; watcherState1.CrashAttenuation = this.PlayerManager.Action == ActionType.CrushVertical ? 0.5f : 0.75f; } flag1 = flag1 | flag4; if (flag4 && this.PlayerManager.Action != ActionType.CrushHorizontal && this.PlayerManager.Action != ActionType.CrushVertical) { this.lastCrushDirections.Add(watcherState1.CrushDirection); if ((double)watcherState1.CrushDirection.Y == 0.0) { this.PlayerManager.Position += index.PhysicsState.Velocity; } } if ((double)vector3_11.LengthSquared() > 4.99999987368938E-05 || (double)Math.Abs(Vector3.Dot(index.Center - watcherState1.OriginalCenter, FezMath.Abs(watcherState1.CrushDirection))) >= 8.0) { if (watcherState1.MoveEmitter != null && !watcherState1.MoveEmitter.Dead) { watcherState1.MoveEmitter.Cue.Stop(false); } watcherState1.MoveEmitter = (SoundEmitter)null; if (!watcherState1.SkipNextSound) { SoundEffectExtensions.EmitAt(this.collideSound, index.Center); } watcherState1.Action = WatchersHost.WatcherAction.Wait; index.PhysicsState.Velocity = Vector3.Zero; watcherState1.StartTime = TimeSpan.Zero; watcherState1.CrashAttenuation = 1f; break; } else { break; } case WatchersHost.WatcherAction.Wait: watcherState1.StartTime += gameTime.ElapsedGameTime; if (watcherState1.StartTime.TotalSeconds > 1.5) { watcherState1.Action = WatchersHost.WatcherAction.Withdrawing; watcherState1.StartTime = gameTime.TotalGameTime; watcherState1.WithdrawEmitter = watcherState1.SkipNextSound ? (SoundEmitter)null : SoundEffectExtensions.EmitAt(this.withdrawSound, index.Center, true); break; } else { break; } case WatchersHost.WatcherAction.Withdrawing: watcherState1.EyeOffset = Vector3.Lerp(watcherState1.EyeOffset, -watcherState1.CrushDirection * 0.5f / 16f, 0.05f); Vector3 vector3_12 = -watcherState1.CrushDirection * (float)gameTime.ElapsedGameTime.TotalSeconds * 2f; index.PhysicsState.Velocity = Vector3.Lerp(index.PhysicsState.Velocity, vector3_12, 0.025f); if (watcherState1.WithdrawEmitter != null) { watcherState1.WithdrawEmitter.VolumeFactor = 0.0f; } bool flag5 = false; if (FezMath.DepthMask(this.CameraManager.Viewpoint) == FezMath.GetMask(FezMath.AsAxis(FezMath.OrientationFromDirection(watcherState1.CrushDirection)))) { flag5 = true; } if (watcherState1.WithdrawEmitter != null) { watcherState1.WithdrawEmitter.VolumeFactor = 1f; } Vector3 center2 = index.PhysicsState.Center; Vector3 velocity = index.PhysicsState.Velocity; this.PhysicsManager.Update((ISimplePhysicsEntity)index.PhysicsState, true, false); index.PhysicsState.Center = center2 + velocity; if (watcherState1.WithdrawEmitter != null) { watcherState1.WithdrawEmitter.Position = index.Center; } if (flag5 ? (double)Math.Abs(Vector3.Dot(index.Center - watcherState1.OriginalCenter, vector3_1 + Vector3.Up)) <= 1.0 / 32.0 : (double)Vector3.Dot(index.Center - watcherState1.OriginalCenter, watcherState1.CrushDirection) <= 1.0 / 1000.0) { if (watcherState1.WithdrawEmitter != null) { watcherState1.WithdrawEmitter.FadeOutAndDie(0.1f); watcherState1.WithdrawEmitter = (SoundEmitter)null; } watcherState1.SkipNextSound = false; watcherState1.Action = WatchersHost.WatcherAction.Cooldown; watcherState1.CrushDirection = Vector3.Zero; watcherState1.StartTime = TimeSpan.Zero; } index.PhysicsState.UpdateInstance(); this.LevelManager.UpdateInstance(index); break; case WatchersHost.WatcherAction.Cooldown: index.PhysicsState.Velocity = watcherState1.OriginalCenter - index.Center; this.PhysicsManager.Update((ISimplePhysicsEntity)index.PhysicsState, true, false); index.PhysicsState.UpdateInstance(); this.LevelManager.UpdateInstance(index); watcherState1.EyeOffset = Vector3.Lerp(watcherState1.EyeOffset, Vector3.Zero, 0.05f); watcherState1.Eyes.Material.Opacity = 0.5f; watcherState1.StartTime += gameTime.ElapsedGameTime; if (watcherState1.StartTime.TotalSeconds > 0.5) { index.PhysicsState.Velocity = Vector3.Zero; watcherState1.Action = WatchersHost.WatcherAction.Idle; break; } else { break; } } Vector3 vector3_13 = index.PhysicsState.Center + vector3_2 * -5f / 16f + Vector3.UnitY * -2f / 16f - 0.5f * vector3_3; watcherState1.Eyes.Groups[0].Position = vector3_13 + watcherState1.EyeOffset; watcherState1.Eyes.Groups[1].Position = vector3_13 + vector3_2 * 9f / 16f + watcherState1.EyeOffset; watcherState1.Eyes.Groups[2].Position = watcherState1.Eyes.Groups[0].Position; watcherState1.Eyes.Groups[3].Position = watcherState1.Eyes.Groups[1].Position; watcherState1.Eyes.Groups[0].Enabled = false; watcherState1.Eyes.Groups[1].Enabled = false; } }
protected override void LoadContent() { base.LoadContent(); this.shadowEffect = new CloudShadowEffect(); this.shadowMesh = new Mesh() { DepthWrites = false, AlwaysOnTop = true, SamplerState = SamplerState.LinearWrap }; foreach (FaceOrientation faceOrientation in Util.GetValues <FaceOrientation>()) { if (FezMath.IsSide(faceOrientation)) { this.axisPerGroup.Add(this.shadowMesh.AddFace(Vector3.One, Vector3.Zero, faceOrientation, true), FezMath.AsAxis(faceOrientation) == Axis.X ? Axis.Z : Axis.X); } } this.shadowMesh.Effect = (BaseEffect)this.shadowEffect; this.LevelManager.SkyChanged += new Action(this.InitializeShadows); this.InitializeShadows(); this.LightingPostProcess.DrawOnTopLights += new Action(this.DrawLights); }
public LongRunningAction PlaySoundAt(int id, string soundName, bool loop, float initialDelay, float perLoopDelay, bool directional, float pitchVariation) { SoundEffect sfx = this.CMProvider.CurrentLevel.Load <SoundEffect>("Sounds/" + soundName); float duration = (float)sfx.Duration.TotalSeconds; Volume volume = this.LevelManager.Volumes[id]; Vector3 center = (volume.From + volume.To) / 2f; Vector3 direction = Vector3.One; if (directional) { direction = Enumerable.Aggregate <Vector3>(Enumerable.Select <FaceOrientation, Vector3>((IEnumerable <FaceOrientation>)volume.Orientations, (Func <FaceOrientation, Vector3>)(x => FezMath.GetMask(FezMath.AsAxis(x)))), (Func <Vector3, Vector3, Vector3>)((a, b) => a + b)); } if (!loop && (double)initialDelay <= 0.0) { SoundEffectExtensions.EmitAt(sfx, center, RandomHelper.Centered((double)pitchVariation)).AxisMask = direction; return((LongRunningAction)null); } else { float toWait = initialDelay; bool perfectLoop = loop && (double)perLoopDelay <= 0.0 && (double)pitchVariation <= 0.0; if (perfectLoop) { return(new LongRunningAction((Func <float, float, bool>)((elapsed, total) => { toWait -= elapsed; if ((double)toWait > 0.0) { return false; } SoundEffectExtensions.EmitAt(sfx, center, perfectLoop, RandomHelper.Centered((double)pitchVariation)).AxisMask = direction; return true; }))); } else { return(new LongRunningAction((Func <float, float, bool>)((elapsed, total) => { toWait -= elapsed; if ((double)toWait <= 0.0) { SoundEffectExtensions.EmitAt(sfx, center, RandomHelper.Centered((double)pitchVariation)).AxisMask = direction; if (!loop) { return true; } toWait += perLoopDelay + duration; } return false; }))); } } }