Exemple #1
0
 private void LoadCharacters()
 {
     foreach (NpcState component in this.NpcStates)
     {
         ServiceHelper.RemoveComponent <NpcState>(component);
     }
     this.NpcStates.Clear();
     foreach (NpcInstance npc in (IEnumerable <NpcInstance>) this.LevelManager.NonPlayerCharacters.Values)
     {
         NpcState npcState = this.CreateNpcState(npc);
         if (npcState != null)
         {
             ServiceHelper.AddComponent((IGameComponent)npcState);
             npcState.Initialize();
             this.NpcStates.Add(npcState);
         }
     }
 }
Exemple #2
0
        private void Fly(TimeSpan elapsed)
        {
            if (!this.flyRight.HasValue)
            {
                this.flyRight = new Vector3?(Vector3.Transform(Vector3.Right, this.Group.Rotation));
            }
            if ((!this.FlyingBack || this.Npc.ActorType != ActorType.Owl) && FezMath.AlmostEqual(FezMath.Dot(FezMath.Abs(Vector3.Transform(Vector3.Right, this.Group.Rotation)), FezMath.Abs(this.flyRight.Value)), 0.0f, 0.1f))
            {
                NpcState npcState  = this;
                Vector3? nullable1 = npcState.flyRight;
                Vector3  vector3   = Vector3.Transform(Vector3.Right, this.Group.Rotation);
                Vector3? nullable2 = nullable1.HasValue ? new Vector3?(nullable1.GetValueOrDefault() + vector3) : new Vector3?();
                npcState.flyRight = nullable2;
            }
            this.flySpeed = Vector2.Lerp(this.flySpeed, new Vector2(4f, 3f), 0.03333334f);
            Vector2 vector2 = this.flySpeed * ((1f - FezMath.Frac(this.CurrentTiming.Step + 0.75f)) * new Vector2(0.4f, 0.6f) + new Vector2(0.6f, 0.4f));

            this.Position += (float)elapsed.TotalSeconds * (vector2.X * this.flyRight.Value + Vector3.Up * vector2.Y * (this.FlyingBack ? -1f : 1f));
            if (FezMath.IsOrthographic(this.CameraManager.Viewpoint) && this.CameraManager.ViewTransitionReached)
            {
                Vector3 b = FezMath.ForwardVector(this.CameraManager.Viewpoint);
                if (this.InBackground)
                {
                    b *= -1f;
                }
                NearestTriles nearestTriles = this.LevelManager.NearestTrile(this.Position, QueryOptions.Simple);
                TrileInstance trileInstance = nearestTriles.Surface ?? nearestTriles.Deep;
                if (trileInstance != null)
                {
                    Vector3 a       = trileInstance.Center + trileInstance.TransformedSize / 2f * -b;
                    Vector3 vector3 = FezMath.DepthMask(this.CameraManager.Viewpoint);
                    if ((double)FezMath.Dot(this.Position, b) > (double)FezMath.Dot(a, b))
                    {
                        this.Position = this.Position * FezMath.ScreenSpaceMask(this.CameraManager.Viewpoint) + a * vector3 - b;
                    }
                }
            }
            if (this.CurrentTiming.Frame == 0 && this.lastFrame != 0)
            {
                SoundEffectExtensions.EmitAt(this.flySound, this.Position);
            }
            this.lastFrame = this.CurrentTiming.Frame;
            if (this.FlyingBack)
            {
                if ((double)this.Position.Y > (double)this.Npc.Position.Y)
                {
                    return;
                }
                this.Position      = this.Npc.Position;
                this.CurrentAction = NpcAction.Land;
                this.flySpeed      = Vector2.Zero;
                this.UpdateAction();
                this.FlyingBack = false;
                this.flyRight   = new Vector3?();
            }
            else
            {
                if (this.CameraManager.Frustum.Contains(new BoundingBox(this.Position - Vector3.One, this.Position + Vector3.One)) != ContainmentType.Disjoint)
                {
                    return;
                }
                if (this.MayComeBack)
                {
                    this.OwlInvisible  = true;
                    this.MayComeBack   = false;
                    this.CurrentAction = NpcAction.Idle;
                    this.flySpeed      = Vector2.Zero;
                    this.flyRight      = new Vector3?();
                    this.UpdateAction();
                }
                else
                {
                    ServiceHelper.RemoveComponent <NpcState>(this);
                }
            }
        }