Пример #1
0
        public Fighter(DeviceContext ctx, PlayerShotManager manager)
        {
            this.d2dDeviceContext = ctx;
            this.d2dDevice        = ctx.Device;

            this.shotManager = manager;
            this.Initialize();
        }
Пример #2
0
        public RectTargetManager(DeviceContext ctx, PlayerShotManager playerShotManager, Scorer PlayerScorer)
        {
            this.context = ctx;

            this.playerShotManager = playerShotManager;

            this.PlayerScorer = PlayerScorer;

            this.Initialize();
        }
Пример #3
0
            private void CreateDeviceResources()
            {
                /// デフォルトDirect3Dデバイスの作成(取得)
                var defaultDevice = new SharpDX.Direct3D11.Device(DriverType.Hardware, DeviceCreationFlags.Debug | DeviceCreationFlags.BgraSupport);
                /// サポートされているデバイスの取得
                var device = defaultDevice.QueryInterface <SharpDX.Direct3D11.Device1>();

                /// COMを使って、D3Dデバイスオブジェクトに内在するのDXGIデバイスオブジェクトを取得する
                var dxgiDevice2 = device.QueryInterface <SharpDX.DXGI.Device2>();
                /// アダプターの取得
                var dxgiAdapter = dxgiDevice2.Adapter;

                /// COMを使って、DXGIデバイスのファクトリーオブジェクトを取得
                SharpDX.DXGI.Factory2 dxgiFactory2 = dxgiAdapter.GetParent <SharpDX.DXGI.Factory2>();


                var desc = new SwapChainDescription1();

                desc.Width             = 480;
                desc.Height            = 640;
                desc.Format            = Format.B8G8R8A8_UNorm;
                desc.Stereo            = false;
                desc.SampleDescription = new SampleDescription(1, 0);
                desc.Usage             = Usage.RenderTargetOutput;
                desc.BufferCount       = 2;
                desc.Scaling           = Scaling.AspectRatioStretch;
                desc.SwapEffect        = SwapEffect.FlipSequential;
                desc.Flags             = SwapChainFlags.AllowModeSwitch;


                /// スワップチェインの作成
                this.swapChain = new SwapChain1(dxgiFactory2, device, new ComObject(mWindow), ref desc);


                /// Direct2Dデバイスの取得。
                var d2dDevice = new SharpDX.Direct2D1.Device(dxgiDevice2);

                /// Direct2Dデバイスのコンテキストを取得。
                this.d2dDeviceContext = new SharpDX.Direct2D1.DeviceContext(d2dDevice, DeviceContextOptions.None);

                /// スワップチェインからBuffer0のサーフェイスを取得。
                var backBuffer = this.swapChain.GetBackBuffer <Surface>(0);

                var displayInfo = DisplayInformation.GetForCurrentView();

                this.d2dTarget = new Bitmap1(this.d2dDeviceContext, backBuffer, new BitmapProperties1(new PixelFormat(Format.B8G8R8A8_UNorm, SharpDX.Direct2D1.AlphaMode.Premultiplied), displayInfo.LogicalDpi
                                                                                                      , displayInfo.LogicalDpi, BitmapOptions.Target | BitmapOptions.CannotDraw));

                this.PlayerScorer = new Scorer(this.d2dDeviceContext);
                this.updateList   = new List <IUpdatable>();

                /// 自機の作成
                this.playerShotManager = new PlayerShotManager(this.d2dDeviceContext);
                this.updateList.Add(this.playerShotManager);
                this.fighterDisplay = new Fighter(this.d2dDeviceContext, playerShotManager);
                this.fighterDisplay.SetPosition(540, 240);

                this.displayList = new List <IDrawable>();
                this.displayList.Add(this.fighterDisplay);
                this.displayList.Add(this.playerShotManager);
                this.targetManager = new RectTargetManager(this.d2dDeviceContext, this.playerShotManager, this.PlayerScorer);
                this.displayList.Add(this.targetManager);
                this.updateList.Add(this.targetManager);

                this.displayList.Add(this.PlayerScorer);

                /* 様々な初期化処理を以下に書く */
                var fighterPath = new PathGeometry(d2dDevice.Factory);

                var sink = fighterPath.Open();

                sink.BeginFigure(new Vector2(50f, 0f), FigureBegin.Filled);

                sink.AddLines(new SharpDX.Mathematics.Interop.RawVector2[]
                {
                    new Vector2(0f, 0f), new Vector2(0f, 50f), new Vector2(50f, 50f)
                });
                sink.EndFigure(FigureEnd.Closed);
                sink.Close();

                this.tFighterPath = new TransformedGeometry(d2dDevice.Factory, fighterPath, Matrix3x2.Identity);
                this.fighterBrush = new SolidColorBrush(d2dDeviceContext, Color.OrangeRed);

                this.fpsController = new FramePerSec(this.d2dDeviceContext);

                this.enemyShotManager = new EnemyShotManager(this.d2dDeviceContext, this.targetManager, this.fighterDisplay);

                this.displayList.Add(this.enemyShotManager);
                this.updateList.Add(this.enemyShotManager);
            }