public void Dispose()
 {
     InstructionText.Dispose();
     HelpText.Dispose();
     Character.Dispose();
     Shark.Dispose();
     MousePointer.Dispose();
     Pointer.Dispose();
     ShipLocationIndicator.Dispose();
     DistanceShipLocation.Dispose();
 }
 public void Update()
 {
     Shark.Update();
     if (!GodMode)
     {
         Character.Update();
     }
     else
     {
         Character.UpdateForGodMode();
     }
 }
Beispiel #3
0
 public void Dispose()
 {
     Skybox.Dispose();
     Terrain.Dispose();
     Water.Dispose();
     Ship.Dispose();
     Shark.Dispose();
     Character.Dispose();
     Fishes.ForEach(fish => fish.Dispose());
     Vegetation.Dispose();
     Common.Dispose();
     Weapon.Dispose();
     Bubble.Dispose();
 }
Beispiel #4
0
 public void Update(float elapsedTime, float timeBeetweenUpdate)
 {
     Timer += elapsedTime;
     FogShader.SetValue("time", Timer);
     SoundManager.PlayMusicAmbient(Character.Submerge);
     Character.Update(Ray, Shark.Mesh, elapsedTime);
     PhysicalWorld.dynamicsWorld.StepSimulation(elapsedTime, maxSubSteps: 10, timeBeetweenUpdate);
     Fishes.ForEach(fish => fish.Update(elapsedTime, Camera));
     Skybox.Update();
     Shark.Update(elapsedTime);
     Water.Update(elapsedTime, Camera.Position);
     Terrain.Update(elapsedTime, Camera.Position);
     Character.LooksAtTheHatch = Ray.IntersectsWithObject(objectAABB: Ship.Plane.BoundingBox, distance: 500);
     Character.CanAttack       = Ray.IntersectsWithObject(objectAABB: Shark.Mesh.BoundingBox, distance: 150);
     Character.NearShip        = Ray.IntersectsWithObject(objectAABB: Ship.OutdoorMesh.BoundingBox, distance: 500);
     Character.IsNearSkybox    = Skybox.IsNearSkybox;
     Bubble.Update(elapsedTime, MeshBuilder, Skybox);
     DetectSelectedItem();
 }
Beispiel #5
0
        public void Render(TgcFrustum frustum)
        {
            Character.Render();

            if (Character.IsInsideShip)
            {
                Ship.RenderIndoorShip();
            }
            else
            {
                FogShader.SetValue("CameraPos", TGCVector3.TGCVector3ToFloat4Array(Camera.Position));
                FogShader.SetValue("eyePosition", TGCVector3.TGCVector3ToFloat4Array(Camera.Position));
                Ship.RenderOutdoorShip();
                Skybox.Render(Terrain.SizeWorld());
                Terrain.Render();
                Shark.Render();
                QuadTree.Render(frustum, false);
                Fishes.ForEach(fish => fish.Render());
                Water.Render();
                Bubble.Render();
            }
        }
Beispiel #6
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);
        }
 public GameEventsManager(Shark shark, Character character, GameSoundManager soundManager)
 {
     Shark        = shark;
     Character    = character;
     SoundManager = soundManager;
 }
Beispiel #8
0
        private void InitializerObjects()
        {
            FogShader = TGCShaders.Instance.LoadEffect(ShadersDir + "Shaders.fx");

            FogShader.SetValue("ColorFog", Color.SteelBlue.ToArgb());
            FogShader.SetValue("StartFogDistance", 2000);
            FogShader.SetValue("EndFogDistance", 10000);
            FogShader.SetValue("globalLightPosition", TGCVector3.TGCVector3ToFloat4Array(LightPosition));

            SetMaterialColors();

            /* Initializer object */
            LightBox    = TGCBox.fromSize(TGCVector3.One * 150, Color.White);
            Skybox      = new Skybox(MediaDir, Camera);
            Water       = new Water(MediaDir, ShadersDir, new TGCVector3(0, 3500, 0));
            Ship        = new Ship(MediaDir);
            ShowScene   = true;
            Terrain     = new Terrain(MediaDir, ShadersDir);
            MeshBuilder = new MeshBuilder(Terrain, Water);
            Shark       = new Shark(MediaDir, Skybox, Terrain, Camera, SoundManager);
            Character   = new Character(Camera, Input, SoundManager);
            Weapon      = new Weapon(MediaDir, Camera);
            Vegetation  = new Vegetation(MediaDir);
            Common      = new Common(MediaDir);
            Fishes      = Common.ListFishes.Select(mesh => new Fish(Skybox, Terrain, mesh)).ToList();
            Bubble      = new Bubble(MediaDir);
            AddWeaponToCharacter();

            /* Location */

            MeshBuilder.LocateMeshesInWorld(meshes: ref Vegetation.ListAlgas, area: Skybox.CurrentPerimeter);
            MeshBuilder.LocateMeshesInWorld(meshes: ref Common.ListCorals, area: Skybox.CurrentPerimeter);
            MeshBuilder.LocateMeshesInWorld(meshes: ref Common.ListOres, area: Skybox.CurrentPerimeter);
            MeshBuilder.LocateMeshesInWorld(meshes: ref Common.ListRock, area: Skybox.CurrentPerimeter);
            MeshBuilder.LocateMeshesInWorld(meshes: ref Common.ListFishes, area: Skybox.CurrentPerimeter);
            MeshBuilder.LocateMeshesInWorld(meshes: ref Bubble.Bubbles, area: Skybox.CurrentPerimeter);

            Common.LocateObjects();

            /* Add rigidBody to the world */

            PhysicalWorld = new PhysicalWorld();
            PhysicalWorld.AddBodyToTheWorld(Terrain.Body);
            PhysicalWorld.AddBodyToTheWorld(Character.Body);
            PhysicalWorld.AddBodyToTheWorld(Ship.BodyOutdoorShip);
            PhysicalWorld.AddBodyToTheWorld(Ship.BodyIndoorShip);
            PhysicalWorld.AddBodyToTheWorld(Shark.Body);
            Common.ListCorals.ForEach(coral => PhysicalWorld.AddBodyToTheWorld(coral.Body));
            Common.ListOres.ForEach(ore => PhysicalWorld.AddBodyToTheWorld(ore.Body));
            Common.ListRock.ForEach(rock => PhysicalWorld.AddBodyToTheWorld(rock.Body));
            AddRoofRigidBody();

            Bubble.SetShader(FogShader, "FogBubble");
            Skybox.SetShader(FogShader, "Fog");
            Common.SetShader(FogShader, "Fog");
            Shark.SetShader(FogShader, "Fog");
            Vegetation.SetShader(FogShader, "FogVegetation");
            Ship.SetShader(ref FogShader);

            LightBox.Transform = TGCMatrix.Translation(LightPosition);

            var meshes = GetStaticMeshes();

            QuadTree.Camera = Camera;
            QuadTree.create(meshes, Terrain.world.BoundingBox);
        }
        public void Render()
        {
            if (ShowHelp)
            {
                InstructionText.Render();
            }
            else
            {
                HelpText.Render();
            }

            if (!ActiveInventory)
            {
                if (ShowSharkLife)
                {
                    Shark.Render();
                }

                Character.Render();
                Pointer.Render();

                if (ShowInfoExitShip)
                {
                    ShipText.Text = Constants.SHIP_EXIT_TEXT;
                    ShipText.Render();
                }
                if (ShowInfoEnterShip)
                {
                    ShipText.Text = Constants.SHIP_ENTER_TEXT;
                    ShipText.Render();
                }
                if (NearObjectForSelect)
                {
                    CollectText.Render();
                }

                if (ShowInfoItemCollect)
                {
                    var index = 0;
                    ItemHistory.ForEach(item =>
                    {
                        index++;
                        ItemsHistoryText.Text     = "COLLECTED " + item + " + 1";
                        ItemsHistoryText.Position = new TGCVector2(Constants.COLLECT_TEXT_POSITION.X, Constants.COLLECT_TEXT_POSITION.Y + index * 20);
                        ItemsHistoryText.Render();
                    });
                }

                if (ShowIndicatorShip)
                {
                    ShipLocationIndicator.Render();
                    DistanceShipLocation.Text = DistanceWithShip.ToString();
                    DistanceShipLocation.Render();
                }
            }
            else
            {
                if (CanCraft)
                {
                    Crafting.Render();
                }
                else
                {
                    Inventory.Render();
                    if (ActiveWeapon)
                    {
                        Crafting.RenderItemWeapon();
                    }
                }
                RenderMousePointer();
            }
        }