Ejemplo 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();
        }
Ejemplo n.º 2
0
        //TODO: Need to render enemies at certain times. Don't know when, but probably need to put that here or in Advance
        public void Render()
        {
            //This is the soundtrack. This can be changed if necessary
            //sounds.Soundtrack();
            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();

            //score display
            font.DrawText(null,              // Because I say so
                          "Score: " + score, // Text to draw
                          new Point(25, 15), // Location on the display (pixels with 0,0 as upper left)
                          Color.LightCyan);  // Font color

            foreach (Polygon p in lasers)
            {
                p.Render(device);
            }

            foreach (Polygon p in enemies)
            {
                p.Render(device);
            }

            player.Render(device);

            //End the scene
            device.EndScene();
            device.Present();
        }
Ejemplo n.º 3
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
            // Static background
            //device.Transform.Projection = Matrix.OrthoOffCenterLH(0, widP, 0, playingH, 0, 1);

            // Background moves with player
            //float winCenter = playerLoc.X;
            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();
            // Render the floor polygon
            //floor.Render(device);
            // Render all the polygons in the world
            foreach (Polygon p in world)
            {
                p.Render(device);
            }


            if (coins.Count >= 1)
            {
                foreach (Polygon p in coins)
                {
                    p.Render(device);
                }
            }

            /*// Render the triangle (later a rectangle)
             * GraphicsStream gs = vertices.Lock(0, 0, 0);     // Lock the vertex list
             * int clr = Color.FromArgb(255, 0, 0).ToArgb();
             * int vertex_clr = Color.FromArgb(0, 255, 0).ToArgb();*/
            // To draw a simple rectangle

            /* gs.Write(new CustomVertex.PositionColored(1, 1, 0, clr));
             * gs.Write(new CustomVertex.PositionColored(1, 3, 0, clr));
             * gs.Write(new CustomVertex.PositionColored(3, 3, 0, clr));
             * // Change the color of one vertex
             * //gs.Write(new CustomVertex.PositionColored(3, 3, 0, vertex_clr));
             * // To draw rectangle
             * gs.Write(new CustomVertex.PositionColored(3, 1, 0, clr));
             */
            // To draw the block player

            /*gs.Write(new CustomVertex.PositionColored(playerLoc.X - 0.1f, playerLoc.Y, 0, clr));
             * gs.Write(new CustomVertex.PositionColored(playerLoc.X - 0.1f, playerLoc.Y + 0.5f, 0, clr));
             * gs.Write(new CustomVertex.PositionColored(playerLoc.X + 0.1f, playerLoc.Y + 0.5f, 0, clr));
             * gs.Write(new CustomVertex.PositionColored(playerLoc.X + 0.1f, playerLoc.Y, 0, clr));
             * vertices.Unlock();
             *
             * device.SetStreamSource(0, vertices, 0);
             * device.VertexFormat = CustomVertex.PositionColored.Format;
             * // To draw triangle
             * // device.DrawPrimitives(PrimitiveType.TriangleList, 0, 1);
             * // To draw rectangle
             * device.DrawPrimitives(PrimitiveType.TriangleFan, 0, 2);*/

            foreach (PolygonTextured p in powerup)
            {
                p.Render(device);
            }
            foreach (PolygonTextured p in swords)
            {
                p.Render(device);
            }
            //sword_sprite.Render(device);
            foreach (Wolverine w in wolverines)
            {
                w.Render(device);
            }
            flag.Render(device);
            player.Render(device);
            //End the scene

            Sprite sp = new Sprite(device);

            Microsoft.DirectX.Direct3D.Font font = new Microsoft.DirectX.Direct3D.Font(device, new System.Drawing.Font(System.Drawing.FontFamily.GenericSansSerif, 20f));
            font.DrawText(null, "score: " + score, new Point(3, 3), Color.Black);

            if (game_over == true)
            {
                //Microsoft.DirectX.Direct3D.Font font2 = new Microsoft.DirectX.Direct3D.Font(device, new System.Drawing.Font(System.Drawing.FontFamily.GenericSansSerif, 40f));
                font.DrawText(null, "You Win! Score:" + score, new Point(200, 200), Color.Black);
                font.Dispose();
            }
            font.Dispose();

            device.EndScene();
            device.Present();
        }
Ejemplo n.º 4
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
            // Static background
            //device.Transform.Projection = Matrix.OrthoOffCenterLH(0, widP, 0, playingH, 0, 1);

            // Background moves with player
            //float winCenter = playerLoc.X;
            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();
            // Render the floor polygon
            //floor.Render(device);
            // Render all the polygons in the world
            foreach (Polygon p in world)
            {
                p.Render(device);
            }

            player.Render(device);


            font.DrawText(null,              // Because I say so
                          "Score:" + score,  // Text to draw
                          new Point(10, 10), // Location on the display (pixels with 0,0 as upper left)
                          Color.LightCyan);  // Font color



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