private void SetStates(SwitchEnum star1, SwitchEnum star2, SwitchEnum star3)
        {
            float delay = 0;
            float delta = 0.5f;

            IGameAction animations = null;

            if (this.Owner != null && this.Owner.Scene != null)
            {
                animations = this.Owner.Scene.CreateEmptyGameAction();
            }

            if (this.star1Component != null)
            {
                this.star1Component.State = star1;

                if (star1 == SwitchEnum.ON)
                {
                    delay += delta;
                    animations.ContinueWith(this.CreateStarAnimation(this.star1Component.Owner, delay));
                }
            }

            if (this.star2Component != null)
            {
                this.star2Component.State = star2;

                if (star2 == SwitchEnum.ON)
                {
                    delay += delta;
                    animations.ContinueWith(this.CreateStarAnimation(this.star2Component.Owner, delay));
                }
            }

            if (this.star3Component != null)
            {
                this.star3Component.State = star3;

                if (star3 == SwitchEnum.ON)
                {
                    delay += delta;
                    animations.ContinueWith(this.CreateStarAnimation(this.star3Component.Owner, delay));
                }
            }

            if (animations != null)
            {
                animations.Run();
            }
        }
Beispiel #2
0
        protected override void Start()
        {
            base.Start();

            IGameAction action = this.CreateDelayGameAction(TimeSpan.FromSeconds(1.0f))
                                 .ContinueWith(new FloatAnimationGameAction(this.teapot, 0.0f, 255.0f, TimeSpan.FromSeconds(1.5f), EaseFunction.None, (v) =>
            {
                this.disappearMaterial.Threshold = v;
            }))
                                 .ContinueWith(new FloatAnimationGameAction(this.teapot, 255.0f, 0.0f, TimeSpan.FromSeconds(1.5f), EaseFunction.None, (v) =>
            {
                this.disappearMaterial.Threshold = v;
            }));

            action.Run();
        }
Beispiel #3
0
        public void MoveTo(Transform3D transform)
        {
            var scene = this.Owner.Scene;

            IGameAction action =
                scene.CreateParallelGameActions(
                    new MoveTo3DGameAction(
                        this.Owner,
                        transform.Position,
                        TimeSpan.FromSeconds(TranslationDuration),
                        EaseFunction.SineInOutEase),
                    new RotateTo3DGameAction(
                        this.Owner,
                        transform.Rotation,
                        TimeSpan.FromSeconds(RotationDuration),
                        EaseFunction.SineInOutEase))
                .WaitAll();

            action.Run();
        }
Beispiel #4
0
        /// <summary>
        /// Perform Run actions
        /// </summary>
        protected override void PerformRun()
        {
            this.CheckEnd();

            if (this.childActions == null)
            {
                if (this.childActionGenerators == null)
                {
                    throw new NullReferenceException("There are no action generators");
                }

                for (int i = 0; i < this.childActionGenerators.Length; i++)
                {
                    this.childActions[i] = this.childActionGenerators[i]();
                }
            }

            for (int i = 0; i < this.childActions.Length; i++)
            {
                IGameAction action = this.childActions[i];

                if (action.State == TaskState.Finished)
                {
                    this.ActionCompleted(action);
                }
                else if (action.State == TaskState.Aborted)
                {
                    this.ActionCancelled(action);
                }
                else if (action.State != TaskState.Running)
                {
                    action.Completed += this.ActionCompleted;
                    action.Cancelled += this.ActionCancelled;

                    action.Run();
                }
            }
        }
        public void MoveTo(Entity destinationEntity)
        {
            var scene = this.Owner.Scene;

            var cameraPoint = FindCameraPosition(this.Owner);

            List <Transform3D> path = calculatePath(this.Owner, cameraPoint, destinationEntity);

            var limitCameraBehavior = Owner.FindComponent <LimitCameraBehavior>();

            limitCameraBehavior.IsActive = false;

            IGameAction action = null;

            if (path.Count() > 1)
            {
                // rotation action
                IGameAction rotationAction = null;
                for (int i = 0; i < path.Count; i++)
                {
                    if (i == 0)
                    {
                        rotationAction = scene.CreateGameAction(
                            new RotateToShortest3DGameAction(
                                Owner,
                                path[i].Rotation,
                                TimeSpan.FromSeconds(TranslationDuration / path.Count),
                                EaseFunction.None,
                                false,
                                true));
                    }
                    else
                    {
                        rotationAction =
                            rotationAction.ContinueWith(
                                scene.CreateGameAction(
                                    new RotateToShortest3DGameAction(
                                        Owner,
                                        path[i].Rotation,
                                        TimeSpan.FromSeconds(TranslationDuration / path.Count),
                                        (i == path.Count - 1) ? EaseFunction.SineOutEase : EaseFunction.None,
                                        false,
                                        true)));
                    }
                }

                // init movement rotation
                var transform = this.Owner.FindComponent <Transform3D>();
                path.Insert(0, transform);
                CatmullRomSpline catmullRomSpline = new CatmullRomSpline(path.ToArray());

                action = scene.CreateParallelGameActions(
                    new FloatAnimationGameAction(
                        this.Owner,
                        0,
                        1,
                        TimeSpan.FromSeconds(TranslationDuration),
                        EaseFunction.SineInOutEase,
                        (lerp) =>
                {
                    transform.Position = catmullRomSpline.GetPosition(lerp);
                }),
                    rotationAction
                    )
                         .WaitAll();
            }
            else
            {
                action = scene.CreateParallelGameActions(
                    new MoveTo3DGameAction(
                        this.Owner,
                        path.Last().Position,
                        TimeSpan.FromSeconds(TranslationDuration),
                        EaseFunction.SineInOutEase),
                    new RotateToShortest3DGameAction(
                        this.Owner,
                        path.Last().Rotation,
                        TimeSpan.FromSeconds(TranslationDuration),
                        EaseFunction.SineOutEase,
                        false,
                        true))
                         .WaitAll();
            }

            if (action != null)
            {
                action.Run();
                action.Completed += (obj) =>
                {
                    limitCameraBehavior.OriginalRotation = path.Last().Rotation;
                    limitCameraBehavior.IsActive         = true;
                    var destinationLimitCameraBehavior = destinationEntity.FindComponent <LimitCameraBehavior>();
                    limitCameraBehavior.MaxPitch = destinationLimitCameraBehavior?.MaxPitch ?? LimitCameraBehavior.DefaultMaxPitch;
                    limitCameraBehavior.MaxYaw   = destinationLimitCameraBehavior?.MaxYaw ?? LimitCameraBehavior.DefaultMaxYaw;

                    // Invoke subscribed
                    AnimationCompleted?.Invoke(this, new EventArgs());
                };
            }
        }
        protected override void Update(TimeSpan gameTime)
        {
            if (this.isDeadAnimation)
            {
                return;
            }

            if (this.firstUpdate)
            {
                this.aabbBoundingBox.Min = this.currentPosition - this.collider.BoundingBox.HalfExtent;
                this.aabbBoundingBox.Max = this.currentPosition + this.collider.BoundingBox.HalfExtent;

                this.firstUpdate = false;
            }

            if (this.currentPosition != this.desiredPosition)
            {
                this.transform.Position = Vector3.SmoothStep(this.currentPosition, this.desiredPosition, this.JumpSmoothStep * (float)gameTime.TotalSeconds);
                this.currentPosition    = this.transform.Position;

                this.aabbBoundingBox.Min = this.currentPosition - this.collider.BoundingBox.HalfExtent;
                this.aabbBoundingBox.Max = this.currentPosition + this.collider.BoundingBox.HalfExtent;
            }


            if (this.currentOrientation != this.desiredOrientation)
            {
                this.currentOrientation    = Quaternion.Slerp(this.currentOrientation, this.desiredOrientation, this.JumpSmoothStep * (float)gameTime.TotalSeconds);
                this.transform.Orientation = this.currentOrientation;
            }

            if (this.currentScale != this.desiredScale)
            {
                this.currentScale    = Vector3.SmoothStep(this.currentScale, this.desiredScale, this.scaleAnimationSpeed * (float)gameTime.TotalSeconds);
                this.transform.Scale = this.currentScale;
            }


            var vehicles = this.EntityManager.FindAllByTag(Constants.TAG_VEHICLE);

            foreach (Entity vehicle in vehicles)
            {
                var vehicleBehavior = vehicle.FindComponent <VehicleBehavior>();

                // TODO: Workaround: check if position Z >0 cause vehicle boundingboxe create in <0,0,0> and collides
                if (this.currentPosition.Z > 2)
                {
                    if (this.aabbBoundingBox.Intersects(vehicleBehavior.AABBBoundingBox))
                    {
                        // Input stop
                        var inputBehavior = this.Owner.FindComponent <PlayerInputBehavior>();
                        inputBehavior.IgnoreInput = true;

                        var vector = this.currentPosition - vehicle.FindComponent <Transform3D>().Position;
                        var angle  = Vector2.Angle(Vector2.UnitX, new Vector2(vector.X, vector.Z));

                        if (this.audioService != null)
                        {
                            this.audioService.Play(Audio.Sfx.chicken1_wav);
                        }

                        if (this.animationService != null)
                        {
                            IGameAction animation = null;
                            if (angle > MathHelper.PiOver4 && angle < 3 * MathHelper.PiOver4)
                            {
                                // look up on this dead
                                this.desiredOrientation    = this.upOrientation;
                                this.currentOrientation    = this.desiredOrientation;
                                this.transform.Orientation = this.currentOrientation;

                                animation = animationService.CreateDeadAnimation(this.Owner, transform, new Vector3(2f, 1.2f, 0.2f));

                                animation.Delay(TimeSpan.FromMilliseconds(250))
                                .ContinueWithAction(() =>
                                {
                                    if (this.audioService != null)
                                    {
                                        this.audioService.Play(Audio.Sfx.deadDrop1_wav);
                                    }
                                })
                                .ContinueWith(animationService.CreateFallAnimation(this.Owner, transform));
                            }
                            else
                            {
                                animation = animationService.CreateDeadAnimation(this.Owner, transform, new Vector3(2f, 0.2f, 1.2f));
                            }

                            animation
                            .Delay(TimeSpan.FromMilliseconds(1500))
                            .ContinueWithAction(() =>
                            {
                                this.BackToInitial();
                            });

                            animation.Run();
                        }

                        this.isDeadAnimation = true;
                    }
                }
            }

            this.UpdateScore();
        }
Beispiel #7
0
        protected override void Update(TimeSpan gameTime)
        {
            if (this.isDeadAnimation)
            {
                return;
            }

            if (this.currentPosition != this.desiredPosition)
            {
                this.transform.Position = Vector3.SmoothStep(this.currentPosition, this.desiredPosition, this.JumpSmoothStep * (float)gameTime.TotalSeconds);
                this.currentPosition    = this.transform.Position;
            }


            if (this.currentOrientation != this.desiredOrientation)
            {
                this.currentOrientation    = Quaternion.Slerp(this.currentOrientation, this.desiredOrientation, this.JumpSmoothStep * (float)gameTime.TotalSeconds);
                this.transform.Orientation = this.currentOrientation;
            }

            if (this.currentScale != this.desiredScale)
            {
                this.currentScale    = Vector3.SmoothStep(this.currentScale, this.desiredScale, this.scaleAnimationSpeed * (float)gameTime.TotalSeconds);
                this.transform.Scale = this.currentScale;
            }

            // TODO: Workaround: check if position Z >0 cause vehicle boundingboxe create in <0,0,0> and collides
            if (this.currentPosition.Z > 2)
            {
                this.physicBody.ContactTest(this.collisionList);

                if (this.collisionList.Count > 0)
                {
                    // Input stop
                    var inputBehavior = this.Owner.FindComponent <PlayerInputBehavior>();
                    inputBehavior.IgnoreInput = true;

                    var vector = this.currentPosition - collisionList[0].ThisBody.Transform3D.Position;
                    var angle  = Vector2.Angle(Vector2.UnitX, new Vector2(vector.X, vector.Z));

                    if (this.audioService != null)
                    {
                        this.audioService.Play(Audio.Sfx.chicken1_wav);
                    }

                    if (this.animationService != null)
                    {
                        IGameAction animation = null;
                        if (angle > MathHelper.PiOver4 && angle < 3 * MathHelper.PiOver4)
                        {
                            // look up on this dead
                            this.desiredOrientation    = this.upOrientation;
                            this.currentOrientation    = this.desiredOrientation;
                            this.transform.Orientation = this.currentOrientation;

                            animation = animationService.CreateDeadAnimation(this.Owner, transform, new Vector3(200f, 120f, 20f));

                            animation.Delay(TimeSpan.FromMilliseconds(250))
                            .ContinueWithAction(() =>
                            {
                                if (this.audioService != null)
                                {
                                    this.audioService.Play(Audio.Sfx.deadDrop1_wav);
                                }
                            })
                            .ContinueWith(animationService.CreateFallAnimation(this.Owner, transform));
                        }
                        else
                        {
                            animation = animationService.CreateDeadAnimation(this.Owner, transform, new Vector3(200f, 20f, 120f));
                        }

                        animation
                        .Delay(TimeSpan.FromMilliseconds(1500))
                        .ContinueWithAction(() =>
                        {
                            this.BackToInitial();
                        });

                        animation.Run();
                    }

                    this.isDeadAnimation = true;
                }
            }

            this.UpdateScore();
        }