Exemplo n.º 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);
        }
Exemplo n.º 2
0
        public override void Update()
        {
            Point2I loc = (Point2I)(Physics.PositionedCollisionBox.Center / GameSettings.TILE_SIZE);

            // Check if tile location has changed.
            if (loc != tileLocation)
            {
                Rectangle2F rect = new Rectangle2F(loc * GameSettings.TILE_SIZE,
                                                   new Vector2F(GameSettings.TILE_SIZE, GameSettings.TILE_SIZE));

                // Only change tile locations if the collision box is fully contained inside the tile.
                if (rect.Contains(physics.PositionedCollisionBox))
                {
                    tileLocation = loc;

                    // Check for seed bouncers in the new location.
                    foreach (Tile tile in RoomControl.TileManager.GetTilesAtLocation(tileLocation))
                    {
                        TileSeedBouncer seedBouncer = tile as TileSeedBouncer;
                        if (seedBouncer != null)
                        {
                            OnCollideTile(seedBouncer, false);
                            break;
                        }
                    }
                }
            }

            base.Update();
        }