示例#1
0
        private void Initialize()
        {
            try {
                //Common DirectX setup calls...
                PresentParameters presentParams = new PresentParameters();
                presentParams.Windowed               = true;
                presentParams.SwapEffect             = SwapEffect.Discard;
                presentParams.BackBufferFormat       = Format.Unknown;
                presentParams.AutoDepthStencilFormat = DepthFormat.D16;
                presentParams.EnableAutoDepthStencil = true;

                // Store the default adapter
                int         adapterOrdinal = D3D.Manager.Adapters.Default.Adapter;
                CreateFlags flags          = CreateFlags.SoftwareVertexProcessing;

                // Check to see if we can use a pure hardware device
                D3D.Caps caps = D3D.Manager.GetDeviceCaps(adapterOrdinal, D3D.DeviceType.Hardware);

                // Do we support hardware vertex processing?
                if (caps.DeviceCaps.SupportsHardwareTransformAndLight)
                {
                    // Replace the software vertex processing
                    flags = CreateFlags.HardwareVertexProcessing;
                }

                device              = new D3D.Device(0, D3D.DeviceType.Hardware, this, flags, presentParams);
                device.DeviceReset += new System.EventHandler(this.OnResetDevice);
                OnResetDevice(device, null);

                //Space Donuts setup
                donutTexture = TextureLoader.FromFile(device, MediaUtilities.FindFile(TileSetFileName), 1024, 1024,
                                                      1, 0, Format.A8R8G8B8, Pool.Managed, Filter.Point, Filter.Point, (unchecked ((int)0xff000000)));

                donutTileSet   = new TileSet(donutTexture, 0, 0, 6, 5, 32, 32);
                pyramidTileSet = new TileSet(donutTexture, 0, 384, 4, 10, 16, 16);
                sphereTileSet  = new TileSet(donutTexture, 0, 512, 2, 20, 8, 8);
                cubeTileSet    = new TileSet(donutTexture, 0, 544, 2, 20, 8, 8);
                shipTileSet    = new TileSet(donutTexture, 0, 576, 4, 10, 16, 16);
                nixiesTileSet  = new TileSet(donutTexture, 0, 832, 1, 14, 8, 8);
                bulletTileSet  = new TileSet(donutTexture, 304, 832, 1, 1, 8, 2);

                //set up DirectInput keyboard device...
                kbd = new DI.Device(SystemGuid.Keyboard);
                kbd.SetCooperativeLevel(this,
                                        DI.CooperativeLevelFlags.Background | DI.CooperativeLevelFlags.NonExclusive);
                kbd.Acquire();

                soundHandler = new SoundHandler(this);

                sm.OnCollisionDetected += new SpriteManager.HandleCollision(this.CollisionHandler);

                hrt.Start();
            }
            catch (DirectXException e) {
                Console.WriteLine("Exception is " + e.ErrorString);
                // Catch any errors and return a failure
            }
        }
        private void Initialize()
        {
            try {
                //Common DirectX setup calls...
                PresentParameters presentParams = new PresentParameters();
                presentParams.Windowed = true;
                presentParams.SwapEffect = SwapEffect.Discard;
                presentParams.BackBufferFormat = Format.Unknown;
                presentParams.AutoDepthStencilFormat = DepthFormat.D16;
                presentParams.EnableAutoDepthStencil = true;

                // Store the default adapter
                int adapterOrdinal = D3D.Manager.Adapters.Default.Adapter;
                CreateFlags flags = CreateFlags.SoftwareVertexProcessing;

                // Check to see if we can use a pure hardware device
                D3D.Caps caps = D3D.Manager.GetDeviceCaps(adapterOrdinal, D3D.DeviceType.Hardware);

                // Do we support hardware vertex processing?
                if (caps.DeviceCaps.SupportsHardwareTransformAndLight)
                    // Replace the software vertex processing
                    flags = CreateFlags.HardwareVertexProcessing;

                device = new D3D.Device(0, D3D.DeviceType.Hardware, this, flags, presentParams);
                device.DeviceReset += new System.EventHandler(this.OnResetDevice);
                OnResetDevice(device, null);

                //Space Donuts setup
                donutTexture = TextureLoader.FromFile(device, MediaUtilities.FindFile(TileSetFileName), 1024, 1024,
                    1, 0,Format.A8R8G8B8, Pool.Managed, Filter.Point, Filter.Point, (unchecked((int)0xff000000)));

                donutTileSet = new TileSet(donutTexture, 0, 0, 6, 5, 32, 32);
                pyramidTileSet = new TileSet(donutTexture, 0, 384, 4, 10, 16, 16);
                sphereTileSet = new TileSet(donutTexture, 0, 512, 2, 20, 8, 8);
                cubeTileSet = new TileSet(donutTexture, 0, 544, 2, 20, 8, 8);
                shipTileSet = new TileSet(donutTexture, 0, 576, 4, 10, 16, 16);
                nixiesTileSet = new TileSet(donutTexture, 0, 832, 1, 14, 8, 8);
                bulletTileSet = new TileSet(donutTexture, 304, 832, 1, 1, 8, 2);

                //set up DirectInput keyboard device...
                kbd = new DI.Device(SystemGuid.Keyboard);
                kbd.SetCooperativeLevel(this,
                    DI.CooperativeLevelFlags.Background | DI.CooperativeLevelFlags.NonExclusive);
                kbd.Acquire();

                soundHandler = new SoundHandler(this);

                sm.OnCollisionDetected += new SpriteManager.HandleCollision(this.CollisionHandler);

                hrt.Start();
            }
            catch (DirectXException e) {
                Console.WriteLine("Exception is " + e.ErrorString);
                // Catch any errors and return a failure
            }
        }