Beispiel #1
0
    public void iniciarAlgoritmo(Nebulosa nebulosa)
    {
        SistemaPlanetario nodoInicialTemporal = null;

        nebulosaG = nebulosa;
        // buscar el nodo inicial
        foreach (var item in nebulosa.sistemasPlanetarios)
        {
            if (item.inicial)
            {
                nodoInicialTemporal = item;
            }
            if (item.tieneTeletransportador)
            {
                if (nodoInicialTemporal == null)
                {
                    nodoInicialTemporal = item;
                }
                nodoInicial = item;
            }
        }
        List <SistemaPlanetario> camino = new List <SistemaPlanetario>();

        nave = GameObject.FindGameObjectWithTag("Nave").GetComponent <NaveEspacial>();
        double[] materiales = new double[4];
        materiales[0] = nave.iridio;
        materiales[1] = nave.paladio;
        materiales[2] = nave.platino;
        materiales[3] = nave.elementoZero;
        if (nodoInicialTemporal != null)
        {
            buscarCamino(nodoInicialTemporal, 0, nebulosa.grafo, nave.combustible, camino, 0f, nave.sondas, materiales);
        }
    }
Beispiel #2
0
    /// <summary>
    /// Este es un algoritmo voraz que se encarga de buscar el nodo inicial mas adecuado.
    /// </summary>
    /// <param name="planetas"></param>
    /// <param name="grafo"></param>
    public void buscarNodoInicial(List <Planeta> planetas, List <AristaNodo> grafo)
    {
        nave = GameObject.FindGameObjectWithTag("Nave").GetComponent <NaveEspacial>();
        double  mayor          = 0;
        Planeta planetaInicial = null;

        foreach (var item in planetas)
        {
            double iridio       = nave.iridio + item.iridio;
            double paladio      = nave.paladio + item.paladio;
            double platino      = nave.platino + item.platino;
            double elementoZero = nave.elementoZero + item.elementoZero;

            iridio       = Mathf.Clamp((float)iridio, 0, Constantes.IRIDIO_MAX);
            platino      = Mathf.Clamp((float)platino, 0, Constantes.PLATINO_MAX);
            paladio      = Mathf.Clamp((float)paladio, 0, Constantes.PALADIO_MAX);
            elementoZero = Mathf.Clamp((float)elementoZero, 0, Constantes.ELEMENTOZERO_MAX);

            double total = iridio + paladio + platino + elementoZero;

            if (total > mayor)
            {
                mayor          = total;
                planetaInicial = item;
            }
            if (item.inicial)
            {
                planetaInicial = item;
                break;
            }
            if (item.teletransportador.planetaFK != 0 || item.deposito.planetaFK != 0)
            {
                planetaInicial = item;
                break;
            }
        }

        double[]       costo  = new double[4];
        List <Planeta> camino = new List <Planeta>();

        for (int i = 0; i < costo.Length; i++)
        {
            costo[i] = 0;
        }

        if (planetaInicial != null)
        {
            buscarCaminoPlanetas(planetaInicial, grafo, costo, camino, 0);
        }

        //foreach (var item in caminoGlobal)
        //{
        //    Debug.Log(caminoGlobal.Count+"-"+item.nombre);
        //}
    }
Beispiel #3
0
    void Start()
    {
        nave = GameObject.FindGameObjectWithTag("Nave").GetComponent <NaveEspacial>();
        nebulosaSingleton = GameObject.FindGameObjectWithTag("Nebulosa").GetComponent <NebulosaSingleton>();

        foreach (var item in nebulosaSingleton.nebulosa.sistemasPlanetarios)
        {
            item.recorrido = new RecorridoPlanetas();
            item.recorrido.buscarNodoInicial(item.nodos, item.grafo);
        }
        nebulosaSingleton.nebulosa.recorrido = new RecorridoSistemas();
        nebulosaSingleton.nebulosa.recorrido.iniciarAlgoritmo(nebulosaSingleton.nebulosa);


        GameObject lineaSistemas = Instantiate(lineaRecorrido);


        #region pintarLineas
        int i = 0;
        if (nebulosaSingleton.nebulosa.recorrido.caminoGlobal != null)
        {
            foreach (var item in nebulosaSingleton.nebulosa.recorrido.caminoGlobal)
            {
                lineaSistemas.GetComponent <LineRenderer>().positionCount = i + 1;


                lineaSistemas.GetComponent <LineRenderer>().SetPosition(i, new Vector3(item.x, 0, item.z));
                i++;
                GameObject lineaPlanetas = Instantiate(lineaRecorrido);

                GameObject circulo = new GameObject();
                circulo.transform.position   = new Vector3(item.x, 0, item.z);
                circulo.transform.localScale = new Vector3(20, 20, 20);
                GameObject sistemaTemp = new GameObject();
                sistemaTemp.transform.parent        = circulo.transform;
                sistemaTemp.transform.localPosition = new Vector3(0, -2, 0);
                sistemaTemp.transform.localScale    = new Vector3(0.5f, 0.5f, 0.5f);
                GameObject planetaTemp = new GameObject();
                int        j           = 0;
                lineaPlanetas.GetComponent <LineRenderer>().startWidth = 0.5f;
                foreach (var planeta in item.recorrido.caminoGlobal)
                {
                    planetaTemp.transform.parent        = sistemaTemp.transform;
                    planetaTemp.transform.localPosition = (new Vector3(planeta.x, 0, planeta.z));
                    lineaPlanetas.GetComponent <LineRenderer>().positionCount = j + 1;
                    lineaPlanetas.GetComponent <LineRenderer>().SetPosition(j, new Vector3(planetaTemp.transform.position.x, -40, planetaTemp.transform.position.z));
                    j++;
                }
            }
        }
        #endregion pintarLineas

        StartCoroutine(nave.sistemaDeNavegacion(nebulosaSingleton.nebulosa.recorrido.caminoGlobal));
    }
Beispiel #4
0
 private void Awake()
 {
     if (naveEspacial == null)
     {
         naveEspacial = this;
         DontDestroyOnLoad(gameObject);
     }
     else if (naveEspacial != this)
     {
         Destroy(gameObject);
     }
 }
Beispiel #5
0
    public void recalcularAlgorimo(SistemaPlanetario nodoInicial)
    {
        List <SistemaPlanetario> camino = new List <SistemaPlanetario>();

        nave = GameObject.FindGameObjectWithTag("Nave").GetComponent <NaveEspacial>();
        double[] materiales = new double[4];
        materiales[0] = nave.iridio;
        materiales[1] = nave.paladio;
        materiales[2] = nave.platino;
        materiales[3] = nave.elementoZero;
        if (nodoInicial != null)
        {
            buscarCamino(nodoInicial, 0, nebulosaG.grafo, nave.combustible, camino, 0f, nave.sondas, materiales);
        }
    }
Beispiel #6
0
    public void calcular()
    {
        nave = GameObject.FindGameObjectWithTag("Nave").GetComponent <NaveEspacial>();
        if (valeLaPenaAtacar())
        {
            nave.vida -= EnemigoTipoA.DANO_ATAQUE * tipoA;
            nave.vida -= EnemigoTipoB.DANO_ATAQUE * tipoB;
            nave.vida -= EnemigoTipoC.DANO_ATAQUE * tipoC;

            nave.atacar();
        }
        else
        {
            nave.huir();
        }
    }
Beispiel #7
0
 private void Start()
 {
     nave = GameObject.FindGameObjectWithTag("Nave").GetComponent <NaveEspacial>();
 }
 public bool CheckIfMyShotsCollided(NaveEspacial otraNave)
 {
     return(arma.CheckShots(otraNave));
 }
Beispiel #9
0
        /// <summary>
        ///     Se llama una sola vez, al principio cuando se ejecuta el ejemplo.
        ///     Escribir aquí todo el código de inicialización: cargar modelos, texturas, estructuras de optimización, todo
        ///     procesamiento que podemos pre calcular para nuestro juego.
        ///     Borrar el codigo ejemplo no utilizado.
        /// </summary>
        public override void Init()
        {
            estrellasS.ForEach(e => e.AutoTransform = true);
            CustomVertex.PositionTextured[] screenQuadVertices =
            {
                new CustomVertex.PositionTextured(-1,  1, 1, 0, 0),
                new CustomVertex.PositionTextured(1,   1, 1, 1, 0),
                new CustomVertex.PositionTextured(-1, -1, 1, 0, 1),
                new CustomVertex.PositionTextured(1,  -1, 1, 1, 1)
            };
            //vertex buffer de los triangulos
            screenQuadVB = new VertexBuffer(typeof(CustomVertex.PositionTextured), 4, D3DDevice.Instance.Device, Usage.Dynamic | Usage.WriteOnly,
                                            CustomVertex.PositionTextured.Format, Pool.Default);
            screenQuadVB.SetData(screenQuadVertices, 0, LockFlags.None);

            //Creamos un DepthStencil que debe ser compatible con nuestra definicion de renderTarget2D.
            depthStencil = D3DDevice.Instance.Device.CreateDepthStencilSurface(D3DDevice.Instance.Device.PresentationParameters.BackBufferWidth,
                                                                               D3DDevice.Instance.Device.PresentationParameters.BackBufferHeight, DepthFormat.D24S8, MultiSampleType.None, 0, true);

            depthStencilOld = D3DDevice.Instance.Device.DepthStencilSurface;


            escena = new Texture(D3DDevice.Instance.Device, D3DDevice.Instance.Device.PresentationParameters.BackBufferWidth,
                                 D3DDevice.Instance.Device.PresentationParameters.BackBufferHeight, 1, Usage.RenderTarget, Format.X8R8G8B8, Pool.Default);

            propulsores = new Texture(D3DDevice.Instance.Device, D3DDevice.Instance.Device.PresentationParameters.BackBufferWidth,
                                      D3DDevice.Instance.Device.PresentationParameters.BackBufferHeight, 1, Usage.RenderTarget, Format.X8R8G8B8, Pool.Default);

            propulsoresBlurAux = new Texture(D3DDevice.Instance.Device, D3DDevice.Instance.Device.PresentationParameters.BackBufferWidth,
                                             D3DDevice.Instance.Device.PresentationParameters.BackBufferHeight, 1, Usage.RenderTarget, Format.X8R8G8B8, Pool.Default);

            propulsoresBlurAux2 = new Texture(D3DDevice.Instance.Device, D3DDevice.Instance.Device.PresentationParameters.BackBufferWidth,
                                              D3DDevice.Instance.Device.PresentationParameters.BackBufferHeight, 1, Usage.RenderTarget, Format.X8R8G8B8, Pool.Default);

            //Device de DirectX para crear primitivas.
            var d3dDevice = D3DDevice.Instance.Device;

            D3DDevice.Instance.Device.Transform.Projection =
                Matrix.PerspectiveFovLH(D3DDevice.Instance.FieldOfView,
                                        D3DDevice.Instance.AspectRatio,
                                        D3DDevice.Instance.ZNearPlaneDistance,
                                        D3DDevice.Instance.ZFarPlaneDistance * 1.8f);

            this.postProcessMerge = TgcShaders.loadEffect(this.ShadersDir + "PostProcess.fx");
            this.blurEffect       = TgcShaders.loadEffect(this.ShadersDir + "GaussianBlur.fx");

            blurEffect.SetValue("screen_dx", d3dDevice.PresentationParameters.BackBufferWidth);
            blurEffect.SetValue("screen_dy", d3dDevice.PresentationParameters.BackBufferHeight);

            this.escenarios = new List <Escenario>();
            this.enemigos   = new List <NaveEnemiga>();

            //Crear SkyBox
            skyBox        = new TgcSkyBox();
            skyBox.Center = new TGCVector3(0, 0, -2300f);
            skyBox.Size   = new TGCVector3(10000, 10000, 18000);
            var texturesPath = MediaDir + "XWing\\Textures\\";

            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Up, texturesPath + "space.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Down, texturesPath + "space.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Left, texturesPath + "space.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Right, texturesPath + "space.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Front, texturesPath + "space.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Back, texturesPath + "space.jpg");

            skyBox.Init();

            this.navePrincipal                = new NaveEspacial(MediaDir, "xwing-TgcScene.xml", Color.DarkBlue, 10, 250, null, 250f);
            this.navePrincipal.ScaleFactor    = TGCMatrix.Scaling(0.5f, 0.5f, 0.5f);
            this.navePrincipal.RotationVector = new TGCVector3(0, FastMath.PI_HALF, 0);
            this.navePrincipal.MovementVector = new TGCVector3(1200f, -1100f, 4000f);


            for (int i = 0; i < 5; i++)
            {
                escenarios.Add(Escenario.GenerarEscenarioDefault(MediaDir, i));
            }

            for (int i = 0; i < enemigosAlMismoTiempo; i++)
            {
                enemigos.Add(new NaveEnemiga(MediaDir, "X-Wing-TgcScene.xml", dañoEnemigos, 500, navePrincipal));
                enemigos[i].MovementVector = new TGCVector3(0, 0, 500000000000f);
                enemigos[i].CreateOOB();
            }


            //escenarios.ForEach(es => es.generarTorre(MediaDir));
            currentScene = escenarios[0];

            this.navePrincipal.CreateOOB();
            //Suelen utilizarse objetos que manejan el comportamiento de la camara.
            //Lo que en realidad necesitamos gráficamente es una matriz de View.
            //El framework maneja una cámara estática, pero debe ser inicializada.
            //Posición de la camara.
            var cameraPosition = new TGCVector3(0, 0, 0);
            //Quiero que la camara mire hacia el origen (0,0,0).
            var lookAt = new TGCVector3(-50000, -1, 0);

            //Configuro donde esta la posicion de la camara y hacia donde mira.
            Camara.SetCamera(cameraPosition, lookAt);
            //Internamente el framework construye la matriz de view con estos dos vectores.
            //Luego en nuestro juego tendremos que crear una cámara que cambie la matriz de view con variables como movimientos o animaciones de escenas.

            Camara = new CamaraStarWars(this.navePrincipal.GetPosition(), 20, 100);

            sol = TGCBox.fromSize(new TGCVector3(0, 5000, 4000), new TGCVector3(50, 50, 50), Color.Yellow);
            sol.AutoTransform = true;
            menu = new Menu(MediaDir, Input);

            //Cargo sonidos
            pathSonidoMenu     = MediaDir + "Sound\\musica_menu.mp3";
            pathSonidoAmbiente = MediaDir + "Music\\StarWarsMusic.mp3";
            pathSonidoDisparo  = MediaDir + "Music\\laserSound.wav";

            if (menu.playSonidoMenu)
            {
                playerAmbiente.closeFile();
                playerAmbiente.FileName = pathSonidoMenu;
                playerAmbiente.play(true);
            }


            drawer = new Drawer2D();
            hud    = new Hud(MediaDir, Input);

            //ShadowMap

            // Creo el shadowmap.
            // Format.R32F
            // Format.X8R8G8B8
            g_pShadowMap = new Texture(D3DDevice.Instance.Device, SHADOWMAP_SIZE, SHADOWMAP_SIZE, 1, Usage.RenderTarget, Format.R32F, Pool.Default);

            // tengo que crear un stencilbuffer para el shadowmap manualmente
            // para asegurarme que tenga la el mismo tamano que el shadowmap, y que no tenga
            // multisample, etc etc.
            g_pDSShadow = D3DDevice.Instance.Device.CreateDepthStencilSurface(SHADOWMAP_SIZE, SHADOWMAP_SIZE, DepthFormat.D24S8, MultiSampleType.None, 0, true);
            // por ultimo necesito una matriz de proyeccion para el shadowmap, ya
            // que voy a dibujar desde el pto de vista de la luz.
            // El angulo tiene que ser mayor a 45 para que la sombra no falle en los extremos del cono de luz
            // de hecho, un valor mayor a 90 todavia es mejor, porque hasta con 90 grados es muy dificil
            // lograr que los objetos del borde generen sombras
            var aspectRatio = D3DDevice.Instance.AspectRatio;

            g_mShadowProj = TGCMatrix.PerspectiveFovLH(Geometry.DegreeToRadian(50), aspectRatio, 50, 15000);
            D3DDevice.Instance.Device.Transform.Projection = TGCMatrix.PerspectiveFovLH(Geometry.DegreeToRadian(45.0f), aspectRatio, near_plane, far_plane).ToMatrix();
        }
Beispiel #10
0
 private void Start()
 {
     nave = GetComponent <NaveEspacial>();
 }