コード例 #1
0
        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();
        }
コード例 #2
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();
        }