Esempio n. 1
0
 /// <summary>
 /// Initializes this instance.
 /// </summary>
 /// <param name="ginfo"></param>
 /// <param name="factory"></param>
 /// <param name="obj"></param>
 public override void Initialize(GraphicInfo ginfo, GraphicFactory factory, IObject obj)
 {
     effect = factory.GetEnvironmentMapEffect();
     if (enableLightining)
     {
         effect.EnableDefaultLighting();
     }
     effect.EnvironmentMapAmount = amountDiffuse;
     base.Initialize(ginfo, factory, obj);
 }
Esempio n. 2
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // Calculate the screen aspect ratio
            float aspectRatio = (float)GraphicsDevice.Viewport.Width / GraphicsDevice.Viewport.Height;
            // Create a projection matrix
            Matrix projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45), aspectRatio, 0.1f, 1000.0f);

            // Calculate a view matrix (where we are looking from and to)
            Matrix view = Matrix.CreateLookAt(new Vector3(0, 0, 4), Vector3.Zero, Vector3.Up);

            // Create and initialize the effect
            _effect            = new EnvironmentMapEffect(GraphicsDevice);
            _effect.Projection = projection;
            _effect.View       = view;
            _effect.World      = Matrix.Identity;
            _effect.EnableDefaultLighting();

            base.Initialize();
        }
Esempio n. 3
0
        /// <summary>
        /// Load graphics content for the game.
        /// </summary>
        public override void Activate(bool instancePreserved)
        {
            if (!instancePreserved)
            {
                if (content == null)
                {
                    content = new ContentManager(ScreenManager.Game.Services, "Content");
                }

                topViewport    = ScreenManager.GraphicsDevice.Viewport;
                bottomViewport = ScreenManager.GraphicsDevice.Viewport;

                if (ScreenManager.ScreenHorizontal == true)
                {
                    topViewport.Height    = topViewport.Height / 2;
                    bottomViewport.Height = bottomViewport.Height / 2;
                    bottomViewport.Y      = topViewport.Height;

                    camera.AspectRatio = (float)ScreenManager.GraphicsDevice.Viewport.Width /
                                         (ScreenManager.GraphicsDevice.Viewport.Height / 2);
                    camera2.AspectRatio = (float)ScreenManager.GraphicsDevice.Viewport.Width /
                                          (ScreenManager.GraphicsDevice.Viewport.Height / 2);

                    camera.FieldOfView  = MathHelper.ToRadians(45);
                    camera2.FieldOfView = MathHelper.ToRadians(45);
                }
                else
                {
                    topViewport.Width    = topViewport.Width / 2;
                    bottomViewport.Width = bottomViewport.Width / 2;
                    bottomViewport.X     = topViewport.Width;

                    camera.AspectRatio = (float)(ScreenManager.GraphicsDevice.Viewport.Width / 2) /
                                         ScreenManager.GraphicsDevice.Viewport.Height;
                    camera2.AspectRatio = (float)(ScreenManager.GraphicsDevice.Viewport.Width / 2) /
                                          ScreenManager.GraphicsDevice.Viewport.Height;

                    camera.FieldOfView  = MathHelper.ToRadians(60);
                    camera2.FieldOfView = MathHelper.ToRadians(60);
                }

                gameFont    = content.Load <SpriteFont>("gamefont");
                rockModel   = content.Load <Model>("Rock");
                shipModel   = content.Load <Model>("SpaceShip1");
                shipModel2  = content.Load <Model>("SpaceShip2");
                groundModel = content.Load <Model>("Ground");
                cubeModel   = content.Load <Model>("cube");
                bulletModel = content.Load <Model>("Cone");
                skyBoxModel = content.Load <Model>("Space_SkyBox");
                audioEngine = ScreenManager.AudioEngine;
                soundBank   = ScreenManager.SoundBank;
                waveBank    = ScreenManager.WaveBank;
                acSFX       = audioEngine.GetCategory("SFX");
                acMusic     = audioEngine.GetCategory("Music");

                // Environmental Map Effect for Player 1
                envEffect1            = new EnvironmentMapEffect(ScreenManager.GraphicsDevice);
                envEffect1.Projection = Matrix.CreatePerspectiveFieldOfView(
                    MathHelper.PiOver4, ScreenManager.GraphicsDevice.Viewport.AspectRatio, 1.0f, 100.0f);
                envEffect1.View = Matrix.CreateLookAt(
                    new Vector3(2, 3, 32), Vector3.Zero, Vector3.Up);
                textureCube1 = new TextureCube(ScreenManager.GraphicsDevice, 256, false, SurfaceFormat.Color);
                Color[] facedata1 = new Color[256 * 256];
                for (int i = 0; i < 6; i++)
                {
                    envEffect1.Texture = content.Load <Texture2D>("skybox" + i.ToString());
                    envEffect1.Texture.GetData <Color>(facedata1);
                    textureCube1.SetData <Color>((CubeMapFace)i, facedata1);
                }
                envEffect1.Texture        = (shipModel.Meshes[0].Effects[0] as EnvironmentMapEffect).Texture;
                envEffect1.EnvironmentMap = textureCube1;
                envEffect1.EnableDefaultLighting();
                envEffect1.EnvironmentMapAmount   = 1.0f;
                envEffect1.FresnelFactor          = 1.0f;
                envEffect1.EnvironmentMapSpecular = Vector3.Zero;

                // Environmental Map Effect for Player 2
                envEffect2            = new EnvironmentMapEffect(ScreenManager.GraphicsDevice);
                envEffect2.Projection = Matrix.CreatePerspectiveFieldOfView(
                    MathHelper.PiOver4, ScreenManager.GraphicsDevice.Viewport.AspectRatio, 1.0f, 100.0f);
                envEffect2.View = Matrix.CreateLookAt(
                    new Vector3(2, 3, 32), Vector3.Zero, Vector3.Up);
                textureCube2 = new TextureCube(ScreenManager.GraphicsDevice, 256, false, SurfaceFormat.Color);
                Color[] facedata2 = new Color[256 * 256];
                for (int i = 0; i < 6; i++)
                {
                    envEffect2.Texture = content.Load <Texture2D>("skybox" + i.ToString());
                    envEffect2.Texture.GetData <Color>(facedata2);
                    textureCube2.SetData <Color>((CubeMapFace)i, facedata2);
                }
                envEffect2.Texture        = (shipModel2.Meshes[0].Effects[0] as EnvironmentMapEffect).Texture;
                envEffect2.EnvironmentMap = textureCube2;
                envEffect2.EnableDefaultLighting();
                envEffect2.EnvironmentMapAmount   = 1.0f;
                envEffect2.FresnelFactor          = 1.0f;
                envEffect2.EnvironmentMapSpecular = Vector3.Zero;

                //audioEngine = ScreenManager.AudioEngine;
                //soundBank = ScreenManager.SoundBank;
                //waveBank = ScreenManager.WaveBank;

                if (ScreenManager.AudioEnabled == true)
                {
                    acSFX.SetVolume(ScreenManager.SFXVolume);
                    acMusic.SetVolume(ScreenManager.AudioVolume);
                }
                else
                {
                    acSFX.SetVolume(0);
                    acMusic.SetVolume(0);
                }

                FxCue = soundBank.GetCue("ShotFx");
                //FxCue.Apply3D(shipListen1, shipEmit1);

                ship1Pos = new Vector3(10000, 350, 10000);
                ship2Pos = new Vector3(100, 350, 100);

                // Create shiplllllllllllllllllllllllllllll
                ship  = new Ship(ScreenManager.GraphicsDevice, ship1Pos, soundBank);
                ship2 = new Ship(ScreenManager.GraphicsDevice, ship2Pos, soundBank);
                //ship2.Position = new Vector3(100, 100, 100);

                RandomRockSpawner();

                UpdateCameraChaseTarget(ship, camera);
                UpdateCameraChaseTarget(ship2, camera2);

                camera.Reset();
                camera2.Reset();

                // A real game would probably have more content than this sample, so
                // it would take longer to load. We simulate that by delaying for a
                // while, giving you a chance to admire the beautiful loading screen.
                Thread.Sleep(1000);

                // once the load has finished, we use ResetElapsedTime to tell the game's
                // timing mechanism that we have just finished a very long frame, and that
                // it should not try to catch up.
                ScreenManager.Game.ResetElapsedTime();
            }

#if WINDOWS_PHONE
            if (Microsoft.Phone.Shell.PhoneApplicationService.Current.State.ContainsKey("PlayerPosition"))
            {
                playerPosition = (Vector2)Microsoft.Phone.Shell.PhoneApplicationService.Current.State["PlayerPosition"];
                enemyPosition  = (Vector2)Microsoft.Phone.Shell.PhoneApplicationService.Current.State["EnemyPosition"];
            }
#endif
        }