Ejemplo n.º 1
0
        public static bool avoid_rectangulo(double newx, double newy, Vector velocity, Cairo.Rectangle r, Vector location)
        {
            bool reboto;

            reboto = Logica.avoid_linea(newx, newy, velocity, new Cairo.Rectangle(r.X, r.Y, r.X + r.Width, r.Y), location);
            if (reboto)
            {
                return(true);
            }
            reboto = Logica.avoid_linea(newx, newy, velocity, new Cairo.Rectangle(r.X + r.Width, r.Y, r.X + r.Width, r.Y + r.Height), location);
            if (reboto)
            {
                return(true);
            }
            reboto = Logica.avoid_linea(newx, newy, velocity, new Cairo.Rectangle(r.X + r.Width, r.Y + r.Height, r.X, r.Y + r.Height), location);
            if (reboto)
            {
                return(true);
            }
            reboto = Logica.avoid_linea(newx, newy, velocity, new Cairo.Rectangle(r.X, r.Y + r.Height, r.X, r.Y), location);
            if (reboto)
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 2
0
        private void update(BoidCollection boids, List <Obstaculo> C, List <Obstaculo> R, List <Obstaculo> L, double magnitud) //Revisa los limites y calcula los rebotes
        {
            Velocity.add(Acceleration);                                                                                        //Update velocity
            Velocity.limit(Logica.max_speed);

            double newx     = this.Location.X + this.Velocity.X;
            double newy     = this.Location.Y + this.Velocity.Y;
            double velOrigX = this.Velocity.X;
            double velOrigY = this.Velocity.Y;

            Constantes.reboto = false;
            for (int i = 0; i < C.Count() && !Constantes.reboto; i++)
            {
                if (C.ElementAt(i).enable)
                {
                    Logica.avoid_circulo(newx, newy, this.Velocity, C.ElementAt(i).rectangle, this.Location);
                }
            }
            for (int i = 0; i < R.Count() && !Constantes.reboto; i++)
            {
                if (R.ElementAt(i).enable)
                {
                    Logica.avoid_rectangulo(newx, newy, this.Velocity, R.ElementAt(i).rectangle, this.Location);
                }
            }
            for (int i = 0; i < L.Count() && !Constantes.reboto; i++)
            {
                if (L.ElementAt(i).enable)
                {
                    Logica.avoid_linea(newx, newy, this.Velocity, L.ElementAt(i).rectangle, this.Location);
                }
            }



            //rebota o atraviesa los bordes de la pantalla
            if (Logica.rebotar)
            {
                if (newx > Constantes.limites.Right - 10 || newx < Constantes.limites.Left + 10)
                {
                    this.Velocity.X = -1 * this.Velocity.X;
                }

                if (newy > Constantes.limites.Bottom - 40 || newy < Constantes.limites.Top + 20)
                {
                    this.Velocity.Y = -1 * (this.Velocity.Y);
                }
            }

            else if (Logica.atravesar)
            {
                if (newx < 0)
                {
                    LocationNueva.X = Constantes.limites.Width;
                }
                if (newy < 0)
                {
                    LocationNueva.Y = Constantes.limites.Height;
                }
                if (newx > Constantes.limites.Width)
                {
                    LocationNueva.X = 0;
                }
                if (newy > Constantes.limites.Height)
                {
                    LocationNueva.Y = 0;
                }
            }

            Velocity.X *= magnitud;
            Velocity.Y *= magnitud;
            LocationNueva.add(Velocity);

            //Reset acceleration
            Acceleration.X = 0;
            Acceleration.Y = 0;
        }