public void Render(FrameEventArgs e)
        {
            GL.Viewport(0, 0, sceneManager.Width, sceneManager.Height);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            projectionMatrix = Matrix4.CreateOrthographicOffCenter(0, sceneManager.Width, 0, sceneManager.Height, -1.0f, +1.0f);

            ball.Render(projectionMatrix);
            paddlePlayer.Render(projectionMatrix);
            paddlePlayer2.Render(projectionMatrix);
            speedPowerUp.Render(projectionMatrix);
            lengthPowerUp.Render(projectionMatrix);

            float width = sceneManager.Width, height = sceneManager.Height, fontSize = Math.Min(width, height) / 10f;

            GUI.Label(new Rectangle(0, (int)(fontSize / 5f), (int)width, (int)(fontSize * 1f)), ("" + scorePlayer), (int)fontSize / 2, StringAlignment.Near);
            GUI.Label(new Rectangle(0, (int)(fontSize / 5f), (int)width, (int)(fontSize * 1f)), (scorePlayer2 + ""), (int)fontSize / 2, StringAlignment.Far);
            if (GamerOver == false)
            {
                GUI.Label(new Rectangle(0, (int)(fontSize / 5f), (int)width, (int)(fontSize * 1f)), ("Time: " + clock + "." + Timer), (int)fontSize / 2, StringAlignment.Center);
            }
            else
            {
                GUI.Label(new Rectangle(0, (int)(fontSize / 5f), (int)width, (int)(fontSize * 10f)), ("Game Over"), (int)fontSize * 2, StringAlignment.Center);
                GUI.Label(new Rectangle(0, (int)(fontSize * 3f), (int)width, (int)(fontSize * 10f)), (" " + winner), (int)fontSize / 2, StringAlignment.Center);
            }
            //GUI.Label(new Rectangle(0, (int)(fontSize / 16f), (int)width, (int)(fontSize * 4f)), ("Player " + scorePlayer + "       AI: " + scoreAI), (int)fontSize, StringAlignment.Center);
            //GUI.Label(new Rectangle(0, (int)(fontSize / 16f), (int)width, (int)(fontSize * 4f)), ("X " + ball.Velocity.X + "       Y: " + ball.Velocity.Y), (int)fontSize, StringAlignment.Center);
            GUI.Render();
        }
Exemplo n.º 2
0
        public void Render(FrameEventArgs e)
        {
            GL.Viewport(0, 0, sceneManager.Width, sceneManager.Height);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            projectionMatrix = Matrix4.CreateOrthographicOffCenter(0, sceneManager.Width, 0, sceneManager.Height, -1.0f, +1.0f);

            ball.Render(projectionMatrix);
            paddlePlayer.Render(projectionMatrix);
            paddlePlayer2.Render(projectionMatrix);
        }
Exemplo n.º 3
0
        // Called each frame after update; is responsible simply for
        // drawing all of our game objects and more to the screen.
        public override async Task Draw()
        {
            Graphics.Begin();

            // begin drawing with push, in our virtual resolution
            Graphics.Clear(40, 45, 52);

            Graphics.SetColor(255, 255, 255);

            // render different things depending on which part of the game we're in
            if (gameState == GameState.Start)
            {
                // UI messages
                Graphics.SetFont(smallFont);
                Graphics.Print("Wellcome to Pong!", 0, 10, VirtualWidth, Alignment.Center);
                Graphics.Print("Press Enter to begin!", 0, 20, VirtualWidth, Alignment.Center);
            }
            else if (gameState == GameState.Serve)
            {
                // UI messages
                Graphics.SetFont(smallFont);
                Graphics.Print($"Player {servingPlayer}\\'s serve!", 0, 10, VirtualWidth, Alignment.Center);
                Graphics.Print("Press Enter to serve!", 0, 20, VirtualWidth, Alignment.Center);
            }
            else if (gameState == GameState.Play)
            {
                // No UI messages to display in play
            }
            else if (gameState == GameState.Done)
            {
                // UI messages
                Graphics.SetFont(largeFont);
                Graphics.Print($"Player {winningPlayer} wins!", 0, 10, VirtualWidth, Alignment.Center);
                Graphics.SetFont(smallFont);
                Graphics.Print("Press Enter to restart!", 0, 30, VirtualWidth, Alignment.Center);
            }

            // show the score before ball is rendered so it can move over the text
            DisplayScore();

            player1.Render();
            player2.Render();
            ball.Render();

            // Display FPS for debugging; simply comment out to remove
            // DisplayFps();

            await Graphics.Apply();
        }