// Load a Direct2D bitmap from the given gdi resource.
        public D2D.Bitmap LoadBitmap(Bitmap drawingBitmap)
        {
            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);
        }
Example #2
0
        public TileGameWindow(string title, int width, int height, bool fullscreen)
            : base(title, width, height, fullscreen)
        {
            this.m_Factory = new Factory();

            RenderTargetProperties rtProperties = new RenderTargetProperties
            {
                PixelFormat = new SlimDXPixelFormat(Format.B8G8R8A8_UNorm, AlphaMode.Premultiplied)
            };

            WindowRenderTargetProperties properties = new WindowRenderTargetProperties
            {
                Handle    = FormObject.Handle,
                PixelSize = new Size(width, height)
            };

            this.m_RenderTarget = new WindowRenderTarget(this.m_Factory, rtProperties, properties);

            this.m_DebugBrush = new SolidColorBrush(this.m_RenderTarget, new Color4(1.0f, 1.0f, 1.0f, 0.0f));

            this.m_PlayerSprites = LoadBitmap(Application.StartupPath + "\\Robot.png");
            this.m_Player        = new Player
            {
                PositionX = 4,
                PositionY = 8
            };

            this.InitalizeTileGameWorld();
        }
Example #3
0
 public LevelObject(int posX, int posY, D2D.Bitmap objectBitmap, int rectangleHoehe, int rectangleBreite)
 {
     PosX                 = posX;
     PosY                 = posY;
     ObjectBitmap         = objectBitmap;
     this.RectangleHoehe  = rectangleHoehe;
     this.RectangleBreite = rectangleBreite;
 }
Example #4
0
        /// <summary>
        /// Draws a Texture.
        /// </summary>
        /// <param name="texture">The Texture.</param>
        /// <param name="rectangle">The Rectangle.</param>
        /// <param name="opacity">The Opacity.</param>
        /// <param name="color">The Color.</param>
        public void DrawTexture(Texture2D texture, Rectangle rectangle, Color color, float opacity = 1)
        {
            var dxTexture = texture as DirectXTexture;

            if (dxTexture == null)
            {
                throw new ArgumentException("DirectX10 expects a DirectXTexture as resource.");
            }
            Bitmap dxBmp = dxTexture.GetBitmap();

            _renderTarget.DrawBitmap(dxBmp, DirectXHelper.ConvertRectangle(rectangle), opacity,
                                     InterpolationMode == InterpolationMode.Linear
                    ? SlimDX.Direct2D.InterpolationMode.Linear
                    : SlimDX.Direct2D.InterpolationMode.NearestNeighbor);
        }
        // Loads a Direct2D bitmap from the given file.
        public D2D.Bitmap LoadBitmap(string file)
        {
            D2D.Bitmap result = null;

            //Create Gdi Bitmap
            Bitmap drawingBitmap = Bitmap.FromFile(file) as Bitmap;

            //Load the Direct2D resource from the gdi resource
            result = LoadBitmap(drawingBitmap);

            //Dispose the gdi bitmap after loading
            drawingBitmap.Dispose();

            return(result);
        }
Example #6
0
        /// <summary>
        /// Draws a Texture.
        /// </summary>
        /// <param name="texture">The Texture.</param>
        /// <param name="position">The Position.</param>
        /// <param name="opacity">The Opacity.</param>
        /// <param name="color">The Color.</param>
        public void DrawTexture(Texture2D texture, Vector2 position, Color color, float opacity = 1)
        {
            var dxTexture = texture as DirectXTexture;

            if (dxTexture == null)
            {
                throw new ArgumentException("DirectX10 expects a DirectXTexture as resource.");
            }
            Bitmap dxBmp = dxTexture.GetBitmap();

            _renderTarget.DrawBitmap(dxBmp,
                                     new RectangleF(position.X, position.Y, texture.Width, texture.Height), opacity,
                                     InterpolationMode == InterpolationMode.Linear
                    ? SlimDX.Direct2D.InterpolationMode.Linear
                    : SlimDX.Direct2D.InterpolationMode.NearestNeighbor);
        }
Example #7
0
        /// <summary>
        /// This method loads a bitmap file into memory for us.
        /// </summary>
        /// <param name="filename"></param>
        public SlimDXBitmap LoadBitmap(string filename)
        {
            // This will hold the Direct2D Bitmap that we will return at the end of this function.
            SlimDXBitmap d2dBitmap = null;


            // Load the bitmap using the System.Drawing.Bitmap class.
            SystemBitmap originalImage = new SystemBitmap(filename);

            // Create a rectangle holding the size of the bitmap image.
            Rectangle bounds = new Rectangle(0, 0, originalImage.Width, originalImage.Height);

            // Lock the memory holding this bitmap so that only we are allowed to mess with it.
            BitmapData imageData = originalImage.LockBits(bounds, ImageLockMode.ReadOnly, SystemPixelFormat.Format32bppPArgb);

            // Create a DataStream attached to the bitmap.
            DataStream dataStream = new DataStream(imageData.Scan0,
                                                   imageData.Stride * imageData.Height,
                                                   true,
                                                   false);

            // Set the pixel format and properties.
            BitmapProperties bmpProperties = new BitmapProperties
            {
                PixelFormat = new SlimDXPixelFormat(Format.B8G8R8A8_UNorm, AlphaMode.Premultiplied)
            };


            // Copy the image data into a new SlimDX.Direct2D.Bitmap object.
            d2dBitmap = new SlimDXBitmap(
                this.m_RenderTarget,
                new Size(bounds.Width, bounds.Height),
                dataStream,
                imageData.Stride,
                bmpProperties);

            // Unlock the memory that is holding the original bitmap object.
            originalImage.UnlockBits(imageData);


            // Get rid of the original bitmap object since we no longer need it.
            originalImage.Dispose();


            // Return the Direct2D bitmap.
            return(d2dBitmap);
        }
Example #8
0
        public void Render()
        {
            d2dWindowRenderTarget.BeginDraw();
            d2dWindowRenderTarget.Clear(new Color4(Color.Black));
            int sizex, sizey;

            foreach (gameobject curr in ToDraw)
            {
                if (curr.Game_object_state == 0)
                {
                    sizex = targetControl.Width;
                    sizey = targetControl.Height;
                }
                else
                {
                    sizex = 200;
                    sizey = 200;
                }
                if (curr.D2dbm == null)
                {
                    d2dPixelFormat                  = new PixelFormat(SlimDX.DXGI.Format.B8G8R8A8_UNorm, AlphaMode.Premultiplied);
                    d2dBitmapProperties             = new BitmapProperties();
                    d2dBitmapProperties.PixelFormat = d2dPixelFormat;

                    bitmapData = curr.Game_object_bitmap.LockBits(new Rectangle(new Point(0, 0), new Size(curr.Game_object_bitmap.Width, curr.Game_object_bitmap.Height)), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
                    dataStream = new DataStream(bitmapData.Scan0, bitmapData.Stride * bitmapData.Height, true, false);
                    SlimDX.Direct2D.Bitmap temp = new SlimDX.Direct2D.Bitmap(d2dWindowRenderTarget, new Size(curr.Game_object_bitmap.Width, curr.Game_object_bitmap.Height), dataStream, bitmapData.Stride, d2dBitmapProperties);
                    curr.D2dbm = temp;
                    curr.Game_object_bitmap.UnlockBits(bitmapData);
                    d2dWindowRenderTarget.DrawBitmap(curr.D2dbm);
                    dataStream.Dispose();
                }
                else
                {
                    //d2dWindowRenderTarget.DrawBitmap(curr.D2dbm, new Rectangle(curr.Game_object_position.X, curr.Game_object_position.Y, targetControl.Width, targetControl.Height));
                    d2dWindowRenderTarget.DrawBitmap(curr.D2dbm, new Rectangle(curr.Game_object_position.X, curr.Game_object_position.Y, sizex, sizey), 1.0f, InterpolationMode.Linear, new Rectangle(1024 * curr.Game_object_state, 0, 1024, curr.Game_object_bitmap.Height));
                }
            }



            d2dWindowRenderTarget.DrawRectangle(new SolidColorBrush(d2dWindowRenderTarget, new Color4(Color.Red)), new Rectangle(20, 20, targetControl.Width - 40, targetControl.Height - 40));
            d2dWindowRenderTarget.DrawText(Form1.counter.ToString(), new TextFormat(wrtFactory, "Arial", SlimDX.DirectWrite.FontWeight.Normal, SlimDX.DirectWrite.FontStyle.Normal, FontStretch.Normal, 18, "en-us"), new Rectangle(new Point(0, 0), new Size(200, 20)), new SolidColorBrush(d2dWindowRenderTarget, new Color4(Color.Blue)));
            d2dWindowRenderTarget.EndDraw();
            Form1.tempcounter++;
        }
Example #9
0
        /// <summary>
        /// Draws a Texture.
        /// </summary>
        /// <param name="spriteSheet">The SpriteSheet.</param>
        /// <param name="rectangle">The Rectangle.</param>
        /// <param name="color">The Color.</param>
        /// <param name="opacity">The Opacity.</param>
        public void DrawTexture(SpriteSheet spriteSheet, Rectangle rectangle, Color color, float opacity = 1)
        {
            var dxTexture = spriteSheet.Texture2D as DirectXTexture;

            if (dxTexture == null)
            {
                throw new ArgumentException("DirectX10 expects a DirectXTexture as resource.");
            }
            Bitmap dxBmp = dxTexture.GetBitmap();

            DirectXHelper.RenderTarget.DrawBitmap(dxBmp,
                                                  new RectangleF(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height), opacity,
                                                  InterpolationMode == InterpolationMode.Linear
                    ? SlimDX.Direct2D.InterpolationMode.Linear
                    : SlimDX.Direct2D.InterpolationMode.NearestNeighbor,
                                                  DirectXHelper.ConvertRectangleF(spriteSheet.Rectangle));
        }
        public void Draw()
        {
            if (this._d2dbitmap == null)
            {
                // Load the texture
                var bitmapData = this.tileSheetBitmap.LockBits(
                    tileRect,
                    System.Drawing.Imaging.ImageLockMode.ReadOnly,
                    System.Drawing.Imaging.PixelFormat.Format32bppPArgb
                );
                var dataStream = new DataStream(
                    bitmapData.Scan0,
                    bitmapData.Stride * bitmapData.Height,
                    true,
                    false
                );
                var d2dPixelFormat = new PixelFormat(
                    SlimDX.DXGI.Format.B8G8R8A8_UNorm,
                    SlimDX.Direct2D.AlphaMode.Premultiplied
                );
                var d2dBitmapProperties = new BitmapProperties();
                d2dBitmapProperties.PixelFormat = d2dPixelFormat;

                _d2dbitmap = new SlimDX.Direct2D.Bitmap(
                    _device.RenderTarget,
                    tileRect.Size,
                    dataStream,
                    bitmapData.Stride,
                    d2dBitmapProperties
                );
                this.tileSheetBitmap.UnlockBits(bitmapData);
            }

            // Render to the 2D context
            _device.RenderTarget.DrawBitmap(
                _d2dbitmap,
                new Rectangle(
                    this.drawToPosition,
                    new Size(this.tileRect.Width, this.tileRect.Height)
                )
            );
        }
Example #11
0
        /// <summary>
        /// Initializes a new DirectXTexture class.
        /// </summary>
        /// <param name="bmp">The Bitmap.</param>
        internal DirectXTexture(System.Drawing.Bitmap bmp)
        {
            RawBitmap = (System.Drawing.Bitmap)bmp.Clone();
            _width    = bmp.Width;
            _height   = bmp.Height;
            var sourceArea       = new Rectangle(0, 0, bmp.Width, bmp.Height);
            var bitmapProperties = new BitmapProperties
            {
                PixelFormat   = new PixelFormat(Format.R8G8B8A8_UNorm, AlphaMode.Premultiplied),
                HorizontalDpi = 96,
                VerticalDpi   = 96
            };
            var size = new Size(bmp.Width, bmp.Height);

            int stride = bmp.Width * sizeof(int);

            using (var tempStream = new DataStream(bmp.Height * stride, true, true))
            {
                BitmapData bitmapData = bmp.LockBits(sourceArea, ImageLockMode.ReadOnly,
                                                     System.Drawing.Imaging.PixelFormat.Format32bppPArgb);

                for (int y = 0; y < bmp.Height; y++)
                {
                    int offset = bitmapData.Stride * y;
                    for (int x = 0; x < bmp.Width; x++)
                    {
                        byte b    = Marshal.ReadByte(bitmapData.Scan0, offset++);
                        byte g    = Marshal.ReadByte(bitmapData.Scan0, offset++);
                        byte r    = Marshal.ReadByte(bitmapData.Scan0, offset++);
                        byte a    = Marshal.ReadByte(bitmapData.Scan0, offset++);
                        int  rgba = r | (g << 8) | (b << 16) | (a << 24);
                        tempStream.Write(rgba);
                    }
                }
                bmp.UnlockBits(bitmapData);
                tempStream.Position = 0;
                _bmp = new Bitmap(DirectXHelper.RenderTarget, size, tempStream, stride, bitmapProperties);
            }
        }
        //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;
        }
 public PlayerShip(D2D.Bitmap spaceshipBitmap)
 {
     this.SpaceshipBitmap = spaceshipBitmap;
 }
Example #14
0
        /// <summary>
        /// Initializes a new DirectXTexture class.
        /// </summary>
        /// <param name="bmp">The Bitmap.</param>
        internal DirectXTexture(System.Drawing.Bitmap bmp)
        {
            RawBitmap = (System.Drawing.Bitmap) bmp.Clone();
            _width = bmp.Width;
            _height = bmp.Height;
            var sourceArea = new Rectangle(0, 0, bmp.Width, bmp.Height);
            var bitmapProperties = new BitmapProperties
            {
                PixelFormat = new PixelFormat(Format.R8G8B8A8_UNorm, AlphaMode.Premultiplied),
                HorizontalDpi = 96,
                VerticalDpi = 96
            };
            var size = new Size(bmp.Width, bmp.Height);

            int stride = bmp.Width*sizeof (int);
            using (var tempStream = new DataStream(bmp.Height*stride, true, true))
            {
                BitmapData bitmapData = bmp.LockBits(sourceArea, ImageLockMode.ReadOnly,
                    System.Drawing.Imaging.PixelFormat.Format32bppPArgb);

                for (int y = 0; y < bmp.Height; y++)
                {
                    int offset = bitmapData.Stride*y;
                    for (int x = 0; x < bmp.Width; x++)
                    {
                        byte b = Marshal.ReadByte(bitmapData.Scan0, offset++);
                        byte g = Marshal.ReadByte(bitmapData.Scan0, offset++);
                        byte r = Marshal.ReadByte(bitmapData.Scan0, offset++);
                        byte a = Marshal.ReadByte(bitmapData.Scan0, offset++);
                        int rgba = r | (g << 8) | (b << 16) | (a << 24);
                        tempStream.Write(rgba);
                    }
                }
                bmp.UnlockBits(bitmapData);
                tempStream.Position = 0;
                _bmp = new Bitmap(DirectXHelper.RenderTarget, size, tempStream, stride, bitmapProperties);
            }
        }
Example #15
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;
        }
Example #16
0
        //Zeichnet alle Objekte
        protected override void OnPaint(PaintEventArgs e)
        {
            label1.Text     = "Leben:" + lives;
            labelScore.Text = "Score:" + score;
            base.OnPaint(e);
            if (m_initialized)
            {
                m_renderTarget.BeginDraw();
                try
                {
                    m_renderTarget.Clear(new Color4(this.BackColor));

                    //Perform all Direct2D rendering here
                    m_renderTarget.FillRectangle(
                        m_backBrushEx,
                        new Rectangle(new Point(), this.Size));

                    //Apply quality
                    D2D.InterpolationMode interpolationMode = D2D.InterpolationMode.NearestNeighbor;
                    interpolationMode = D2D.InterpolationMode.Linear;

                    //Draw all images

                    if (gameOver || nextLevel)
                    {
                        m_renderTarget.DrawBitmap(level.Background, new Rectangle(0, 0, this.Width, this.Height), 1f, interpolationMode);
                    }
                    else
                    {
                        m_renderTarget.DrawBitmap(level.Background, new Rectangle(level.LevelPositionX, 0, 8352, 5300), 1f, interpolationMode);
                    }


                    foreach (Resources.EnemyShip ships in level.EnemyShipList)
                    {
                        if (ships.Destroyed == false)
                        {
                            m_renderTarget.DrawBitmap(enenyShipBitmap, new Rectangle(ships.PosX, ships.PosY, ships.ShipHitboxX, ships.ShipHitboxY), 1f, interpolationMode);
                        }
                    }

                    foreach (Resources.LevelObject levelObject in level.ObjectList)
                    {
                        m_renderTarget.DrawBitmap(levelObject.ObjectBitmap, new Rectangle(levelObject.PosX, levelObject.PosY, levelObject.RectangleBreite, levelObject.RectangleHoehe), 1f, interpolationMode);
                        if ((IntersectPixels(new Rectangle(_Player.PosX, _Player.PosY, _Player.ShipHitboxX, _Player.ShipHitboxY), spaceshipBitmapGDI, new Rectangle(levelObject.PosX, levelObject.PosY, levelObject.RectangleBreite, levelObject.RectangleHoehe), levelObject.ObjectBitmapGDI)) && (!invincible))
                        {
                            destroyed = true;
                        }
                    }

                    for (int i = _projektilListe.Count - 1; i >= 0; i--)
                    {
                        {
                            if ((_projektilListe[i].Visible == true) && (_projektilListe[i].PosX < this.Width) && (_projektilListe[i].PosX > 0) && (!gameOver))
                            {
                                if (_projektilListe[i].Hostile)
                                {
                                    m_renderTarget.DrawBitmap(projektileHostileBitmap, new Rectangle(_projektilListe[i].PosX, _projektilListe[i].PosY, 30, 5), 1f, interpolationMode);
                                }
                                else
                                {
                                    m_renderTarget.DrawBitmap(projektileBitmap, new Rectangle(_projektilListe[i].PosX, _projektilListe[i].PosY, 30, 5), 1f, interpolationMode);
                                }
                            }
                        }
                    }
                    if (destroyed)
                    {
                        if (lives > 0)
                        {
                            D2D.Bitmap continueScreen = LoadBitmap(continueScreenGDI);
                            pause = true;
                            m_renderTarget.DrawBitmap(continueScreen, new Rectangle(10, 200, 1052, 222), 1f, interpolationMode);
                        }
                        else
                        {
                            gameOver = true;
                            level.LoadLevelGameOver();
                            level.Background        = LoadBitmap(level.Backgroundgdi);
                            FinalScoreLabel.Visible = false;
                            FinalScoreLabel.Text    = "Score: " + score;
                            pause = true;
                            if (!groupBestOfTen.Visible)
                            {
                                labelHighScores.Text     = VanguardsHighScore.EinträgeAnzeigenPunkte("Flappy_Bird");
                                labelHighScores.Visible  = true;
                                labelText1.Visible       = true;
                                labelText2.Visible       = true;
                                labelPlayerName.Visible  = true;
                                labelFinalScore.Visible  = true;
                                applyScore.Visible       = true;
                                labelScore.Visible       = false;
                                labelFinalScore.Text     = score.ToString();
                                groupSubmitScore.Visible = true;
                            }
                        }
                    }
                    else if (nextLevel)
                    {
                        level.LoadLevelNextLevel();
                        level.Background        = LoadBitmap(level.Backgroundgdi);
                        FinalScoreLabel.Visible = true;
                        FinalScoreLabel.Text    = "Score: " + score;
                        pause = true;
                    }
                    else
                    {
                        m_renderTarget.DrawBitmap(_Player.getShipBitmap(), new Rectangle(_Player.PosX, _Player.PosY, _Player.ShipHitboxX, _Player.ShipHitboxY), 1f, interpolationMode);
                    }
                }
                finally
                {
                    m_renderTarget.EndDraw();
                }
            }
        }
Example #17
0
        private void InitalizeTileGameWorld()
        {
            // Initiailize the world.
            // =======================================================================================================

            // Load the tile sheet.
            m_TileSheet = LoadBitmap(Application.StartupPath + "\\TileSheet.png");


            // Set up our tile list.
            m_TileList = new List <Tile>();

            // The code below sets up the behavior of each sprite in terms of whether the player can walk on it or not.
            // It also specifies the position of each sprite in the sprite sheet so we know which tile to use to draw it.

            // First row of sprites in the sprite sheet.
            m_TileList.Add(new Tile()
            {
                IsSolid = false, SheetPosX = 0, SheetPosY = 0
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = false, SheetPosX = 1, SheetPosY = 0
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = false, SheetPosX = 2, SheetPosY = 0
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = false, SheetPosX = 3, SheetPosY = 0
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = false, SheetPosX = 4, SheetPosY = 0
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = false, SheetPosX = 5, SheetPosY = 0
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = false, SheetPosX = 6, SheetPosY = 0
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = true, SheetPosX = 7, SheetPosY = 0
            });

            // Second row of sprites in the sprite sheet.
            m_TileList.Add(new Tile()
            {
                IsSolid = true, SheetPosX = 0, SheetPosY = 1
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = true, SheetPosX = 1, SheetPosY = 1
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = true, SheetPosX = 2, SheetPosY = 1
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = true, SheetPosX = 3, SheetPosY = 1
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = true, SheetPosX = 4, SheetPosY = 1
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = true, SheetPosX = 5, SheetPosY = 1
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = true, SheetPosX = 6, SheetPosY = 1
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = true, SheetPosX = 7, SheetPosY = 1
            });

            // Third row of sprites in the sprite sheet.
            m_TileList.Add(new Tile()
            {
                IsSolid = false, SheetPosX = 0, SheetPosY = 2
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = false, SheetPosX = 1, SheetPosY = 2
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = false, SheetPosX = 2, SheetPosY = 2
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = false, SheetPosX = 3, SheetPosY = 2
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = false, SheetPosX = 4, SheetPosY = 2
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = false, SheetPosX = 5, SheetPosY = 2
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = false, SheetPosX = 6, SheetPosY = 2
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = false, SheetPosX = 7, SheetPosY = 2
            });

            // Fourth row of sprites in the sprite sheet.
            m_TileList.Add(new Tile()
            {
                IsSolid = false, SheetPosX = 0, SheetPosY = 3
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = false, SheetPosX = 1, SheetPosY = 3
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = false, SheetPosX = 2, SheetPosY = 3
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = false, SheetPosX = 3, SheetPosY = 3
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = false, SheetPosX = 4, SheetPosY = 3
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = false, SheetPosX = 5, SheetPosY = 3
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = false, SheetPosX = 6, SheetPosY = 3
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = false, SheetPosX = 7, SheetPosY = 3
            });

            // Fifth row of sprites in the sprite sheet.
            m_TileList.Add(new Tile()
            {
                IsSolid = true, SheetPosX = 0, SheetPosY = 4
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = true, SheetPosX = 1, SheetPosY = 4
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = true, SheetPosX = 2, SheetPosY = 4
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = true, SheetPosX = 3, SheetPosY = 4
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = true, SheetPosX = 4, SheetPosY = 4
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = true, SheetPosX = 5, SheetPosY = 4
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = true, SheetPosX = 6, SheetPosY = 4
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = true, SheetPosX = 7, SheetPosY = 4
            });

            // Sixth row of sprites in the sprite sheet.
            m_TileList.Add(new Tile()
            {
                IsSolid = true, SheetPosX = 0, SheetPosY = 5
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = true, SheetPosX = 1, SheetPosY = 5
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = true, SheetPosX = 2, SheetPosY = 5
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = true, SheetPosX = 3, SheetPosY = 5
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = true, SheetPosX = 4, SheetPosY = 5
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = true, SheetPosX = 5, SheetPosY = 5
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = true, SheetPosX = 6, SheetPosY = 5
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = true, SheetPosX = 7, SheetPosY = 5
            });

            // Seventh row of sprites in the sprite sheet.
            m_TileList.Add(new Tile()
            {
                IsSolid = true, SheetPosX = 0, SheetPosY = 6
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = true, SheetPosX = 1, SheetPosY = 6
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = true, SheetPosX = 2, SheetPosY = 6
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = true, SheetPosX = 3, SheetPosY = 6
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = true, SheetPosX = 4, SheetPosY = 6
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = true, SheetPosX = 5, SheetPosY = 6
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = true, SheetPosX = 6, SheetPosY = 6
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = true, SheetPosX = 7, SheetPosY = 6
            });

            // Eighth row of sprites in the sprite sheet.
            m_TileList.Add(new Tile()
            {
                IsSolid = true, SheetPosX = 0, SheetPosY = 7
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = true, SheetPosX = 1, SheetPosY = 7
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = true, SheetPosX = 2, SheetPosY = 7
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = true, SheetPosX = 3, SheetPosY = 7
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = true, SheetPosX = 4, SheetPosY = 7
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = true, SheetPosX = 5, SheetPosY = 7
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = true, SheetPosX = 6, SheetPosY = 7
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = true, SheetPosX = 7, SheetPosY = 7
            });

            // Nineth row of sprites in the sprite sheet.
            m_TileList.Add(new Tile()
            {
                IsSolid = true, SheetPosX = 0, SheetPosY = 8
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = true, SheetPosX = 1, SheetPosY = 8
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = true, SheetPosX = 2, SheetPosY = 8
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = true, SheetPosX = 3, SheetPosY = 8
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = true, SheetPosX = 4, SheetPosY = 8
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = true, SheetPosX = 5, SheetPosY = 8
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = true, SheetPosX = 6, SheetPosY = 8
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = true, SheetPosX = 7, SheetPosY = 8
            });

            // Tenth row of sprites in the sprite sheet.
            m_TileList.Add(new Tile()
            {
                IsSolid = false, SheetPosX = 0, SheetPosY = 9
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = false, SheetPosX = 1, SheetPosY = 9
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = true, SheetPosX = 2, SheetPosY = 9
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = true, SheetPosX = 3, SheetPosY = 9
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = false, SheetPosX = 4, SheetPosY = 9
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = false, SheetPosX = 5, SheetPosY = 9
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = false, SheetPosX = 6, SheetPosY = 9
            });
            m_TileList.Add(new Tile()
            {
                IsSolid = false, SheetPosX = 7, SheetPosY = 9
            });


            // Create our level.
            m_Map = new int[, ] {
                { 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14 },
                { 14, 10, 0, 3, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 53, 0, 0, 0, 0, 0, 3, 6, 25, 24, 6, 14 },
                { 14, 0, 12, 12, 12, 12, 12, 2, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 48, 1, 0, 0, 0, 10, 0, 6, 20, 21, 6, 14 },
                { 14, 0, 12, 7, 7, 7, 12, 0, 0, 0, 8, 0, 0, 0, 0, 4, 0, 0, 0, 0, 48, 0, 10, 0, 0, 0, 0, 6, 20, 21, 6, 14 },
                { 14, 3, 12, 7, 7, 7, 12, 0, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 48, 6, 6, 6, 6, 6, 6, 6, 20, 21, 6, 14 },
                { 14, 0, 12, 7, 7, 7, 12, 0, 6, 25, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 19, 18, 18, 18, 18, 18, 18, 18, 22, 23, 24, 14 },
                { 14, 0, 12, 12, 15, 12, 12, 9, 6, 17, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 26, 26, 26, 26, 26, 26, 26, 30, 31, 16, 14 },
                { 14, 0, 5, 11, 0, 0, 8, 0, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 48, 6, 6, 6, 6, 6, 6, 6, 20, 21, 6, 14 },
                { 14, 0, 0, 0, 0, 0, 0, 0, 0, 72, 0, 0, 0, 0, 0, 0, 56, 49, 57, 3, 48, 0, 10, 0, 0, 10, 0, 6, 20, 21, 6, 14 },
                { 14, 9, 0, 0, 0, 0, 0, 1, 75, 72, 74, 1, 0, 0, 2, 0, 48, 9, 63, 49, 50, 55, 13, 13, 13, 13, 13, 6, 20, 21, 6, 14 },
                { 14, 0, 0, 13, 13, 13, 13, 13, 13, 73, 13, 13, 13, 13, 0, 0, 58, 49, 59, 4, 48, 0, 13, 7, 7, 7, 13, 6, 20, 21, 6, 14 },
                { 14, 0, 0, 13, 73, 73, 73, 73, 13, 73, 73, 79, 73, 13, 0, 0, 0, 0, 0, 0, 48, 8, 13, 7, 7, 7, 13, 6, 20, 21, 6, 14 },
                { 14, 0, 0, 13, 13, 13, 76, 13, 13, 13, 13, 13, 78, 13, 0, 9, 0, 0, 0, 0, 48, 0, 13, 7, 7, 7, 13, 6, 20, 21, 6, 14 },
                { 14, 0, 8, 13, 73, 73, 73, 73, 73, 73, 13, 13, 78, 13, 0, 0, 0, 0, 0, 10, 48, 8, 13, 13, 15, 13, 13, 6, 20, 21, 6, 14 },
                { 14, 2, 0, 13, 73, 73, 73, 73, 73, 73, 77, 77, 73, 13, 5, 0, 0, 0, 0, 0, 48, 0, 0, 0, 72, 0, 11, 6, 20, 21, 6, 14 },
                { 14, 0, 0, 13, 73, 73, 73, 73, 73, 13, 13, 13, 13, 13, 0, 0, 0, 8, 0, 0, 48, 0, 0, 9, 72, 9, 0, 6, 20, 21, 6, 14 },
                { 14, 0, 0, 13, 73, 73, 73, 73, 73, 13, 0, 10, 3, 10, 0, 0, 0, 0, 1, 32, 38, 33, 4, 0, 72, 0, 0, 6, 20, 21, 6, 14 },
                { 14, 0, 0, 13, 13, 13, 78, 13, 13, 13, 3, 56, 49, 49, 57, 0, 0, 0, 32, 36, 51, 37, 35, 35, 35, 33, 2, 6, 20, 21, 6, 14 },
                { 14, 9, 0, 13, 73, 73, 73, 73, 73, 13, 10, 48, 9, 0, 54, 0, 0, 32, 36, 51, 51, 51, 45, 42, 44, 37, 33, 6, 20, 21, 6, 14 },
                { 14, 0, 0, 13, 13, 13, 13, 13, 13, 13, 32, 38, 33, 2, 0, 56, 49, 47, 51, 51, 51, 51, 43, 5, 34, 51, 37, 35, 28, 29, 35, 14 },
                { 14, 0, 0, 0, 0, 0, 0, 0, 0, 52, 47, 51, 39, 49, 60, 59, 8, 40, 44, 51, 51, 51, 37, 35, 36, 51, 51, 51, 28, 29, 51, 14 },
                { 14, 0, 0, 8, 0, 0, 8, 0, 4, 0, 40, 44, 43, 1, 48, 0, 3, 0, 40, 44, 51, 51, 51, 51, 51, 51, 45, 42, 28, 29, 42, 14 },
                { 14, 4, 0, 0, 0, 0, 0, 0, 0, 0, 2, 40, 68, 49, 62, 49, 55, 2, 0, 40, 42, 42, 42, 42, 42, 42, 41, 6, 17, 16, 6, 14 },
                { 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14 }
            };
        }
Example #18
0
        public Bitmap GetBitmap(string image)
        {
            Bitmap bitmap;
            bitmaps.TryGetValue(image, out bitmap);
            if (null == bitmap)
            {
                using (System.Drawing.Bitmap source = new System.Drawing.Bitmap(Path.Combine("Assets", image)))
                {
                    System.Drawing.Imaging.BitmapData sourceData = source.LockBits(
                        new Rectangle(0, 0, source.Width, source.Height),
                        System.Drawing.Imaging.ImageLockMode.ReadOnly,
                        System.Drawing.Imaging.PixelFormat.Format32bppPArgb
                    );

                    using (DataStream dataStream = new DataStream(sourceData.Scan0, sourceData.Stride * sourceData.Height, true, false))
                    {
                        bitmap = new Bitmap(renderTarget, new Size(source.Width, source.Height), dataStream, sourceData.Stride, bitmapProperties);
                        bitmaps[image] = bitmap;
                    }

                    source.UnlockBits(sourceData);
                }
            }
            return bitmap;
        }