public void creaMisilV()
        {
            TgcSceneLoader loader = new TgcSceneLoader();
            string         sonido = env.MediaDir + "MySounds\\Launch4.wav";
            var            scene  = loader.loadSceneFromFile(env.MediaDir + "MeshCreator\\Meshes\\Objetos\\Misil-T\\misil-T-TgcScene.xml");
            TgcMesh        mesh   = scene.Meshes[0];

            mesh.AutoUpdateBoundingBox = true;
            mesh.createBoundingBox();
            mesh.Position = this.getMesh().Position;
            Vector3 scale = new Vector3(1f, 1f, 1f);

            Arma arma = new Arma(mesh, this.env, sonido, 20, this.orientacion, this.anguloFinal, scale, this.getMesh(), false);

            ControladorDeVehiculos.getInstance().agregarArma(arma);
            base.agregarArma(arma);
        }
        public virtual void creaDisparo(Vector3 posicion)
        {
            string  sonido = env.MediaDir + "MySounds\\MachineGun.wav";
            var     loader = new TgcSceneLoader();
            var     scene  = loader.loadSceneFromFile(env.MediaDir + "MeshCreator\\Meshes\\Objetos\\Bala\\Bala-TgcScene.xml");
            TgcMesh mesh   = scene.Meshes[0];
            Vector3 scale  = new Vector3(0.3f, 0.3f, 0.3f);

            mesh.Scale = scale;
            mesh.AutoUpdateBoundingBox = true;
            mesh.createBoundingBox();
            mesh.Position = posicion;


            Arma arma = new Arma(mesh, this.env, sonido, 40, this.orientacion, this.anguloFinal, scale, this.getMesh(), true);

            //arma.mover();
            ControladorDeVehiculos.getInstance().agregarArma(arma);
            base.agregarArma(arma);
        }
Esempio n. 3
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()
        {
            //Device de DirectX para crear primitivas.
            var d3dDevice = D3DDevice.Instance.Device;

            timestamp = DateTime.Now;

            //Utilizando esta propiedad puedo activar el update/render a intervalos constantes.
            FixedTickEnable = true;
            //Se puede configurar el tiempo en estas propiedades TimeBetweenUpdates y TimeBetweenRenders, por defecto esta puedo en 1F / FPS_60 es a lo minimo que deberia correr el TP.
            //De no estar a gusto como se ejecuta el metodo Tick (el que maneja el GameLoop) el mismo es virtual con lo cual pueden sobrescribirlo.

            //Esconder cursor
            focusWindows  = d3dDevice.CreationParameters.FocusWindow;
            mousePosition = focusWindows.PointToScreen(new Point(focusWindows.Width / 2, focusWindows.Height / 2));
            //Cursor.Hide();

            Sounds.SoundsManager.Instance().sound    = DirectSound.DsDevice;
            Sounds.SoundsManager.Instance().mediaDir = MediaDir;

            //Burbujas
            D3DDevice.Instance.ParticlesEnabled = true;
            D3DDevice.Instance.EnableParticles();
            Particulas.Init(MediaDir, 20);

            //Oceano
            Oceano.Init(TGCVector3.Up * nivelDelAgua * 0.8f, 100, 100, ShadersDir);

            //Settear jugador y camara
            FPSCamara = new FPSCamara(Camera, Input);

            Player = Player.Instance();
            Player.SetInput(Input);
            Player.Init(FPSCamara);



            //Inicializar camara
            var cameraPosition = new TGCVector3(0, 100, -250);
            var lookAt         = new TGCVector3(0, nivelDelAgua, 0);

            Camera.SetCamera(cameraPosition, lookAt);

            sonidoUnderwater = new TgcStaticSound();
            sonidoUnderwater.loadSound(MediaDir + "Sounds\\mar.wav", DirectSound.DsDevice);

            effect         = TGCShaders.Instance.LoadEffect(ShadersDir + "e_fog.fx");
            efectoInterior = TGCShaders.Instance.LoadEffect(ShadersDir + "interior.fx");


            //Iniciar HUD
            Hud.Init(MediaDir);
            Hud.ChangeStatus(Hud.Status.MainMenu);

            //Cargar enviroment
            oceano = new Fondo(MediaDir, ShadersDir);
            oceano.Init();
            oceano.Camera = Camera;

            heightmap = new TgcSimpleTerrain();
            heightmap.loadHeightmap(MediaDir + marBnwDir, marScaleXZ, marScaleY, new TGCVector3(0, marOffsetY, 0));
            heightmap.loadTexture(MediaDir + marTexDir);

            //Cargar entidades
            var loader = new TgcSceneLoader();
            var scene  = loader.loadSceneFromFile(MediaDir + "yellow_fish-TgcScene.xml");
            var mesh   = scene.Meshes[0];

            peces   = new List <Fish>();
            corales = new List <Coral>();
            metales = new List <Metal>();
            piedras = new List <Metal>();

            int i = 0;

            while (i < 20)
            {
                Fish   fish;
                string meshName = i.ToString();
                fish = new Fish(mesh.clone(meshName));
                fish = (Fish)setearMeshParaLista(fish, i);
                peces.Add(fish);

                fish.Effect(effect);
                fish.Technique("RenderScene");
                i++;
            }

            scene = loader.loadSceneFromFile(MediaDir + "shark-TgcScene.xml");
            mesh  = scene.Meshes[0];

            shark = new Shark(mesh);
            shark.Init();
            sharkSound = new Tgc3dSound(MediaDir + "Sounds\\shark.wav", shark.GetMesh().Position, DirectSound.DsDevice);
            shark.setearSonido(sharkSound);
            shark.setearAlturaMaxima(nivelDelAgua - 19f);

            efectoDesaparecer = TGCShaders.Instance.LoadEffect(ShadersDir + "perlin.fx");

            shark.setearEfectoPerlin(efectoDesaparecer);
            perlinTexture = TgcTexture.createTexture(D3DDevice.Instance.Device, MediaDir + "Textures\\perlin.png");
            shark.setearPerlin(perlinTexture);

            scene = loader.loadSceneFromFile(MediaDir + "coral-TgcScene.xml");
            mesh  = scene.Meshes[0];


            i = 0;
            while (i < 25)
            {
                Coral  coral;
                string meshName = i.ToString();
                coral = new Coral(mesh.createMeshInstance(meshName));
                coral = (Coral)setearMeshParaLista(coral, i * 4, -17);
                corales.Add(coral);

                coral.Effect(effect);
                coral.Technique("RenderScene");
                i++;
            }

            scene = loader.loadSceneFromFile(MediaDir + "Oro-TgcScene.xml");
            mesh  = scene.Meshes[0];
            i     = 0;
            while (i < 15)
            {
                Metal  oro;
                string meshName = i.ToString();
                oro      = new Metal(mesh.createMeshInstance(meshName));
                oro      = (Metal)setearMeshParaLista(oro, i * 8, -17);
                oro.Tipo = ElementoRecolectable.oro;
                metales.Add(oro);

                oro.Effect(effect);
                oro.Technique("RenderSceneLight");
                i++;
            }

            scene = loader.loadSceneFromFile(MediaDir + "Hierro-TgcScene.xml");
            mesh  = scene.Meshes[0];
            i     = 0;
            while (i < 15)
            {
                Metal  hierro;
                string meshName = i.ToString() + i.ToString();
                hierro      = new Metal(mesh.createMeshInstance(meshName));
                hierro      = (Metal)setearMeshParaLista(hierro, (i + 10) * 8, -17);
                hierro.Tipo = ElementoRecolectable.hierro;
                metales.Add(hierro);

                hierro.Effect(effect);
                hierro.Technique("RenderScene");
                i++;
            }

            scene = loader.loadSceneFromFile(MediaDir + "Roca-TgcScene.xml");
            mesh  = scene.Meshes[0];
            i     = 0;
            while (i < 15)
            {
                Metal  roca;
                string meshName = i.ToString() + i.ToString() + i.ToString();
                roca      = new Metal(mesh.createMeshInstance(meshName));
                roca      = (Metal)setearMeshParaLista(roca, (i + 10) * 8, -17);
                roca.Tipo = ElementoRecolectable.madera;
                roca.escalar(new TGCVector3(0.3f, 0.3f, 0.3f));
                piedras.Add(roca);

                roca.Effect(effect);
                roca.Technique("RenderScene");
                i++;
            }

            scene = loader.loadSceneFromFile(MediaDir + "ship-TgcScene.xml");
            nave  = Nave.Instance();
            nave.Init(scene, nivelDelAgua);

            scene = loader.loadSceneFromFile(MediaDir + "EspadaDoble-TgcScene.xml");
            mesh  = scene.Meshes[0];
            arma  = new Arma(mesh);

            scene    = loader.loadSceneFromFile(MediaDir + "Mesa-TgcScene.xml");
            mesaNave = MesaNave.Instance();
            mesaNave.Init(scene);
            mesaNave.Effect(efectoInterior);
            mesaNave.Technique("RenderScene");

            scene        = loader.loadSceneFromFile(MediaDir + "SogaEnrollada-TgcScene.xml");
            mesh         = scene.Meshes[0];
            sogaInterior = SogaInterior.Instance();
            sogaInterior.Init(mesh);
            sogaInterior.Effect(efectoInterior);
            sogaInterior.Technique("RenderScene");

            scene         = loader.loadSceneFromFile(MediaDir + "silla-TgcScene.xml");
            sillaInterior = SillaInterior.Instance();
            sillaInterior.Init(scene);
            sillaInterior.Effect(efectoInterior);
            sillaInterior.Technique("RenderScene");

            scene         = loader.loadSceneFromFile(MediaDir + "Timon-TgcScene.xml");
            timonInterior = TimonInterior.Instance();
            timonInterior.Init(scene);
            timonInterior.Effect(efectoInterior);
            timonInterior.Technique("RenderScene");

            scene       = loader.loadSceneFromFile(MediaDir + "LamparaTecho-TgcScene.xml");
            lamparaNave = new LamparaNave(scene.Meshes[0]);
            lamparaNave.Effect(efectoInterior);
            lamparaNave.Technique("RenderScene");


            //Cargar shaders
            fog               = new TgcFog();
            fog.Color         = Color.FromArgb(30, 144, 255);
            fog.Density       = 1;
            fog.EndDistance   = 1000;
            fog.StartDistance = 1;
            fog.Enabled       = true;

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

            //Fog + Lights
            effect.SetValue("nivelAgua", nivelDelAgua);

            interiorNave = InteriorNave.Instance();
            interiorNave.Init(MediaDir);

            DirectSound.ListenerTracking = Player.Instance().mesh;

            //Mascara post process
            maskTexture = TgcTexture.createTexture(D3DDevice.Instance.Device, MediaDir + "Textures\\mascara.png");
            effect.SetValue("textura_mascara", maskTexture.D3dTexture);

            // seteamos los efectos aca porque son fijos
            oceano.Effect(effect);
            oceano.Technique("RenderScene");

            heightmap.Effect    = effect;
            heightmap.Technique = "RenderScene";

            shark.Effect(effect);
            shark.Technique("RenderScene");

            nave.Effect(effect);
            nave.Technique("RenderSceneLight");

            effect.SetValue("ambientColor", Color.FromArgb(255, 255, 255).ToArgb());
            effect.SetValue("diffuseColor", Color.FromArgb(255, 255, 255).ToArgb());
            effect.SetValue("specularColor", Color.FromArgb(255, 255, 255).ToArgb());

            efectoInterior.SetValue("ambientColor", Color.FromArgb(255, 255, 255).ToArgb());
            efectoInterior.SetValue("diffuseColor", Color.FromArgb(255, 255, 255).ToArgb());
            efectoInterior.SetValue("specularColor", Color.FromArgb(255, 255, 255).ToArgb());

            // dibujo el full screen quad
            CustomVertex.PositionTextured[] vertices =
            {
                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
            fullScreenQuad = new VertexBuffer(typeof(CustomVertex.PositionTextured), 4, d3dDevice, Usage.Dynamic | Usage.WriteOnly, CustomVertex.PositionTextured.Format, Pool.Default);
            fullScreenQuad.SetData(vertices, 0, LockFlags.None);

            // dibujo render target

            depthStencil = d3dDevice.CreateDepthStencilSurface(d3dDevice.PresentationParameters.BackBufferWidth, d3dDevice.PresentationParameters.BackBufferHeight, DepthFormat.D24S8, MultiSampleType.None, 0, true);

            renderTarget = new Texture(d3dDevice, d3dDevice.PresentationParameters.BackBufferWidth, d3dDevice.PresentationParameters.BackBufferHeight, 1, Usage.RenderTarget, Format.X8R8G8B8, Pool.Default);

            // inicializo los FB que uso para el Bloom
            coralesBrillantes = new Texture(d3dDevice, d3dDevice.PresentationParameters.BackBufferWidth, d3dDevice.PresentationParameters.BackBufferHeight, 1, Usage.RenderTarget, Format.X8R8G8B8, Pool.Default);

            FBHorizontalBool = new Texture(d3dDevice, d3dDevice.PresentationParameters.BackBufferWidth, d3dDevice.PresentationParameters.BackBufferHeight, 1, Usage.RenderTarget, Format.X8R8G8B8, Pool.Default);

            FBVerticalBloom = new Texture(d3dDevice, d3dDevice.PresentationParameters.BackBufferWidth, d3dDevice.PresentationParameters.BackBufferHeight, 1, Usage.RenderTarget, Format.X8R8G8B8, Pool.Default);
        }