Example #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RabbitBehavior" /> class.
 /// </summary>
 public RabbitBehavior()
 {
     this.velocity         = new Vector2(0.2f, 0);
     this.initialDirection = Vector2.UnitX;
     this.State            = Rabbit.RabbitState.still;
     this.stillTime        = TimeSpan.Zero;
 }
Example #2
0
        /// <summary>
        /// Applies the impulse.
        /// </summary>
        public void ApplyImpulse()
        {
            if (this.state == Rabbit.RabbitState.dead ||
                this.state == Rabbit.RabbitState.dying)
            {
                return;
            }

            // Position
            this.position.X = transform.X;
            this.position.Y = transform.Y;

            Vector2 direction = this.position - this.moonPosition;
            //float distanceLength = direction.Length();
            float distanceLenghtSquare = direction.LengthSquared();

            //float distanceRange = this.gravityRadio - this.moonRadio;
            //float maxAngle = 120;
            //float minAngle = 30;
            //float angleRange = maxAngle - minAngle;
            direction.Normalize();

            //this.velocity += Utils.RotateVectorAroundPoint(direction * 0.25f, this.moonPosition, 30);
            this.velocity += Utils.RotateVectorAroundPoint(direction * 5000 / distanceLenghtSquare, this.moonPosition, 30);
            //this.velocity += Utils.RotateVectorAroundPoint(direction * 0.25f, this.moonPosition, minAngle + ((distanceLength - this.moonRadio) * angleRange) / distanceRange);

            this.State = Rabbit.RabbitState.afloat;
        }
Example #3
0
        /// <summary>
        /// Applies the impulse.
        /// </summary>
        public void ApplyImpulse()
        {
            if (this.state == Rabbit.RabbitState.dead ||
                this.state == Rabbit.RabbitState.dying)
            {
                return;
            }

            // Position
            this.position.X = transform.X;
            this.position.Y = transform.Y;

            Vector2 direction = this.position - this.moonPosition;

            float distanceLenghtSquare = direction.LengthSquared();

            direction.Normalize();

            //this.velocity += Utils.RotateVectorAroundPoint(direction * 5000 / distanceLenghtSquare, this.moonPosition, 30);
            this.velocity += Utils.RotateVectorAroundPoint(direction * 5000 / distanceLenghtSquare, this.moonPosition, 30);

            this.State = Rabbit.RabbitState.afloat;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="RabbitBehavior" /> class.
 /// </summary>
 public RabbitBehavior()
 {
     this.velocity = new Vector2(0.2f, 0);
     this.initialDirection = Vector2.UnitX;
     this.State = Rabbit.RabbitState.still;
     this.stillTime = TimeSpan.Zero;
 }
        /// <summary>
        /// Applies the impulse.
        /// </summary>
        public void ApplyImpulse()
        {
            if (this.state == Rabbit.RabbitState.dead ||
                this.state == Rabbit.RabbitState.dying)
            {
                return;
            }

            // Position
            this.position.X = transform.X;
            this.position.Y = transform.Y;

            Vector2 direction = this.position - this.moonPosition;

            float distanceLenghtSquare = direction.LengthSquared();
            direction.Normalize();
                        
            //this.velocity += Utils.RotateVectorAroundPoint(direction * 5000 / distanceLenghtSquare, this.moonPosition, 30);
            this.velocity += Utils.RotateVectorAroundPoint(direction * 5000 / distanceLenghtSquare, this.moonPosition, 30);

            this.State = Rabbit.RabbitState.afloat;
        }
        /// <summary>
        /// Allows this instance to execute custom logic during its <c>Update</c>.
        /// </summary>
        /// <param name="gameTime">The game time.</param>
        /// <remarks>
        /// This method will not be executed if the <see cref="T:WaveEngine.Framework.Component" />, or the <see cref="T:WaveEngine.Framework.Entity" />
        /// owning it are not <c>Active</c>.
        /// </remarks>
        protected override void Update(TimeSpan gameTime)
        {
            // Position
            this.position.X = transform.X;
            this.position.Y = transform.Y;

            Vector2 distance = this.moonPosition - this.position;
            float distanceSquare = distance.LengthSquared();

            // CheckCollision            
            float force = this.moonForce * ((this.moonMass * this.mass) / distanceSquare);

            distance.Normalize();

            this.velocity += distance * force;

            this.position += this.velocity * (float)gameTime.TotalMilliseconds;

            Vector2 newDistance = this.moonPosition - this.position;
            float newDistanceLength = newDistance.Length();
            if (newDistanceLength < this.moonRadio)
            {
                this.velocity = Vector2.Zero;

                switch (this.state)
                {
                    case Rabbit.RabbitState.afloat:
                        this.State = Rabbit.RabbitState.still;
                        break;
                    case Rabbit.RabbitState.dying:
                        this.State = Rabbit.RabbitState.dead;
                        break;
                }
            }
            else if (newDistanceLength > this.gravityRadio)
            {
                this.State = Rabbit.RabbitState.dying;
            }
            else
            {
                this.transform.X = this.position.X;
                this.transform.Y = this.position.Y;
            }

            // Rotation
            if (this.state == Rabbit.RabbitState.dying)
            {
                this.transform.Rotation += (float)gameTime.TotalMilliseconds / 250;
            }
            else
            {
                float angle = Vector2.Angle(this.initialDirection, distance);
                this.transform.Rotation = -angle;
            }

            // Still Time
            if (this.state == Rabbit.RabbitState.still)
            {
                this.stillTime += gameTime;
                if (this.stillTime > TimeSpan.FromSeconds(3))
                {
                    this.State = Rabbit.RabbitState.dead;
                }
            }
            else
            {
                this.stillTime = TimeSpan.Zero;
            }
        }
Example #7
0
        /// <summary>
        /// Allows this instance to execute custom logic during its <c>Update</c>.
        /// </summary>
        /// <param name="gameTime">The game time.</param>
        /// <remarks>
        /// This method will not be executed if the <see cref="T:WaveEngine.Framework.Component" />, or the <see cref="T:WaveEngine.Framework.Entity" />
        /// owning it are not <c>Active</c>.
        /// </remarks>
        protected override void Update(TimeSpan gameTime)
        {
            // Position
            this.position.X = transform.X;
            this.position.Y = transform.Y;

            Vector2 distance       = this.moonPosition - this.position;
            float   distanceSquare = distance.LengthSquared();

            // CheckCollision
            float force = this.moonForce * ((this.moonMass * this.mass) / distanceSquare);

            distance.Normalize();

            this.velocity += distance * force;

            this.position += this.velocity * (float)gameTime.TotalMilliseconds;

            Vector2 newDistance       = this.moonPosition - this.position;
            float   newDistanceLength = newDistance.Length();

            if (newDistanceLength < this.moonRadio)
            {
                this.velocity = Vector2.Zero;

                switch (this.state)
                {
                case Rabbit.RabbitState.afloat:
                    this.State = Rabbit.RabbitState.still;
                    break;

                case Rabbit.RabbitState.dying:
                    this.State = Rabbit.RabbitState.dead;
                    break;
                }
            }
            else if (newDistanceLength > this.gravityRadio)
            {
                this.State = Rabbit.RabbitState.dying;
            }
            else
            {
                this.transform.X = this.position.X;
                this.transform.Y = this.position.Y;
            }

            // Rotation
            if (this.state == Rabbit.RabbitState.dying)
            {
                this.transform.Rotation += (float)gameTime.TotalMilliseconds / 250;
            }
            else
            {
                float angle = Vector2.Angle(this.initialDirection, distance);
                this.transform.Rotation = -angle;
            }

            // Still Time
            if (this.state == Rabbit.RabbitState.still)
            {
                this.stillTime += gameTime;
                if (this.stillTime > TimeSpan.FromSeconds(3))
                {
                    this.State = Rabbit.RabbitState.dead;
                }
            }
            else
            {
                this.stillTime = TimeSpan.Zero;
            }
        }
Example #8
0
        /// <summary>
        /// Applies the impulse.
        /// </summary>
        public void ApplyImpulse()
        {
            if (this.state == Rabbit.RabbitState.dead ||
                this.state == Rabbit.RabbitState.dying)
            {
                return;
            }

            // Position
            this.position.X = transform.X;
            this.position.Y = transform.Y;

            Vector2 direction = this.position - this.moonPosition;
            //float distanceLength = direction.Length();
            float distanceLenghtSquare = direction.LengthSquared();
            //float distanceRange = this.gravityRadio - this.moonRadio;
            //float maxAngle = 120;
            //float minAngle = 30;
            //float angleRange = maxAngle - minAngle;
            direction.Normalize();

            //this.velocity += Utils.RotateVectorAroundPoint(direction * 0.25f, this.moonPosition, 30); 
            this.velocity += Utils.RotateVectorAroundPoint(direction * 5000 / distanceLenghtSquare, this.moonPosition, 30);
            //this.velocity += Utils.RotateVectorAroundPoint(direction * 0.25f, this.moonPosition, minAngle + ((distanceLength - this.moonRadio) * angleRange) / distanceRange);

            this.State = Rabbit.RabbitState.afloat;
        }