Exemplo n.º 1
0
        public void Render()
        {
            if (device == null)
            {
                return;
            }

            device.Clear(ClearFlags.Target, System.Drawing.Color.Blue, 1.0f, 0);

            int   wid    = Width;                         // Width of our display window
            int   hit    = Height;                        // Height of our display window.
            float aspect = (float)wid / (float)hit;       // What is the aspect ratio?

            device.RenderState.ZBufferEnable = false;     // We'll not use this feature
            device.RenderState.Lighting      = false;     // Or this one...
            device.RenderState.CullMode      = Cull.None; // Or this one...

            float widP = playingH * aspect;               // Total width of window

            float winCenter = player.P.X;

            if (winCenter - widP / 2 < 0)
            {
                winCenter = widP / 2;
            }
            else if (winCenter + widP / 2 > playingW)
            {
                winCenter = playingW - widP / 2;
            }

            device.Transform.Projection = Matrix.OrthoOffCenterLH(winCenter - widP / 2,
                                                                  winCenter + widP / 2,
                                                                  0, playingH, 0, 1);

            //Begin the scene
            device.BeginScene();

            // Render the background
            background.Render();
            foreach (Polygon p in world)
            {
                p.Render(device);
            }


            player.Render(device);

            score.DisplayScore();
            lives.DisplayLives();

            if (game_over.gameOver)
            {
                game_over.DisplayGameOver();
                score.DisplayFinalScore();
            }

            //End the scene
            device.EndScene();
            device.Present();
        }