Example #1
0
        //-----------------------------------------------------------------------------
        // Seed Bouncing
        //-----------------------------------------------------------------------------

        // Try to bounce off of a seed bouncer tile, returning true if the bounce was successful.
        private bool AttemptBounce(TileSeedBouncer seedBouncer)
        {
            // Determine the angle the we are moving in.
            angle = Angles.NearestFromVector(physics.Velocity);

            // Determine the angle to bounce off at.
            int newAngle            = -1;
            int bouncerAngle        = seedBouncer.Angle;
            int bouncerAngleReverse = Angles.Reverse(seedBouncer.Angle);
            int plus1  = Angles.Add(angle, 1, WindingOrder.Clockwise);
            int plus2  = Angles.Add(angle, 2, WindingOrder.Clockwise);
            int minus1 = Angles.Add(angle, 1, WindingOrder.CounterClockwise);

            if (plus2 == bouncerAngle || plus2 == bouncerAngleReverse)
            {
                newAngle = Angles.Reverse(angle);
            }
            else if (plus1 == bouncerAngle || plus1 == bouncerAngleReverse)
            {
                newAngle = Angles.Add(angle, 2, WindingOrder.Clockwise);
            }
            else if (minus1 == bouncerAngle || minus1 == bouncerAngleReverse)
            {
                newAngle = Angles.Add(angle, 2, WindingOrder.CounterClockwise);
            }

            // Start moving in the new angle.
            if (newAngle >= 0)
            {
                angle            = newAngle;
                physics.Velocity = Angles.ToVector(angle) * physics.Velocity.Length;
                return(true);
            }
            return(false);
        }
Example #2
0
        //-----------------------------------------------------------------------------
        // Projectile Methods
        //-----------------------------------------------------------------------------

        protected void Crash(bool isInitialCollision)
        {
            if (crashAnimation != null)
            {
                // Create crash effect.
                Effect effect;

                if (bounceOnCrash)
                {
                    effect = new Effect();
                    effect.CreateDestroyTimer(32);
                    effect.EnablePhysics(PhysicsFlags.HasGravity);
                    if (!isInitialCollision)
                    {
                        effect.Physics.Velocity = Angles.ToVector(Angles.Reverse(Angle)) * 0.25f;
                    }
                    effect.Physics.ZVelocity = 1.0f;
                    effect.Physics.Gravity   = 0.07f;
                    effect.Graphics.PlayAnimation(crashAnimation);
                }
                else
                {
                    effect = new Effect(crashAnimation, Graphics.DepthLayer);
                }

                effect.Graphics.IsShadowVisible = false;
                effect.Graphics.DepthLayer      = Graphics.DepthLayer;

                RoomControl.SpawnEntity(effect, position);
                DestroyAndTransform(effect);
            }
            else
            {
                Destroy();
            }

            OnCrash();
        }