Ejemplo n.º 1
0
		public TVViewer()
		{
			// initialize sdl stuff
			screen = Sdl.SDL_SetVideoMode(720, 576, 32, Sdl.SDL_HWSURFACE | Sdl.SDL_DOUBLEBUF);
			yuvOverlay = Sdl.SDL_CreateYUVOverlay(720, 576, Sdl.SDL_YUY2_OVERLAY, screen);
			rect = new Sdl.SDL_Rect(0, 0, 720, 576);
			pixels = Marshal.ReadIntPtr(Marshal.ReadIntPtr(yuvOverlay, 20));
			
			// initialize adapter
			adapter = new Adapter("/dev/video0");
			adapter.SetControlValue(Control.Mute, 0);
			
			// set desired capture method
			adapter.CaptureMethod = CaptureMethod.ReadWrite;
			
			// set video format
			VideoCaptureFormat format = new VideoCaptureFormat(720, 576);
			format.PixelFormat = v4l2_pix_format_id.YUYV;
			format.Field = v4l2_field.Interlaced;
			adapter.SetFormat(format);
			
			adapter.Input = adapter.Inputs[adapter.Inputs.IndexOf("Name", "Television")];
			adapter.Standard = adapter.Standards[adapter.Standards.IndexOf("Name", "PAL")];
			
			Events.Quit += quit;
			Events.KeyboardDown += keyDown;
		}
Ejemplo n.º 2
0
        public Temperatura(int x, int y, int calor)
        {
            Rectangulo = new Sdl.SDL_Rect((short)(x * 32), (short)(y * 32), 32, 32);

            Calor = calor;

            CambiarColor();
        }
Ejemplo n.º 3
0
		private void GfxSetup()
		{
			surfacePtr = Sdl.SDL_SetVideoMode(
				width, 
				height, 
				bpp, 
				flags);
			rect2 = new Sdl.SDL_Rect(
				0,
				0,
				(short) width,
				(short) height);
			Sdl.SDL_SetClipRect(surfacePtr, ref rect2);
		}
Ejemplo n.º 4
0
 /// <summary>
 /// Update an array of rectangles
 /// </summary>
 /// <param name="rectangles">Collection of rectangles to update</param>
 public void Update(Collection<Rectangle> rectangles)
 {
     if (rectangles == null)
     {
         throw new ArgumentNullException("rectangles");
     }
     if (this.disposed)
     {
         throw (new ObjectDisposedException(this.ToString()));
     }
     Sdl.SDL_Rect[] rects = new Sdl.SDL_Rect[rectangles.Count];
     for (int i = 0; i < rectangles.Count; i++)
     {
         rects[i] = Surface.ConvertRectToSdlRect(rectangles[i]);
     }
     Sdl.SDL_UpdateRects(this.Handle, rects.Length, rects);
     GC.KeepAlive(this);
 }
Ejemplo n.º 5
0
        public override void DrawImage(GridCoord point, string image, short width, short height)
        {
            // Convert the width and height into window coords.
            width = (short)(width * (m_windowSizeX / m_camera.ZoomLevelX));
            height = (short)(height * (m_windowSizeY / m_camera.ZoomLevelY));

            // Cache the texture for future use.
            if (!m_textures.ContainsKey(image))
            {
                CacheTexture(image, width, height);
            }

            IntPtr imagePtr = m_textures[image];
            Sdl.SDL_Surface imageSurface = (Sdl.SDL_Surface)System.Runtime.InteropServices.Marshal.PtrToStructure(imagePtr, typeof(Sdl.SDL_Surface));

            // Also resize the texture if necessary
            if ((imageSurface.w != width)
                ||
                (imageSurface.h != height))
            {
                CacheTexture(image, width, height);
            }
            Sdl.SDL_Rect imageRect = new Sdl.SDL_Rect(0, 0, (short)imageSurface.w, (short)imageSurface.h);
            WindowCoord wpoint = GridToWindowCoords(point);
            Sdl.SDL_Rect dstRect = new Sdl.SDL_Rect((short)wpoint.X,(short)wpoint.Y,(short)imageSurface.w,(short)imageSurface.h);
            Sdl.SDL_BlitSurface(imagePtr, ref imageRect, m_surface, ref dstRect);
        }
Ejemplo n.º 6
0
        public static void Run()
        {
            int flags = (Sdl.SDL_HWSURFACE|Sdl.SDL_DOUBLEBUF|Sdl.SDL_ANYFORMAT);
            int bpp = 16;
            int width = 640;
            int height = 480;
            bool quitFlag = false;

            Random rand = new Random();

            string filePath = Path.Combine("..", "..");
            string fileDirectory = "Data";
            string fileName = "SdlExamples.Rectangles.sound.ogg";
            if (File.Exists(fileName))
            {
                filePath = "";
                fileDirectory = "";
            }
            else if (File.Exists(Path.Combine(fileDirectory, fileName)))
            {
                filePath = "";
            }

            string file = Path.Combine(Path.Combine(filePath, fileDirectory), fileName);

            Sdl.SDL_Event evt;

            try
            {
                Sdl.SDL_Init(Sdl.SDL_INIT_EVERYTHING);
                Sdl.SDL_WM_SetCaption("Tao.Sdl Example - Rectangles", "");
                IntPtr surfacePtr = Sdl.SDL_SetVideoMode(
                    width,
                    height,
                    bpp,
                    flags);

                int result = SdlMixer.Mix_OpenAudio(
                    SdlMixer.MIX_DEFAULT_FREQUENCY,
                    (short)SdlMixer.MIX_DEFAULT_FORMAT,
                    2,
                    1024);
                IntPtr chunkPtr = SdlMixer.Mix_LoadMUS(file);

                SdlMixer.MusicFinishedDelegate musicStopped =
                    new SdlMixer.MusicFinishedDelegate(musicHasStopped);
                SdlMixer.Mix_HookMusicFinished(musicStopped);

                result = SdlMixer.Mix_PlayMusic(chunkPtr, 1);
                if (result == -1)
                {
                    Console.WriteLine("Music Error: " + Sdl.SDL_GetError());
                }

                int rmask = 0x00000000;
                int gmask = 0x00ff0000;
                int bmask = 0x0000ff00;
                int amask = 0x000000ff;

                IntPtr rgbSurfacePtr = Sdl.SDL_CreateRGBSurface(
                    flags,
                    width,
                    height,
                    bpp,
                    rmask,
                    gmask,
                    bmask,
                    amask);

                Sdl.SDL_Rect rect = new Sdl.SDL_Rect(
                    0,
                    0,
                    (short)width,
                    (short)height);
                result = Sdl.SDL_FillRect(rgbSurfacePtr, ref rect, 0);

                Sdl.SDL_Rect rect2;

                IntPtr videoInfoPointer = Sdl.SDL_GetVideoInfo();
                if (videoInfoPointer == IntPtr.Zero)
                {
                    throw new ApplicationException(string.Format("Video query failed: {0}", Sdl.SDL_GetError()));
                }

                Sdl.SDL_VideoInfo videoInfo = (Sdl.SDL_VideoInfo)
                    Marshal.PtrToStructure(videoInfoPointer,
                    typeof(Sdl.SDL_VideoInfo));
                Console.WriteLine("Hi There");

                Sdl.SDL_PixelFormat pixelFormat = (Sdl.SDL_PixelFormat)
                    Marshal.PtrToStructure(videoInfo.vfmt,
                    typeof(Sdl.SDL_PixelFormat));

                Console.WriteLine(videoInfo.hw_available);
                Console.WriteLine(videoInfo.wm_available);
                Console.WriteLine(videoInfo.blit_hw);
                Console.WriteLine(videoInfo.blit_hw_CC);
                Console.WriteLine(videoInfo.blit_hw_A);
                Console.WriteLine(videoInfo.blit_sw);
                Console.WriteLine(videoInfo.blit_hw_CC);
                Console.WriteLine(videoInfo.blit_hw_A);
                Console.WriteLine(videoInfo.blit_fill);
                Console.WriteLine(videoInfo.video_mem);
                Console.WriteLine(pixelFormat.BitsPerPixel);
                Console.WriteLine(pixelFormat.BytesPerPixel);
                Console.WriteLine(pixelFormat.Rmask);
                Console.WriteLine(pixelFormat.Gmask);
                Console.WriteLine(pixelFormat.Bmask);
                Console.WriteLine(pixelFormat.Amask);

                int numevents = 10;
                Sdl.SDL_Event[] events = new Sdl.SDL_Event[numevents];
                events[0].type = Sdl.SDL_KEYDOWN;
                events[0].key.keysym.sym = (int)Sdl.SDLK_p;
                events[1].type = Sdl.SDL_KEYDOWN;
                events[1].key.keysym.sym = (int)Sdl.SDLK_z;
                int result2 = Sdl.SDL_PeepEvents(events, numevents, Sdl.SDL_ADDEVENT, Sdl.SDL_KEYDOWNMASK);
                Console.WriteLine("Addevent result: " + result2);

                while (quitFlag == false)
                {
                    result = Sdl.SDL_PollEvent(out evt);

                    if (evt.type == Sdl.SDL_QUIT)
                    {
                        quitFlag = true;
                    }
                    else if (evt.type == Sdl.SDL_KEYDOWN)
                    {
                        if ((evt.key.keysym.sym == (int)Sdl.SDLK_ESCAPE) ||
                            (evt.key.keysym.sym == (int)Sdl.SDLK_q))
                        {
                            quitFlag = true;
                        }
                        if (evt.key.keysym.sym == (int)Sdl.SDLK_p)
                        {
                            Console.WriteLine("Key p event was added");
                        }
                        if (evt.key.keysym.sym == (int)Sdl.SDLK_z)
                        {
                            Console.WriteLine("Key z event was added");
                        }
                    }

                    rect2 = new Sdl.SDL_Rect(
                        (short)rand.Next(-300, width),
                        (short)rand.Next(-300, height),
                        (short)rand.Next(20, 300),
                        (short)rand.Next(20, 300));

                    try
                    {
                        result = Sdl.SDL_FillRect(
                            surfacePtr,
                            ref rect2,
                            rand.Next(100000));
                        result = Sdl.SDL_BlitSurface(
                            rgbSurfacePtr,
                            ref rect2,
                            surfacePtr,
                            ref rect);
                        result = Sdl.SDL_Flip(surfacePtr);
                    }
                    catch (Exception) { }
                }
            }
            catch
            {
                Sdl.SDL_Quit();
                throw;
            }
            finally
            {
                Sdl.SDL_Quit();
            }
        }
Ejemplo n.º 7
0
        public override void DrawText(GridCoord point, int size, string text, System.Drawing.Color colour)
        {
            // Convert the colour
            Sdl.SDL_Color sdlcolour = new Sdl.SDL_Color(colour.R, colour.G, colour.B, colour.A);

            // Render the text to a surface
            IntPtr renderPtr = SdlTtf.TTF_RenderText_Solid(m_mainfont, text, sdlcolour);
            Sdl.SDL_Surface fontSurface = (Sdl.SDL_Surface)System.Runtime.InteropServices.Marshal.PtrToStructure(renderPtr, typeof(Sdl.SDL_Surface));

            // Calculate visibility
            WindowCoord wpoint = GridToWindowCoords(point);
            GridCoord toprightpoint = WindowToGridCoords(new WindowCoord(wpoint.X + fontSurface.w, wpoint.Y));
            GridCoord bottomrightpoint = WindowToGridCoords(new WindowCoord(wpoint.X + fontSurface.w, wpoint.Y + fontSurface.h));
            GridCoord bottomleftpoint = WindowToGridCoords(new WindowCoord(wpoint.X, wpoint.Y + fontSurface.h));

            if (IsVisible(point,toprightpoint,bottomrightpoint,bottomleftpoint))
            {
                // Then blit this to the main window
                Sdl.SDL_Rect fontRect = new Sdl.SDL_Rect(0, 0, (short)fontSurface.w, (short)fontSurface.h);
                Sdl.SDL_Rect dstRect = new Sdl.SDL_Rect((short)wpoint.X,(short)wpoint.Y,(short)fontSurface.w,(short)fontSurface.h);
                Sdl.SDL_BlitSurface(renderPtr, ref fontRect, m_surface, ref dstRect);
            }

            // Clean up the mess
            Sdl.SDL_FreeSurface(renderPtr);
        }
Ejemplo n.º 8
0
 private void SDLBlitScreen(IntPtr p_image, IntPtr p_surface)
 {
     Sdl.SDL_Rect tileRect = new Sdl.SDL_Rect(0, 0, (short)SCREEN_WIDTH, (short)SCREEN_HEIGHT);
     Sdl.SDL_Rect dstRect = new Sdl.SDL_Rect(0, 0, (short)SCREEN_WIDTH, (short)SCREEN_HEIGHT);
     Sdl.SDL_BlitSurface(p_image, ref tileRect, p_surface, ref dstRect);
 }
Ejemplo n.º 9
0
		public void RenderGlyph_Blended()
		{
			this.Quit();
			this.Init();
			IntPtr surfacePtr = VideoSetup();
			Sdl.SDL_Rect rect1 = new Sdl.SDL_Rect(0,0,400,400);
			Sdl.SDL_Rect rect2 = new Sdl.SDL_Rect(0,0,400,400);
			IntPtr fontPtr = SdlTtf.TTF_OpenFont("../../FreeSans.ttf", 12);
			Sdl.SDL_Color colorfg = new Sdl.SDL_Color(254, 0, 0);
			IntPtr fontSurfacePtr = SdlTtf.TTF_RenderGlyph_Blended(fontPtr, 1000, colorfg);
			Assert.IsFalse(fontSurfacePtr == IntPtr.Zero);
			int result = Sdl.SDL_BlitSurface(fontSurfacePtr, ref rect1, surfacePtr, ref rect2);
			Assert.AreEqual(result, 0);
			Sdl.SDL_UpdateRect(surfacePtr, 0,0,400,400);
			Thread.Sleep(sleepTime);
			this.Quit();
		}
Ejemplo n.º 10
0
        private void InitWindow(Configuration configuration)
        {
            width = configuration.resWidth;
            height = configuration.resHeight;
            centerX = width / 2;
            centerY = height / 2;
            bpp = configuration.bpp;
            Name = configuration.title;
            Fullscreen = configuration.fullscreen;
            buttonActionDelegate = new ButtonAction(buttonAction);
            alwaysUpdateMouse = true;
            exceptions = 0;

            if (Fullscreen)
            {
                flags = (/*Sdl.SDL_HWACCEL | Sdl.SDL_HWSURFACE |*/ Sdl.SDL_OPENGL | Sdl.SDL_FULLSCREEN);

                bpp = 32/*System.Windows.Forms.Screen.PrimaryScreen.BitsPerPixel*/;

                /*Width = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;
                Height = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;*/
            }
            else
                flags = (/*Sdl.SDL_HWACCEL | Sdl.SDL_HWSURFACE |*/ Sdl.SDL_OPENGL);

            quitFlag = false;
            try
            {
                Log.Write("InitSDL: " + Width.ToString() + "x" + Height.ToString() + "@" + bpp.ToString());

                Sdl.SDL_Init(Sdl.SDL_INIT_EVERYTHING);
                Sdl.SDL_WM_SetCaption(Name, "");

                IntPtr surfacePtr = Sdl.SDL_SetVideoMode(Width, Height, 32, flags);

                Sdl.SDL_Rect rect2 = new Sdl.SDL_Rect(0, 0, (short)Width, (short)Height);
                Sdl.SDL_SetClipRect(surfacePtr, ref rect2);
                Sdl.SDL_WarpMouse((short)centerX, (short)centerY);
                Log.Write("[" + (short)centerX + ", " + (short)centerY + "] <- [" + centerX + ", " + centerY + "]");
                Sdl.SDL_ShowCursor(0);
            }
            catch
            {
                Sdl.SDL_Quit(); // Vi kallar inte Quit() här för detta är Ändå första funktionen så om det inte går här så blir det så mycket null fel I Quit();
                quitFlag = true;
                Log.Write("Create OpenGL Window Failure", LogType.CriticalError);
                throw;
            }
        }
Ejemplo n.º 11
0
        public static void Inicializar(short ancho, short alto, int colores,bool pantalla_completa)
        {
            BarraHerramientas = 200;

            int bpp;
            int flags = Sdl.SDL_HWSURFACE | Sdl.SDL_DOUBLEBUF | Sdl.SDL_ANYFORMAT;

            Console.WriteLine("Inicializando SDL");

            Hardware.Ancho = ancho;
            Hardware.Alto = alto;

            if(pantalla_completa)
            {
                flags |= Sdl.SDL_FULLSCREEN;
            }

            #region video

            if(Sdl.SDL_Init(Sdl.SDL_INIT_VIDEO) < 0)
            {
                Console.WriteLine("No se pudo inicar el sistema de video");
                Console.WriteLine("ERROR: {0}", Sdl.SDL_GetError());
                Environment.Exit(1);

            }

            bpp = Sdl.SDL_VideoModeOK(ancho, alto, colores, flags);

            if(bpp == 0)
            {
                Console.WriteLine("No se pudo establecer el modo de video");
                Console.WriteLine("ERROR: {0}", Sdl.SDL_GetError());
                Environment.Exit(1);
            }

            pantalla = Sdl.SDL_SetVideoMode(ancho, alto, bpp, flags);
            #endregion

            #region Fuentes

            if(SdlTtf.TTF_Init() < 0)
            {
                Console.WriteLine("No se pudo inicar el manejador de fuentes");
                Console.WriteLine("ERROR: {0}", Sdl.SDL_GetError());
                Environment.Exit(1);
            }

            #endregion

            origen = new Sdl.SDL_Rect(0 , 0, ancho, alto);
            //Sdl.SDL_SetClipRect(pantalla, ref origen);

            #region Sonido

            if(Sdl.SDL_InitSubSystem(Sdl.SDL_INIT_AUDIO) < 0)
            {
                Console.WriteLine("No se pudo inicar el sistema de audio");
                Console.WriteLine("ERROR: {0}", Sdl.SDL_GetError());
                SonidoActivo = false;
            }
            else
            {
                SonidoActivo = true;
            }

            if(SonidoActivo)
            {
                if(SdlMixer.Mix_OpenAudio(22050, Sdl.AUDIO_S16, 2, 4096) < 0)
                {
                    Console.WriteLine("No se pudo inicar el mezclador de audio");
                    Console.WriteLine("ERROR: {0}", Sdl.SDL_GetError());
                    SonidoActivo = false;
                }
            }

            AlmacenSonidos.Inicializar();

            #endregion

            Console.WriteLine("SDL inicializado con exito");

            Sprite boton = new Sprite("Assets/Botones/boton.png");

            fuente = new Fuente("Assets/Fuentes/FreeSansBold.ttf", 14);
            CambiarColorTexto(0,0,0);

            boton.Mover(650, 100);
            boton.Dibujar();
            EscribirTexto("Arriba", 685, 115);

            boton.Mover(650, 154);
            boton.Dibujar();
            EscribirTexto("Abajo", 685, 169);

            boton.Mover(650, 207);
            boton.Dibujar();
            EscribirTexto("Izquierda", 685, 222);

            boton.Mover(650, 270);
            boton.Dibujar();
            EscribirTexto("Derecha", 685, 285);

            boton.Mover(650, 324);
            boton.Dibujar();
            EscribirTexto("Buscar", 685, 339);

            fuente = new Fuente("Assets/Fuentes/FreeSansBold.ttf", 20);
        }
Ejemplo n.º 12
0
		public void zoomSurface()
		{
			this.InitSdl();
			Sdl.SDL_Rect rect1 = new Sdl.SDL_Rect(0,0,400,400);
			Sdl.SDL_Rect rect2 = new Sdl.SDL_Rect(0,0,400,400);
			IntPtr bmpImagePtr = Sdl.SDL_LoadBMP("test.bmp");
			IntPtr zoomSurfacePtr = SdlGfx.zoomSurface(bmpImagePtr, 5, 2, SdlGfx.SMOOTHING_OFF);
			int result = Sdl.SDL_BlitSurface(zoomSurfacePtr, ref rect1, surfacePtr, ref rect2);
			Assert.IsNotNull(zoomSurfacePtr);
			Assert.IsFalse(zoomSurfacePtr==IntPtr.Zero);
			Sdl.SDL_UpdateRect(surfacePtr, 0,0,400,400);
			
			//int results = Sdl.SDL_Flip(surfacePtr);
			Thread.Sleep(sleepTime);
		}
Ejemplo n.º 13
0
 public static void DibujarImagen(IntPtr imagen, short x, short y)
 {
     Sdl.SDL_Rect destino = new Sdl.SDL_Rect(x,y, Ancho, Alto);
     Sdl.SDL_BlitSurface(imagen,ref origen, pantalla, ref destino);
 }
Ejemplo n.º 14
0
        public static void EscribirTexto(string texto, int x, int y)
        {
            if(Object.ReferenceEquals(color, null))
            {
                color = new Sdl.SDL_Color(255, 255, 255);
            }

            IntPtr textoComoImagen = SdlTtf.TTF_RenderText_Solid(fuente.ApuntadorFuente, texto, color);

            if(textoComoImagen == IntPtr.Zero)
            {
                Console.WriteLine("Error al renderizar '{0}'", texto);
            }

            Sdl.SDL_Rect destino = new Sdl.SDL_Rect((short)x,(short)y,Ancho , Alto);

            Sdl.SDL_BlitSurface(textoComoImagen, ref origen, pantalla, ref destino);
        }
Ejemplo n.º 15
0
 private int FillRect(byte r, byte g, byte b, byte a)
 {
     Sdl.SDL_Rect rect = new Sdl.SDL_Rect(0, 0, WIDTH, HEIGHT);
     // TODO : actually put the thing together from the
     // color components passed as parameters
     int pf = 0;
     return Sdl.SDL_FillRect(Sdl.SDL_GetVideoSurface(), ref rect, pf);
 }
Ejemplo n.º 16
0
		public void UpdateRects()
		{
			//TODO: Must figure out a real test for this method.
			IntPtr surfacePtr = VideoSetup();
			Sdl.SDL_Rect rect = new Sdl.SDL_Rect(100,100,100,100);
			Sdl.SDL_Rect rect2 = new Sdl.SDL_Rect(150,150,150,150);
			Sdl.SDL_Rect[] rects = {
									   new Sdl.SDL_Rect(100,100,100,100), 
									   new Sdl.SDL_Rect(150,150,150,150)
								   };
			Sdl.SDL_UpdateRects(surfacePtr, rects.Length, rects);
			Sdl.SDL_FreeSurface(surfacePtr);
		}
Ejemplo n.º 17
0
        private void ConfeccionarCamino()
        {
            int intentos;
            int repeticiones = ITERACIONES;
            int castigo;

            Direccion direccion;
            Random random = new Random(System.DateTime.Now.Millisecond);

            int origen = kibus.OnToyY + kibus.OnToyX * 20;
            int destino = casa.OnToyY + casa.OnToyX * 20;
            //Setear los 2 nodos iniciales, origen y destino

            rectanguloOrigen = kibus.GetRectangulo();

            while(repeticiones-->0)
            {
                Console.WriteLine("Iteracion #" + (ITERACIONES - repeticiones));
                //Volver a iniciar los valores;
                nodosVisitados = new Nodo[20*20];
                Nodo.CantidadNodosVisitados = 0;
                Conexion.conexionesUsadas = 0;

                nodosVisitados[destino] = new Nodo();
                nodosVisitados[origen] = new Nodo();

                kibus.Mover(rectanguloOrigen);

                while(kibus.OnToyX != casa.OnToyX || kibus.OnToyY != casa.OnToyY)
                {
                    modoGrafico = Hardware.TeclaPulsada(Sdl.SDLK_g);

                    if(modoGrafico)
                    {
                        DibujarTodo();
                        Hardware.EscribirTexto("Entrenando", 641, 10);
                        Hardware.RefrescarPantalla();
                    }

                    int anterior;
                    int actual;
                    intentos = 0;
                    Sdl.SDL_Rect rectTemp = kibus.GetRectangulo();
                    do
                    {
                        kibus.Mover(rectTemp);
                        do
                        {

                            direccion = (Direccion)random.Next(0, (int)Direccion.MISINGNO);
                            intentos++;

                        }while(!IntentarMover(kibus, direccion, false));

                        anterior = kibus.OnToyY + kibus.OnToyX * 20;

                        kibus.Mover(direccion);

                        actual = kibus.OnToyY + kibus.OnToyX * 20;

                        if(nodosVisitados[actual] == null)
                        {
                            nodosVisitados[actual] = new Nodo();
                            break;
                        }

                    }while(intentos < 8);

                    Conexion cnxDestino;

                    if(nodosVisitados[anterior].conexiones[(int)direccion] == null)
                    {
                        cnxDestino = new Conexion();
                        cnxDestino.direccionUsada = direccion;
                    }
                    else
                    {
                        cnxDestino = nodosVisitados[anterior].conexiones[(int)direccion];
                    }

                    cnxDestino.NodoConexion = nodosVisitados[actual];

                    nodosVisitados[anterior].conexiones[(int)direccion] = cnxDestino;

                    if(modoGrafico)
                    {
                        Hardware.Pausar(10);
                    }
                }

                //Console.WriteLine("CASA: {0},{1}", casa.OnToyX,casa.OnToyY);
                //Console.WriteLine("KIBU: {0},{1}", kibus.OnToyX,kibus.OnToyY);

                //Seteo de los valores minimos y máximos
                if(Conexion.conexionesUsadas > maximo) maximo = Conexion.conexionesUsadas;
                if(Conexion.conexionesUsadas < minimo) minimo = Conexion.conexionesUsadas;

                mediaHistorica = (maximo + minimo)/2;

                castigo = /*Math.Abs(*/Conexion.conexionesUsadas - mediaHistorica/*)*/;

                Console.WriteLine("Maximo :\t" + maximo);
                Console.WriteLine("Minimo :\t" + minimo);
                Console.WriteLine("Media  :\t" + mediaHistorica);
                Console.WriteLine("Conexiones:\t" + Conexion.conexionesUsadas);
                Console.WriteLine("Castigo:\t" + castigo);
                Console.WriteLine(".------------------.");
                actualizarMundoValorifico(nodosVisitados, castigo);
            }
        }
Ejemplo n.º 18
0
        public static void Run()
        {
            int flags = (Sdl.SDL_HWSURFACE | Sdl.SDL_DOUBLEBUF | Sdl.SDL_ANYFORMAT);
            int bpp = 16;
            int width = 640;
            int height = 480;
            bool quitFlag = false;

            Random rand = new Random();

            //string musicFile = "Data/SdlExamples.Reactangles.sound.ogg";

            Sdl.SDL_Event evt;

            try
            {
                Sdl.SDL_Init(Sdl.SDL_INIT_EVERYTHING);
                Sdl.SDL_WM_SetCaption("Tao.Sdl Example - GfxPrimitives", "");
                IntPtr surfacePtr = Sdl.SDL_SetVideoMode(
                    width,
                    height,
                    bpp,
                    flags);

                Sdl.SDL_Rect rect2 =
                    new Sdl.SDL_Rect(0, 0, (short)width, (short)height);
                Sdl.SDL_SetClipRect(surfacePtr, ref rect2);
                while (quitFlag == false)
                {
                    Sdl.SDL_PollEvent(out evt);

                    if (evt.type == Sdl.SDL_QUIT)
                    {
                        quitFlag = true;
                    }
                    else if (evt.type == Sdl.SDL_KEYDOWN)
                    {
                        if ((evt.key.keysym.sym == (int)Sdl.SDLK_ESCAPE) ||
                            (evt.key.keysym.sym == (int)Sdl.SDLK_q))
                        {
                            quitFlag = true;
                        }
                    }

                    try
                    {
                        SdlGfx.filledCircleRGBA(surfacePtr, (short)rand.Next(10, width - 100), (short)rand.Next(10, height - 100), (short)rand.Next(10, 100), (byte)rand.Next(255), (byte)rand.Next(255), (byte)rand.Next(255), (byte)rand.Next(255));
                        Sdl.SDL_Flip(surfacePtr);
                        Thread.Sleep(100);
                    }
                    catch (Exception) { }
                }
            }
            catch
            {
                Sdl.SDL_Quit();
                throw;
            }
            finally
            {
                Sdl.SDL_Quit();
            }
        }
Ejemplo n.º 19
0
 // Private (auxiliar) methods
 
 private static void drawHiddenImage(IntPtr image, int x, int y)
 {
   Sdl.SDL_Rect origin = new Sdl.SDL_Rect(0,0,width,height);
   Sdl.SDL_Rect dest = new Sdl.SDL_Rect((short) x, (short) y,
     width,height);
   Sdl.SDL_BlitSurface(image, ref origin, hiddenScreen, ref dest);
 }
Ejemplo n.º 20
0
 private void SDLBlitSprite(IntPtr p_image, IntPtr p_surface, int x, int y)
 {
     Sdl.SDL_Rect tileRect = new Sdl.SDL_Rect(0, 0, 50, 50);
     Sdl.SDL_Rect dstRect = new Sdl.SDL_Rect((short)x, (short)y, 50, 50);
     Sdl.SDL_BlitSurface(p_image, ref tileRect, p_surface, ref dstRect);
 }
Ejemplo n.º 21
0
 public override void DrawSplash()
 {
     IntPtr imagePtr = SdlImage.IMG_Load("images/Octo-Image.jpg");
     Sdl.SDL_Surface imageSurface = (Sdl.SDL_Surface)System.Runtime.InteropServices.Marshal.PtrToStructure(imagePtr, typeof(Sdl.SDL_Surface));
     Sdl.SDL_Rect imageRect = new Sdl.SDL_Rect(0, 0, (short)imageSurface.w, (short)imageSurface.h);
     Sdl.SDL_Rect dstRect = new Sdl.SDL_Rect(100,100,(short)imageSurface.w,(short)imageSurface.h);
     Sdl.SDL_BlitSurface(imagePtr, ref imageRect, m_surface, ref dstRect);
 }
Ejemplo n.º 22
0
		public void FillRectAndFlip()
		{
			IntPtr surfacePtr = VideoSetup();
			Assert.IsNotNull(surfacePtr);
			Sdl.SDL_Rect rect = new Sdl.SDL_Rect(100,100,100,100);
			Sdl.SDL_FillRect(surfacePtr, ref rect, 10000);
			int resultFlip = Sdl.SDL_Flip(surfacePtr);
			Thread.Sleep(sleepTime);

			Sdl.SDL_Rect rect2 = new Sdl.SDL_Rect(150,150,150,150);
			int result2 = Sdl.SDL_FillRect(surfacePtr, ref rect2, 1000);
			Assert.AreEqual(result2, 0); 
			resultFlip = Sdl.SDL_Flip(surfacePtr);
			Assert.AreEqual(resultFlip, 0); 
			Thread.Sleep(sleepTime);

			int result3 = Sdl.SDL_FillRect(surfacePtr, ref rect, 5000);
			Assert.AreEqual(result3, 0); 
			resultFlip = Sdl.SDL_Flip(surfacePtr);
			
			Assert.AreEqual(resultFlip, 0); 
			Thread.Sleep(sleepTime);
			Sdl.SDL_FreeSurface(surfacePtr);
		}
Ejemplo n.º 23
0
        public bool DrawGlScene()
        {
            if(this.fieldArr != null)
            {
                Sdl.SDL_Rect screenrect = new Sdl.SDL_Rect(0, 0, (short)SCREEN_WIDTH, (short)SCREEN_HEIGHT);

                Sdl.SDL_FillRect(ptrSurface, ref screenrect, 0);

                double moveDelta = (((DateTime.Now.Ticks - this.moveStartTicks) / 10000f) / (250f*(double)this.playerMovementSpeed));
                if(moveDelta > 1.0f)
                    moveDelta = 1.0f;

                Point deltaPoint = RenderManager.deltaPoint(this.playerPosOld, this.playerPos);

                int playerXmove = (int)((this.playerPosOld.X * fieldSize) + (deltaPoint.X * fieldSize * moveDelta));
                int playerYmove = (int)((this.playerPosOld.Y * fieldSize) + (deltaPoint.Y * fieldSize * moveDelta));

                if(playerXmove < 0)
                    playerXmove = 0;
                if(playerXmove >= this.fieldArr.GetLength(0) * fieldSize)
                    playerXmove = this.fieldArr.GetLength(0) * fieldSize;
                if(playerYmove < 0)
                    playerYmove = 0;
                if(playerYmove >= this.fieldArr.GetLength(1) * fieldSize)
                    playerYmove = this.fieldArr.GetLength(1) * fieldSize;

                int offsetX = (viewportWidth / 2) - playerXmove;
                int offsetY = (viewportHeight / 2) - playerYmove;
                int playerX = (viewportWidth / 2);
                int playerY = (viewportHeight / 2);

                for(int x = 0; x < this.fieldArr.GetLength(0); x++)
                {
                    for(int y = 0; y < this.fieldArr.GetLength(1); y++)
                    {
                        if(this.fieldArr[x,y] != null)
                        {
                            // Render Field Texture
                            SDLBlitSprite(this.fieldArr[x,y].getType().getImage(), ptrSurface, offsetX + (x * fieldSize), offsetY + (y * fieldSize));

                            Entity f_ent = this.fieldArr[x,y].getEntity();
                            Loot f_loot = this.fieldArr[x,y].getLoot();

                            if(f_ent != null && !(f_ent is Player))
                                SDLBlitSprite(f_ent.getTexture(), ptrSurface, offsetX + (x * fieldSize), offsetY + (y * fieldSize));

                            if(f_loot != null)
                                SDLBlitSprite(f_loot.getTexture(), ptrSurface, offsetX + (x * fieldSize), offsetY + (y * fieldSize));
                        }
                    }
                }

                foreach(Bullet bullet in GameManager.getInstance().getMap().getBullets())
                {
                    Point position = bullet.getPosition();
                    SDLBlitSprite(bullet.getTexture(), ptrSurface, offsetX + (position.X * fieldSize), offsetY + (position.Y * fieldSize));
                }

                int barY = viewportHeight - fieldSize;
                // draw bottom bar
                SdlGfx.boxRGBA(ptrSurface, 0, (short)barY, (short)viewportWidth, (short)(barY+fieldSize), 180, 200, 200, 127);

                // draw current weapon
                SDLBlitSprite(GameManager.getInstance().getPlayer().getTexture(), ptrSurface, playerX, playerY);
                SDLBlitSprite(GameManager.getInstance().getPlayer().getWeapon().getTexture(), ptrSurface, playerX, playerY);

                // draw current healthpoints
                for(int iHP = 1; iHP <= 15; iHP++)
                {
                    if(iHP <= GameManager.getInstance().getPlayer().getLife())
                    {
                        SDLBlitSprite(this.textureList.getGUITextureByName("heart_on"), ptrSurface, 70 + (iHP*20), barY + 20);
                    }
                    else
                    {
                        SDLBlitSprite(this.textureList.getGUITextureByName("heart_off"), ptrSurface, 70 + (iHP*20), barY + 20);
                    }
                }

                // draw healthpot symbol and current count
                SDLBlitSprite(this.textureList.getGUITextureByName("healthpot"), ptrSurface, 400, barY);
                string strHealthPotCount = GameManager.getInstance().getPlayer().getHealthPotAmount().ToString("00");

                string firstDigit = strHealthPotCount.Substring(0,1);
                string secondDigit = strHealthPotCount.Substring(1,1);
                SDLBlitSprite(this.textureList.getGUITextureByName("num"+firstDigit), ptrSurface, 450, barY);
                SDLBlitSprite(this.textureList.getGUITextureByName("num"+secondDigit), ptrSurface, 475, barY);

                if(this.currentScreenState == ScreenState.BEGINSCREEN)
                {
                    SDLBlitScreen(this.textureList.getGUITextureByName("title"), ptrSurface);
                }
                else if(this.currentScreenState == ScreenState.ENDSCREEN)
                {
                    SDLBlitScreen(this.textureList.getGUITextureByName("gameover"), ptrSurface);
                }
                else if(this.currentScreenState == ScreenState.YOUWON)
                {
                    SDLBlitScreen(this.textureList.getGUITextureByName("win"), ptrSurface);
                }

                // update everything on screen
                Sdl.SDL_UpdateRect(ptrSurface, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);

            }

            return true;
        }
Ejemplo n.º 24
0
        public static void Main()
        {
            short anchoPantalla = 800;
            short altoPantalla = 600;
            int bitsColor = 24;
            int flags = Sdl.SDL_HWSURFACE | Sdl.SDL_DOUBLEBUF | Sdl.SDL_ANYFORMAT | Sdl.SDL_FULLSCREEN;
            IntPtr pantallaOculta;

            // Inicializamos SDL
            Sdl.SDL_Init(Sdl.SDL_INIT_EVERYTHING);
            pantallaOculta = Sdl.SDL_SetVideoMode(
                altoPantalla,
                anchoPantalla,
                bitsColor,
                flags);

            // Indicamos que se recorte lo que salga de la pantalla oculta
            Sdl.SDL_Rect rect2 = new Sdl.SDL_Rect(0,0, (short) anchoPantalla, (short) altoPantalla);
            Sdl.SDL_SetClipRect(pantallaOculta, ref rect2);

            // Cargamos una imagen
            IntPtr imagen;
            imagen = Sdl.SDL_LoadBMP("personaje.bmp");
            if (imagen == IntPtr.Zero)
            {
                System.Console.WriteLine("Imagen inexistente!");
                Environment.Exit(4);
            }

            // Parte repetitiva
            bool terminado = false;
            short x = 400;
            short y = 300;
            short anchoImagen = 160;
            short altoImagen = 160;
            Sdl.SDL_Event suceso;
            int numkeys;
            byte[] teclas;

            do
            {
                // Comprobamos sucesos
                Sdl.SDL_PollEvent(out suceso);
                teclas = Sdl.SDL_GetKeyState(out numkeys);
                // Miramos si se ha pulsado alguna flecha del cursor
                if (teclas[Sdl.SDLK_UP] == 1)
                y -= 2;
                if (teclas[Sdl.SDLK_DOWN] == 1)
                y += 2;
                if (teclas[Sdl.SDLK_LEFT] == 1)
                x -= 2;
                if (teclas[Sdl.SDLK_RIGHT] == 1)
                x += 2;
                if (teclas[Sdl.SDLK_ESCAPE] == 1)
                terminado = true;

                // Borramos pantalla
                Sdl.SDL_Rect origen = new Sdl.SDL_Rect(0, 0, anchoPantalla,altoPantalla);

                Sdl.SDL_FillRect(pantallaOculta, ref origen, 0);

                // Dibujamos en sus nuevas coordenadas
                origen = new Sdl.SDL_Rect(0,0,anchoImagen,altoImagen);
                Sdl.SDL_Rect dest = new Sdl.SDL_Rect(x,y,
                anchoImagen,altoImagen);
                Sdl.SDL_BlitSurface(imagen, ref origen,
                pantallaOculta, ref dest);
                Sdl.SDL_FillRect(pantallaOculta, ref origen, 0);

                // Mostramos pantalla oculta
                Sdl.SDL_Flip(pantallaOculta);

                // Y esperamos 20 ms
                System.Threading.Thread.Sleep( 20 );
            } while(!terminado);

            // Finalmente, cerramos SDL
            Sdl.SDL_Quit();
        }
Ejemplo n.º 25
0
		public void LoadBMPSaveBMPBlit()
		{
			IntPtr surfacePtr = VideoSetup();
			Assert.IsNotNull(surfacePtr);
			Sdl.SDL_Rect rect1 = new Sdl.SDL_Rect(0,0,400,400);
			Sdl.SDL_Rect rect2 = new Sdl.SDL_Rect(0,0,400,400);
			IntPtr bmpImagePtr = Sdl.SDL_LoadBMP("test.bmp");
			Assert.IsNotNull(bmpImagePtr);
			Assert.IsFalse(bmpImagePtr==IntPtr.Zero);
			int result = Sdl.SDL_BlitSurface(bmpImagePtr, ref rect1, surfacePtr, ref rect2);
			Assert.AreEqual(result, 0);
			Sdl.SDL_UpdateRect(surfacePtr, 0,0,400,400);
			Thread.Sleep(sleepTime);
			result = Sdl.SDL_SaveBMP(surfacePtr, "testScreen.bmp");
			Assert.AreEqual(result, 0);
			Sdl.SDL_FreeSurface(surfacePtr);
		}
Ejemplo n.º 26
0
		public void LoadTyped_RW()
		{
			string file = "test.gif";
			IntPtr surfacePtr = VideoSetup();
			IntPtr imagePtr = SdlImage.IMG_LoadTyped_RW(Sdl.SDL_RWFromFile(file, "rb"),1, "gif" );
			Assert.IsFalse(imagePtr == IntPtr.Zero);
			Sdl.SDL_Rect rect1 = new Sdl.SDL_Rect(0,0,200,200);
			Sdl.SDL_Rect rect2 = new Sdl.SDL_Rect(0,0,200,200);
			int result = Sdl.SDL_BlitSurface(imagePtr, ref rect1, surfacePtr, ref rect2);
			Sdl.SDL_UpdateRect(surfacePtr, 0,0,200,200);
			Thread.Sleep(sleepTime);
			Assert.AreEqual(result, 0);
			file = "test.png";
			surfacePtr = VideoSetup();
			imagePtr = SdlImage.IMG_LoadTyped_RW(Sdl.SDL_RWFromFile(file, "rb"), 1, "png");
			Assert.IsFalse(imagePtr == IntPtr.Zero);
			result = Sdl.SDL_BlitSurface(imagePtr, ref rect1, surfacePtr, ref rect2);
			Sdl.SDL_UpdateRect(surfacePtr, 0,0,200,200);
			Thread.Sleep(sleepTime);
			Assert.AreEqual(result, 0);
			this.Quit();
		}
Ejemplo n.º 27
0
 protected override void BeginRender()
 {
     // Clear the buffer and set the clipping rect
     Sdl.SDL_Rect rect = new Sdl.SDL_Rect(0,0,m_windowSizeX, m_windowSizeY);
     Sdl.SDL_FillRect(m_surface, ref rect, 0);
     Sdl.SDL_SetClipRect(m_surface, ref rect);
 }
Ejemplo n.º 28
0
 public static void ClearScreen()
 {
   Sdl.SDL_Rect origin = new Sdl.SDL_Rect(0,0,width,height);
   Sdl.SDL_FillRect(hiddenScreen, ref origin, 0);
 }
Ejemplo n.º 29
0
		public void Load()
		{
			string file = "test.bmp";
			IntPtr surfacePtr = VideoSetup();
			IntPtr imagePtr = SdlImage.IMG_Load(file);
			Assert.IsFalse(imagePtr == IntPtr.Zero);
			Sdl.SDL_Rect rect1 = new Sdl.SDL_Rect(0,0,200,200);
			Sdl.SDL_Rect rect2 = new Sdl.SDL_Rect(0,0,200,200);
			int result = Sdl.SDL_BlitSurface(imagePtr, ref rect1, surfacePtr, ref rect2);
			Sdl.SDL_UpdateRect(surfacePtr, 0,0,200,200);
			Thread.Sleep(sleepTime);
			Assert.AreEqual(result, 0);
			this.Quit();
		}
Ejemplo n.º 30
-1
 public static void Init(short w, short h, int colors, bool fullScreen)
 {
     width = w;
     height = h;
     
     int flags = Sdl.SDL_HWSURFACE | Sdl.SDL_DOUBLEBUF | Sdl.SDL_ANYFORMAT;
     if (fullScreen)
         flags |= Sdl.SDL_FULLSCREEN;
     Sdl.SDL_Init(Sdl.SDL_INIT_EVERYTHING);
     hiddenScreen = Sdl.SDL_SetVideoMode(
       width, 
       height, 
       colors, 
       flags);
       
     Sdl.SDL_Rect rect2 = 
       new Sdl.SDL_Rect(0,0, (short) width, (short) height);
     Sdl.SDL_SetClipRect(hiddenScreen, ref rect2);            
 }