Ejemplo n.º 1
0
        /// <summary>
        /// Devuelve una imagen de la mascota con el ancho y el alto especificado.
        /// </summary>
        /// <param name="ancho">Ancho de la imagen.</param>
        /// <param name="alto">Alto de la imagen.</param>
        /// <param name="color">El color que se usará como fondo.</param>
        /// <returns>Imagen de la mascota.</returns>
        public Bitmap GenerarImagenMascota(int ancho, int alto, Color color)
        {
            NodoComponente  aux               = componentes.Cab;
            ImageAttributes atributos         = new ImageAttributes();
            Color           colorTransparente = ((Bitmap)ListaImagenes[0]).GetPixel(0, 0);

            atributos.SetColorKey(colorTransparente, colorTransparente);

            Bitmap   imagen   = new Bitmap(ancho, alto);
            Graphics pintador = Graphics.FromImage(imagen);

            pintador.Clear(color);

            int i = 0;

            while (aux != null)
            {
                Bitmap    dibujo  = (Bitmap)ListaImagenes[i];
                Rectangle destino = new Rectangle(ancho / 2 + aux.Info.DatoComponente.DistanciaPuntoReferencia.X, alto + aux.Info.DatoComponente.DistanciaPuntoReferencia.Y + 20, aux.Info.DatoComponente.RectanguloFuente.Width, aux.Info.DatoComponente.RectanguloFuente.Height);
                pintador.DrawImage(dibujo, destino, aux.Info.DatoComponente.RectanguloFuente.X, aux.Info.DatoComponente.RectanguloFuente.Y, aux.Info.DatoComponente.RectanguloFuente.Width, aux.Info.DatoComponente.RectanguloFuente.Height, GraphicsUnit.Pixel, atributos);
                aux = aux.Siguiente;
                i++;
            }

            return(imagen);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Pasa los frames necesarios de la aplicación
        /// </summary>
        public Bitmap PasarFrame()
        {
            NodoComponente  aux       = componentes.Cab;
            ImageAttributes atributos = new ImageAttributes();

            this.pintable.DrawImage(fondo, 0, 0);
            int i;

            i = 0;
            if (estaViva)
            {
                Color color = ((Bitmap)ListaImagenes[0]).GetPixel(0, 0);
                atributos.SetColorKey(color, color);
                while (aux != null)
                {
                    aux.Info.PasarFrame();
                    Rectangle destino = new Rectangle(puntoReferencia.X + aux.Info.DatoComponente.DistanciaPuntoReferencia.X, puntoReferencia.Y + aux.Info.DatoComponente.DistanciaPuntoReferencia.Y, aux.Info.DatoComponente.RectanguloFuente.Width, aux.Info.DatoComponente.RectanguloFuente.Height);
                    Bitmap    dibujo  = (Bitmap)ListaImagenes[i];
                    pintable.DrawImage(dibujo, destino, aux.Info.DatoComponente.RectanguloFuente.X, aux.Info.DatoComponente.RectanguloFuente.Y, aux.Info.DatoComponente.RectanguloFuente.Width, aux.Info.DatoComponente.RectanguloFuente.Height, GraphicsUnit.Pixel, atributos);
                    aux = aux.Siguiente;
                    i++;
                }
            }
            else
            {
                Color color = tumba.GetPixel(0, 0);
                atributos.SetColorKey(color, color);
                pintable.DrawImage(tumba, new Rectangle(puntoReferencia.X - tumba.Width / 2, puntoReferencia.Y - tumba.Height, tumba.Width, tumba.Height), 0, 0, tumba.Width, tumba.Height, GraphicsUnit.Pixel, atributos);
            }
            if (OnImagenCambiada != null)
            {
                OnImagenCambiada(this, bmp);
            }
            return(bmp);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Constructor sin parámetros que inicializa todas las variables a sus valores básicos
        /// </summary>
        public Mascota()
        {
            bmp   = new Bitmap(237, 188);
            fondo = new Bitmap(new DirectorioRaiz().Directorio + "graficos\\silla.jpg");
            tumba = new Bitmap(new DirectorioRaiz().Directorio + "graficos\\tumba.bmp");

            componentes = new ListaComponentes();
            inventario  = new ListaObjetos();

            mascotaSerializable = new MascotaSerializable();
            //Serializar();
            Deserializar();

            ListaImagenes = new ArrayList();
            NodoComponente aux = new NodoComponente();

            aux             = this.componentes.Cab;
            PuntoReferencia = new Point(200, 185);
            Destino         = puntoReferencia;
            while (aux != null)
            {
                ListaImagenes.Add(new Bitmap(new DirectorioRaiz().Directorio + aux.Info.RutaImagen));
                aux = aux.Siguiente;
            }

            GC.Collect();
            animacion = 0;
            pintable  = Graphics.FromImage(bmp);
            girado    = false;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Selecciona la animación que se le pasa por parámetros (andar o estarse quieto)
        /// </summary>
        /// <param name="animacion">Número de la animación a seleccionar</param>
        public void SeleccionarAnimacion(int animacion)
        {
            this.animacion = animacion;
            NodoComponente aux = this.componentes.Cab;

            while (aux != null)
            {
                aux.Info.SeleccionarAnimacion(animacion, girado);
                aux = aux.Siguiente;
            }
        }