コード例 #1
0
        public D2D.Bitmap LoadBitmap(Bitmap drawingBitmap, D2D.WindowRenderTarget m_renderTarget)
        {
            D2D.Bitmap result = null;

            //Lock the gdi resource
            BitmapData drawingBitmapData = drawingBitmap.LockBits(
                new Rectangle(0, 0, drawingBitmap.Width, drawingBitmap.Height),
                ImageLockMode.ReadOnly, PixelFormat.Format32bppPArgb);

            //Prepare loading the image from gdi resource
            DataStream dataStream = new DataStream(
                drawingBitmapData.Scan0,
                drawingBitmapData.Stride * drawingBitmapData.Height,
                true, false);

            D2D.BitmapProperties properties = new D2D.BitmapProperties();
            properties.PixelFormat = new D2D.PixelFormat(
                DXGI.Format.B8G8R8A8_UNorm,
                D2D.AlphaMode.Premultiplied);

            //Load the image from the gdi resource
            result = new D2D.Bitmap(
                m_renderTarget,
                new Size(drawingBitmap.Width, drawingBitmap.Height),
                dataStream, drawingBitmapData.Stride,
                properties);

            //Unlock the gdi resource
            drawingBitmap.UnlockBits(drawingBitmapData);

            return(result);
        }
コード例 #2
0
        public void LoadLevel1(D2D.WindowRenderTarget renderTarget)
        {
            LevelPositionX = 0;
            CurrentLevel   = 1;
            //Objects
            _objectList    = null;
            _enemyShipList = null;
            _objectList    = new List <LevelObject>();
            _enemyShipList = new List <EnemyShip>();
            Background     = Backgroundlvl1;
            ObjectList.Add(new LevelObject(400, 400, LoadBitmap(Resources.a10010, renderTarget), 150, 150));
            ObjectList.Add(new LevelObject(1200, 200, LoadBitmap(Resources.a10012, renderTarget), 150, 200));
            ObjectList.Add(new LevelObject(1500, 550, LoadBitmap(Resources.a10010, renderTarget), 100, 120));
            ObjectList.Add(new LevelObject(2000, 420, LoadBitmap(Resources.a10015, renderTarget), 150, 150));
            ObjectList.Add(new LevelObject(2500, 300, LoadBitmap(Resources.a10012, renderTarget), 150, 150));
            ObjectList.Add(new LevelObject(3000, 400, LoadBitmap(Resources.a10010, renderTarget), 150, 150));
            ObjectList.Add(new LevelObject(3400, 200, LoadBitmap(Resources.a10012, renderTarget), 150, 150));
            ObjectList.Add(new LevelObject(3900, 550, LoadBitmap(Resources.a10010, renderTarget), 150, 150));
            ObjectList.Add(new LevelObject(4400, 420, LoadBitmap(Resources.a10015, renderTarget), 150, 150));
            ObjectList.Add(new LevelObject(5500, 300, LoadBitmap(Resources.a10012, renderTarget), 150, 150));

            //enemies
            EnemyShipList.Add(new EnemyShip(1500, 400));
            EnemyShipList.Add(new EnemyShip(2000, 100));
            EnemyShipList.Add(new EnemyShip(2700, 350));
            EnemyShipList.Add(new EnemyShip(3500, 150));
            EnemyShipList.Add(new EnemyShip(4800, 550));
            EnemyShipList.Add(new EnemyShip(5500, 300));
            EnemyShipList.Add(new EnemyShip(6000, 500));
            EnemyShipList.Add(new EnemyShip(7000, 200));
        }
コード例 #3
0
ファイル: SlimDXRenderer.cs プロジェクト: andyld97/Spider
        private void initializeGraphics()
        {
            factory = new D2D.Factory(D2D.FactoryType.SingleThreaded, D2D.DebugLevel.None);

            //Create the render target
            renderTarget = new D2D.WindowRenderTarget(factory, new D2D.WindowRenderTargetProperties()
            {
                Handle         = this.Handle,
                PixelSize      = this.Size,
                PresentOptions = D2D.PresentOptions.Immediately
            });

            //Create linear gradient brush
            D2D.GradientStop[] gradientStops = new D2D.GradientStop[]
            {
                new D2D.GradientStop()
                {
                    Position = 0f, Color = new Color4(Color.White)
                },
                new D2D.GradientStop()
                {
                    Position = 1f, Color = new Color4(Color.White)
                }
            };
            backBrushGradient = new D2D.GradientStopCollection(renderTarget, gradientStops);
            backBrushEx       = new D2D.LinearGradientBrush(renderTarget, backBrushGradient, new D2D.LinearGradientBrushProperties()
            {
                StartPoint = new PointF(0, this.Height), EndPoint = new PointF(0, 0)
            });

            //Update initialization flag
            this.FinishedInit = true;
        }
コード例 #4
0
        public void LoadLevel2(D2D.WindowRenderTarget renderTarget)
        {
            LevelPositionX = 0;
            Background     = Backgroundlvl2;
            CurrentLevel   = 2;
            //Objects
            Backgroundgdi  = Resources.SpaceBackground1;
            _objectList    = null;
            _enemyShipList = null;
            _objectList    = new List <LevelObject>();
            _enemyShipList = new List <EnemyShip>();

            ObjectList.Add(new LevelObject(1, 1, LoadBitmap(Resources.a10012, renderTarget), 20, 6000));
            ObjectList.Add(new LevelObject(1, 740, LoadBitmap(Resources.a10012, renderTarget), 30, 6000));

            //enemies
            EnemyShipList.Add(new EnemyShip(1500, 400));
            EnemyShipList.Add(new EnemyShip(2000, 100));
            EnemyShipList.Add(new EnemyShip(2150, 500));
            EnemyShipList.Add(new EnemyShip(2300, 450));
            EnemyShipList.Add(new EnemyShip(2400, 400));
            EnemyShipList.Add(new EnemyShip(2550, 600));
            EnemyShipList.Add(new EnemyShip(2700, 350));
            EnemyShipList.Add(new EnemyShip(3500, 150));
            EnemyShipList.Add(new EnemyShip(3660, 550));
            EnemyShipList.Add(new EnemyShip(3800, 350));
            EnemyShipList.Add(new EnemyShip(3900, 450));
            EnemyShipList.Add(new EnemyShip(4800, 550));
            EnemyShipList.Add(new EnemyShip(4950, 200));
            EnemyShipList.Add(new EnemyShip(5200, 450));
            EnemyShipList.Add(new EnemyShip(5300, 400));
            EnemyShipList.Add(new EnemyShip(5500, 239));
            EnemyShipList.Add(new EnemyShip(5650, 600));
            EnemyShipList.Add(new EnemyShip(5790, 400));
            EnemyShipList.Add(new EnemyShip(6000, 100));
            EnemyShipList.Add(new EnemyShip(6150, 400));
            EnemyShipList.Add(new EnemyShip(6230, 600));
            EnemyShipList.Add(new EnemyShip(6400, 300));
            EnemyShipList.Add(new EnemyShip(6520, 400));
            EnemyShipList.Add(new EnemyShip(6650, 200));
            EnemyShipList.Add(new EnemyShip(6800, 600));
            EnemyShipList.Add(new EnemyShip(7000, 499));
            EnemyShipList.Add(new EnemyShip(7200, 240));
            EnemyShipList.Add(new EnemyShip(7340, 520));
            EnemyShipList.Add(new EnemyShip(7420, 140));
            EnemyShipList.Add(new EnemyShip(7600, 640));
            EnemyShipList.Add(new EnemyShip(7700, 520));
            EnemyShipList.Add(new EnemyShip(7850, 380));
            EnemyShipList.Add(new EnemyShip(7980, 190));
            EnemyShipList.Add(new EnemyShip(8300, 400));
            EnemyShipList.Add(new EnemyShip(6460, 590));
            EnemyShipList.Add(new EnemyShip(8690, 240));
        }
コード例 #5
0
 public void NextLevel(D2D.WindowRenderTarget renderTarget)
 {
     if (CurrentLevel == 1)
     {
         EnemyShipList = null;
         EnemyShipList = new List <EnemyShip>();
         ObjectList    = null;
         ObjectList    = new List <LevelObject>();
         LoadLevel2(renderTarget);
     }
     else if (CurrentLevel == 2)
     {
         EnemyShipList = null;
         EnemyShipList = new List <EnemyShip>();
         ObjectList    = null;
         ObjectList    = new List <LevelObject>();
         LoadLevel1(renderTarget);
     }
 }
コード例 #6
0
        private void rwDrawer_UserPaint(SlimDX.Direct2D.WindowRenderTarget target)
        {
            rwDrawer.Transform(new SlimDX.Vector2(rwDrawer.Width / 2, rwDrawer.Height / 2), 0);
            target.Transform = rwDrawer.renderMatrix;

            lock (mMapPoints)
            {
                foreach (PT_MAP mPtm in mMapPoints)
                {
                    Point     mPt    = mPtm.p;
                    Rectangle ptRect = new Rectangle(mPt.X, mPt.Y, 1, 1);
                    if (mPtm.scanID == 0)
                    {
                        target.FillRectangle(mBlackBrush, ptRect);
                    }
                    else
                    {
                        target.FillRectangle(mRedBrush, ptRect);
                    }
                }
            }
        }
コード例 #7
0
        // Entlädt alle graphicken
        private void UnloadGraphics()
        {
            if (m_backBrushEx != null)
            {
                m_backBrushEx.Dispose();
            }
            if (m_backBrushGradient != null)
            {
                m_backBrushGradient.Dispose();
            }
            if (m_renderTarget != null)
            {
                m_renderTarget.Dispose();
            }
            if (m_factory != null)
            {
                m_factory.Dispose();
            }

            m_backBrushEx       = null;
            m_backBrushGradient = null;
            m_renderTarget      = null;
            m_factory           = null;
        }
コード例 #8
0
        //Ladet alle graphicken
        private void InitializeGraphics()
        {
            //Get requested debug level
            D2D.DebugLevel debugLevel = D2D.DebugLevel.None;
            if (m_debugMode)
            {
                debugLevel = D2D.DebugLevel.Error;
            }

            //Create factory object
            m_factory = new D2D.Factory(D2D.FactoryType.SingleThreaded, debugLevel);
            //  m_factoryText = new SlimDX.DirectWrite.Factory();
            //Create the render target
            m_renderTarget = new D2D.WindowRenderTarget(m_factory, new D2D.WindowRenderTargetProperties()
            {
                Handle         = this.Handle,
                PixelSize      = this.Size,
                PresentOptions = D2D.PresentOptions.Immediately
            });

            //Create linear gradient brush
            D2D.GradientStop[] gradientStops = new D2D.GradientStop[]
            {
                new D2D.GradientStop()
                {
                    Position = 0f, Color = new Color4(Color.LightGray)
                },
                new D2D.GradientStop()
                {
                    Position = 1f, Color = new Color4(Color.Black)
                }
            };
            m_backBrushGradient = new D2D.GradientStopCollection(m_renderTarget, gradientStops);
            m_backBrushEx       = new D2D.LinearGradientBrush(
                m_renderTarget,
                m_backBrushGradient,
                new D2D.LinearGradientBrushProperties()
            {
                StartPoint = new PointF(0, this.Height),
                EndPoint   = new PointF(0, 0)
            });

            //Create gdi backbrush
            if (m_backBrushGdi != null)
            {
                m_backBrushGdi.Dispose();
            }
            m_backBrushGdi = new LinearGradientBrush(
                new Point(0, this.Height),
                new Point(0, 0),
                Color.LightGray,
                Color.LightSteelBlue);

            //Load the bitmap

            backGroundBitmap = LoadBitmap(Resources.Resource.skyline);
            groundBitmap     = LoadBitmap(Resources.Resource.ground);
            pipeLowerBitmap  = LoadBitmap(Resources.Resource.pipe_up);
            pipeUperBitmap   = LoadBitmap(Resources.Resource.pipe_down);
            birdBitmap       = LoadBitmap(Resources.Resource.bird_one);
            //Update initialization flag
            m_initialized = true;
        }
コード例 #9
0
        private void initializeGraphics()
        {
            factory = new D2D.Factory(D2D.FactoryType.SingleThreaded, D2D.DebugLevel.None);

            //Create the render target
            renderTarget = new D2D.WindowRenderTarget(factory, new D2D.WindowRenderTargetProperties()
            {
                Handle = this.Handle,
                PixelSize = this.Size,
                PresentOptions = D2D.PresentOptions.Immediately
            });

            //Create linear gradient brush
            D2D.GradientStop[] gradientStops = new D2D.GradientStop[]
            {
               new D2D.GradientStop(){ Position = 0f, Color = new Color4(Color.White) },
                new D2D.GradientStop(){ Position = 1f, Color = new Color4(Color.White) }
            };
            backBrushGradient = new D2D.GradientStopCollection(renderTarget, gradientStops);
            backBrushEx = new D2D.LinearGradientBrush(renderTarget, backBrushGradient, new D2D.LinearGradientBrushProperties() { StartPoint = new PointF(0, this.Height), EndPoint = new PointF(0, 0) });

            //Update initialization flag
            this.FinishedInit = true;
        }
コード例 #10
0
        // Ladet alle Graphischen ressoursen
        private void InitializeGraphics()
        {
            //Get requested debug level
            D2D.DebugLevel debugLevel = D2D.DebugLevel.None;
            if (m_debugMode)
            {
                debugLevel = D2D.DebugLevel.Error;
            }

            //Create factory object
            m_factory = new D2D.Factory(D2D.FactoryType.SingleThreaded, debugLevel);

            //Create the render target
            m_renderTarget = new D2D.WindowRenderTarget(m_factory, new D2D.WindowRenderTargetProperties()
            {
                Handle         = this.Handle,
                PixelSize      = this.Size,
                PresentOptions = D2D.PresentOptions.Immediately
            });

            //Create linear gradient brush
            D2D.GradientStop[] gradientStops = new D2D.GradientStop[]
            {
                new D2D.GradientStop()
                {
                    Position = 0f, Color = new Color4(Color.LightGray)
                },
                new D2D.GradientStop()
                {
                    Position = 1f, Color = new Color4(Color.Black)
                }
            };
            m_backBrushGradient = new D2D.GradientStopCollection(m_renderTarget, gradientStops);
            m_backBrushEx       = new D2D.LinearGradientBrush(
                m_renderTarget,
                m_backBrushGradient,
                new D2D.LinearGradientBrushProperties()
            {
                StartPoint = new PointF(0, this.Height),
                EndPoint   = new PointF(0, 0)
            });

            //Create gdi backbrush
            if (m_backBrushGdi != null)
            {
                m_backBrushGdi.Dispose();
            }
            m_backBrushGdi = new LinearGradientBrush(
                new Point(0, this.Height),
                new Point(0, 0),
                Color.LightGray,
                Color.LightSteelBlue);

            //Load the bitmap
            level.Backgroundgdi = Resources.Resources.SpaceBackground1;
            level.Background    = LoadBitmap(level.Backgroundgdi);

            spaceshipBitmapGDI         = Resources.Resources.GreenSpaceShip;
            spaceShipBitmap            = LoadBitmap(spaceshipBitmapGDI);
            _Player                    = new PlayerShip(spaceShipBitmap);
            projektileBitmapGdi        = Resources.Resources.greenProjectile;
            projektileBitmap           = LoadBitmap(projektileBitmapGdi);
            projektileHostileBitmapGdi = Resources.Resources.greenprojectile1;
            projektileHostileBitmap    = LoadBitmap(projektileHostileBitmapGdi);
            level.Backgroundlvl1       = LoadBitmap(Resources.Resources.SpaceBackground1);
            level.Backgroundlvl2       = LoadBitmap(Resources.Resources.sewer);
            level.BackgroundGameOver   = LoadBitmap(Resources.Resources.GameOver);
            level.BackgroundNextLevel  = LoadBitmap(Resources.Resources.NextLevel);
            enenyShipBitmap            = LoadBitmap(Resources.Resources.cartoonship_red);
            //Update initialization flag
            m_initialized = true;
        }