コード例 #1
0
        //Zeichnet alle Graphiken
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            if (m_initialized)
            {
                m_renderTarget.BeginDraw();
                try
                {
                    m_renderTarget.Clear(new Color4(this.BackColor));
                    Rectangle        birdRecktangle = new Rectangle(player.BirdPosx, player.BirdPosy, 68, 48);
                    SlimDX.Matrix3x2 rotationMatrix = new SlimDX.Matrix3x2();
                    SlimDX.Matrix3x2 standartMatrix = new SlimDX.Matrix3x2();
                    //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
                    m_renderTarget.DrawBitmap(backGroundBitmap, new Rectangle(0, 0, 1276, 720), 1f, interpolationMode);
                    foreach (Resources.Pipe_Pair pipes in pipePairList)
                    {
                        Rectangle upperRectangle = new Rectangle(pipes.PipePairPosx, pipes.PipePairPosy, 104, 640);
                        Rectangle lowerRectangle = new Rectangle(pipes.PipePairPosx, pipes.PipePairPosy + 640 + 200, 104, 640);
                        m_renderTarget.DrawBitmap(pipeUperBitmap, upperRectangle, 1f, interpolationMode);
                        m_renderTarget.DrawBitmap(pipeLowerBitmap, lowerRectangle, 1f, interpolationMode);
                        if ((player.BirdPosx >= (pipes.PipePairPosx)) && (pipes.Scored == false))
                        {
                            score       += 1;
                            pipes.Scored = true;
                        }
                        if (upperRectangle.IntersectsWith(birdRecktangle) || lowerRectangle.IntersectsWith(birdRecktangle))
                        {
                            pause    = true;
                            gameOver = true;
                            if (!groupBestOfTen.Visible)
                            {
                                labelHighScores.Visible  = true;
                                labelText1.Visible       = true;
                                labelText2.Visible       = true;
                                labelPlayerName.Visible  = true;
                                labelFinalScore.Visible  = true;
                                applyScore.Visible       = true;
                                Score.Visible            = false;
                                labelFinalScore.Text     = score.ToString();
                                groupSubmitScore.Visible = true;
                            }
                        }
                    }
                    foreach (Resources.Ground ground in groundList)
                    {
                        Rectangle groundRectangle = new Rectangle(ground.GroundPosX1, this.Height - 120, 720, 120);
                        m_renderTarget.DrawBitmap(groundBitmap, groundRectangle, 1f, interpolationMode);
                        if (groundRectangle.IntersectsWith(birdRecktangle))
                        {
                            if (!groupBestOfTen.Visible)
                            {
                                labelHighScores.Text    = flappyBirdHighScore.EinträgeAnzeigenPunkte("Flappybird");
                                labelHighScores.Visible = true;
                                labelText1.Visible      = true;
                                labelText2.Visible      = true;
                                labelPlayerName.Visible = true;
                                labelFinalScore.Visible = true;
                                applyScore.Visible      = true;
                                Score.Visible           = false;
                                labelFinalScore.Text    = score.ToString();
                                pause    = true;
                                gameOver = true;
                                groupSubmitScore.Visible = true;
                            }
                        }
                    }

                    PointF rotationPoint = new PointF(player.BirdPosx + (birdRecktangle.Width / 2), player.BirdPosy + (birdRecktangle.Height / 2));
                    rotationMatrix           = Matrix3x2.Rotation(altitudeValue * 6, rotationPoint);
                    m_renderTarget.Transform = rotationMatrix;



                    m_renderTarget.DrawBitmap(birdBitmap, birdRecktangle, 1f, interpolationMode);
                    Matrix3x2.Translation(0, 0, out rotationMatrix);


                    rotationMatrix           = Matrix3x2.Rotation(0);
                    m_renderTarget.Transform = rotationMatrix;
                    Score.Parent             = this;
                    Score.Text = score.ToString();
                }
                finally
                {
                    m_renderTarget.EndDraw();
                }
            }
        }
コード例 #2
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();
                }
            }
        }