Example #1
0
        protected bool IntentarMover(Personaje personaje, Direccion direccion, bool usandoBandera)
        {
            switch(direccion)
            {
                case Direccion.ARRIBA:
                    return EsPosibleMover(
                                        personaje.X,
                                        (short)(personaje.Y - personaje.GetVelocidadY()),
                                        personaje.GetXFinal(),
                                        (short)(personaje.GetYFinal() - personaje.GetVelocidadY()),
                                        usandoBandera);

                case Direccion.ABAJO:
                    return EsPosibleMover(
                                        personaje.X,
                                        (short)(personaje.Y + personaje.GetVelocidadY()),
                                        personaje.GetXFinal(),
                                        (short)(personaje.GetYFinal() + personaje.GetVelocidadY()),
                                        usandoBandera);

                case Direccion.ABAJO_DER:
                    return EsPosibleMover(
                                        (short)(personaje.X + personaje.GetVelocidadX()),
                                        (short)(personaje.Y + personaje.GetVelocidadY()),
                       					(short)(personaje.GetXFinal() + personaje.GetVelocidadX()),
                                        (short)(personaje.GetYFinal() + personaje.GetVelocidadY()),
                                        usandoBandera);

                case Direccion.ABAJO_IZQ:
                    return EsPosibleMover(
                                        (short)(personaje.X - personaje.GetVelocidadX()),
                                        (short)(personaje.Y + personaje.GetVelocidadY()),
                       					(short)(personaje.GetXFinal() - personaje.GetVelocidadX()),
                                        (short)(personaje.GetYFinal() + personaje.GetVelocidadY()),
                                        usandoBandera);

                case Direccion.ARRIBA_DER:
                    return EsPosibleMover(
                                        (short)(personaje.X + personaje.GetVelocidadX()),
                                        (short)(personaje.Y - personaje.GetVelocidadY()),
                       					(short)(personaje.GetXFinal() + personaje.GetVelocidadX()),
                                        (short)(personaje.GetYFinal() - personaje.GetVelocidadY()),
                                        usandoBandera);

                case Direccion.ARRIBA_IZQ:
                    return EsPosibleMover(
                                        (short)(personaje.X - personaje.GetVelocidadX()),
                                        (short)(personaje.Y - personaje.GetVelocidadY()),
                       					(short)(personaje.GetXFinal() - personaje.GetVelocidadX()),
                                        (short)(personaje.GetYFinal() - personaje.GetVelocidadY()),
                                        usandoBandera);

                case Direccion.DERECHA:
                    return EsPosibleMover(
                                        (short)(personaje.X + personaje.GetVelocidadX()),
                                        personaje.Y,
                       					(short)(personaje.GetXFinal() + personaje.GetVelocidadX()),
                                        personaje.GetYFinal(),
                                        usandoBandera);

                case Direccion.IZQUIERDA:
                    return EsPosibleMover(
                                        (short)(personaje.X - personaje.GetVelocidadX()),
                                        personaje.Y,
                       					(short)(personaje.GetXFinal() - personaje.GetVelocidadX()),
                                        personaje.GetYFinal(),
                                        usandoBandera);

                default:
                    //Console.WriteLine("Movimiento no definido");
                    return false;
            }
        }
Example #2
0
        protected void PosicionarKibus()
        {
            Sdl.SDL_Event evento;
            Sdl.SDL_Rect rectangulo;
            kibus  = new Personaje();
            bool puesto;

            //if(this.casa == null)
            if(requierePosicionarCasa)
            {
                Sprite casa = new Sprite("Assets/GFX/casini.png");
                puesto = false;
                do
                {
                    while(Sdl.SDL_PollEvent(out evento) > 0)
                    {

                        switch(evento.type)
                        {
                            case Sdl.SDL_MOUSEMOTION:
                                if (evento.motion.x > 0 && evento.motion.y > 0
                                    && evento.motion.x < Hardware.Ancho && evento.motion.y < Hardware.Alto)
                                {
                                    rectangulo.x = /*(short)(evento.motion.x - 16);*/(short)(((int)(20 - (((Hardware.Ancho - evento.motion.x) / (float)Hardware.Ancho)) * 20)) * 32);
                                    rectangulo.y = /*(short)(evento.motion.y - 16);*/(short)(((int)(20 - (((Hardware.Alto- evento.motion.y) / (float)Hardware.Alto)) * 20)) * 32);

                                    try
                                    {
                                        if(sprites[rectangulo.x/32,rectangulo.y/32] == null)
                                        {
                                            casa.Mover(rectangulo);
                                        }
                                    }
                                    catch (IndexOutOfRangeException)
                                    {}

                                }
                                break;

                            case Sdl.SDL_MOUSEBUTTONDOWN:
                                try
                                {
                                    if(sprites[rectangulo.x/32,rectangulo.y/32] == null)
                                    {
                                        sprites[rectangulo.x/32,rectangulo.y/32] = casa;
                                        this.casa = casa;
                                        puesto = true;
                                    }
                                }
                                catch (IndexOutOfRangeException)
                                {}

                                break;
                        }
                    }
                    Hardware.DibujarFondo();
                    DibujarObstaculos();
                    casa.Dibujar();
                    Hardware.RefrescarPantalla();

                }while(!puesto);
            }

            puesto = false;
            do
            {
                while(Sdl.SDL_PollEvent(out evento) > 0)
                {

                    switch(evento.type)
                    {
                        case Sdl.SDL_MOUSEMOTION:
                            if (evento.motion.x > 0 && evento.motion.y > 0
                                && evento.motion.x < Hardware.Ancho && evento.motion.y < Hardware.Alto)
                            {
                                rectangulo.x = /*(short)(evento.motion.x - 16);*/(short)(((int)(20 - (((Hardware.Ancho - evento.motion.x) / (float)Hardware.Ancho)) * 20)) * 32);
                                rectangulo.y = /*(short)(evento.motion.y - 16);*/(short)(((int)(20 - (((Hardware.Alto- evento.motion.y) / (float)Hardware.Alto)) * 20)) * 32);

                                try
                                {
                                    if(sprites[rectangulo.x/32,rectangulo.y/32] == null)
                                    {
                                        kibus.Mover(rectangulo);
                                    }
                                }
                                catch (IndexOutOfRangeException)
                                {}

                            }
                            break;

                        case Sdl.SDL_MOUSEBUTTONDOWN:
                            try
                            {
                                if(sprites[rectangulo.x/32,rectangulo.y/32] == null)
                                {
                                    puesto = true;
                                }
                            }
                            catch (IndexOutOfRangeException)
                            {}

                            break;
                    }
                }

                Hardware.DibujarFondo();
                DibujarObstaculos();
                kibus.Dibujar();
                Hardware.RefrescarPantalla();

            }while(!puesto);
        }
Example #3
0
        public override void Iniciar()
        {
            pasos = new Stack<int>();
            continuar = true;

            PosicionarCasa();

            kibus = new Personaje(GetCasa().X, GetCasa().Y);

            //usaurio parte
            while(continuar)
            {
                DibujarTodo();
                ComprobarTeclas();
                MoverElementos();
                Hardware.Pausar(30);
            }

            //IA parte
            while(pasos.Count > 0)
            {
                DibujarTodo();
                Hardware.EscribirTexto("Volviendo a Casa", 10, 10);
                Hardware.RefrescarPantalla();
                Regresar();
                MoverElementos();
                Hardware.Pausar(300);
            }

            DibujarTodo();
            Hardware.EscribirTexto("KIBUS LLEGO! \\O/",(short)(Hardware.Alto/2), (short)(Hardware.Ancho/2));
            Hardware.RefrescarPantalla();
            while(!Hardware.TeclaPulsada(Sdl.SDLK_RETURN))
            {
                Hardware.Pausar(20);
            }
        }