예제 #1
0
        internal bool PerformIdleBehavior(Companion companion, GameTime time, float[] arguments)
        {
            // Determine the behavior logic to apply
            if (this.behavior == Behavior.WANDER)
            {
                if (companion.IsFlying())
                {
                    float dashMultiplier     = 2f;
                    int   minTimeBetweenDash = 5000;
                    if (arguments != null && arguments.Length >= 2)
                    {
                        dashMultiplier     = arguments[0];
                        minTimeBetweenDash = (int)arguments[1];
                    }

                    this.behaviorTimer -= time.ElapsedGameTime.Milliseconds;
                    if (this.behaviorTimer <= 0)
                    {
                        this.motionMultiplier = dashMultiplier;
                        this.behaviorTimer    = Game1.random.Next(minTimeBetweenDash, minTimeBetweenDash * 2);
                    }

                    // Get the current motion multiplier
                    companion.position.Value += companion.motion.Value * this.motionMultiplier;
                    this.motionMultiplier    -= 0.0005f * time.ElapsedGameTime.Milliseconds;
                    if (this.motionMultiplier <= 0f)
                    {
                        this.motionMultiplier = 1f;
                    }

                    companion.motion.X += Game1.random.Next(-1, 2) * 0.1f;
                    companion.motion.Y += Game1.random.Next(-1, 2) * 0.1f;

                    if (companion.motion.X < -1f)
                    {
                        companion.motion.X = -1f;
                    }
                    if (companion.motion.X > 1f)
                    {
                        companion.motion.X = 1f;
                    }
                    if (companion.motion.Y < -1f)
                    {
                        companion.motion.Y = -1f;
                    }
                    if (companion.motion.Y > 1f)
                    {
                        companion.motion.Y = 1f;
                    }

                    return(false);
                }
                else
                {
                    return(PerformCollisionWander(companion, time));
                }
            }
            else if (this.behavior == Behavior.HOVER)
            {
                var gravity = -0.5f;
                if (arguments != null)
                {
                    if (arguments.Length > 0)
                    {
                        gravity = arguments[0];
                    }
                }

                if (companion.yJumpOffset == 0)
                {
                    companion.jumpWithoutSound(5);
                    companion.yJumpGravity = Math.Abs(gravity) * -1;
                }

                return(false);
            }
            else if (this.behavior == Behavior.JUMPER)
            {
                var gravity   = -0.5f;
                var jumpScale = 10f;
                var randomJumpBoostMultiplier = 2f;
                if (arguments != null)
                {
                    if (arguments.Length > 0)
                    {
                        gravity = arguments[0];
                    }
                    if (arguments.Length > 1)
                    {
                        jumpScale = arguments[1];
                    }
                    if (arguments.Length > 2)
                    {
                        randomJumpBoostMultiplier = arguments[2];
                    }
                }


                this.behaviorTimer -= time.ElapsedGameTime.Milliseconds;
                if (this.behaviorTimer <= 0)
                {
                    this.behaviorTimer = Game1.random.Next(1000, 5000);

                    if (Game1.random.NextDouble() <= 0.5)
                    {
                        this.destinationTile = Utility.getRandomAdjacentOpenTile(companion.getTileLocation(), companion.currentLocation) * 64f;
                    }
                }

                Vector2 targetPosition   = this.destinationTile;
                Vector2 smoothedPosition = Vector2.Lerp(companion.position, targetPosition, 0.02f);
                companion.PerformJumpMovement(jumpScale, randomJumpBoostMultiplier, gravity, smoothedPosition);

                return(true);
            }
            else
            {
                return(true);
            }
        }