protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Begin(); playerPaddle.Draw(spriteBatch); computerPaddle.Draw(spriteBatch); ball.Draw(spriteBatch); score.Draw(spriteBatch); spriteBatch.End(); base.Draw(gameTime); }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); // TODO: Add your drawing code here spriteBatch.Begin(); paddleOne.Draw(spriteBatch); paddleTwo.Draw(spriteBatch); ball.Draw(spriteBatch); spriteBatch.End(); base.Draw(gameTime); }
/// <summary> /// Draws game objects /// </summary> /// <param name="graphics">The canvas to draw to</param> public void Draw(Graphics graphics) { graphics.DrawLine(dashedLinePen, topCentre, bottomCentre); scoreRight.DrawScore(graphics); scoreLeft.DrawScore(graphics); rightPaddle.Draw(graphics); leftPaddle.Draw(graphics); ball.DrawSelf(graphics); if (winConditions == true) { DisplayVictory(graphics); } }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); // TODO: Add your drawing code here spriteBatch.Begin(); spriteBatch.Draw(background, bckgrndRectangle, Color.White); ball.Draw(spriteBatch); padLeft.Draw(spriteBatch); padRight.Draw(spriteBatch); DrawTexts(spriteBatch); spriteBatch.End(); base.Draw(gameTime); }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.Gray); spriteBatch.Begin(); // Draw GameObjects paddleOne.Draw(spriteBatch); paddleTwo.Draw(spriteBatch); ball.Draw(spriteBatch); // Write score string score = paddleOne.Score + ":" + paddleTwo.Score; spriteBatch.DrawString(defaultFont, score, new Vector2((GraphicsDevice.Viewport.Width / 2) - (defaultFont.MeasureString(score).X / 2), 0), Color.Black); spriteBatch.End(); base.Draw(gameTime); }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.Black); switch (currentGameState) { case GameState.Menu: spriteBatch.Begin(); spriteBatch.DrawString(font, "Basic Pong", new Vector2(250, 0), Color.Red); spriteBatch.End(); break; case GameState.Game: spriteBatch.Begin(); //double time = gameTime.ElapsedGameTime.TotalSeconds; spriteBatch.Draw(background, new Rectangle(0, 0, 800, 480), Color.Gray); spriteBatch.DrawString(font, (playerScore.X.ToString()), new Vector2(200, 0), Color.White); spriteBatch.DrawString(font, (playerScore.Y.ToString()), new Vector2(500, 0), Color.White); spriteBatch.End(); ball.Draw(spriteBatch); player1.Draw(spriteBatch); player2.Draw(spriteBatch); break; case GameState.Paused: spriteBatch.DrawString(font, "This is paused", new Vector2(200, 0), Color.White); spriteBatch.End(); break; } base.Draw(gameTime); }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { if (theme == Theme.Green) { GraphicsDevice.Clear(Color.DarkOliveGreen); } if (theme == Theme.Black) { GraphicsDevice.Clear(Color.Black); } if (theme == Theme.Pink) { GraphicsDevice.Clear(Color.HotPink); } if (theme == Theme.Rave) { Color background; background = new Color(x, y, z); GraphicsDevice.Clear(background); } if (theme == Theme.Changing) { Color background; background = new Color(a, b, c); GraphicsDevice.Clear(background); if (ball.Boundary.Intersects(player2.Boundary) || ball.Boundary.Intersects(player1.Boundary) || ball.Boundary.Top <= 0 || ball.Boundary.Bottom >= vWindowSize.Y) { change = 1; } else { change = 0; } } int points1 = ball.points1; int points2 = ball.points2; // TODO: Add your drawing code here //if (gameState == GameState.Menu) switch (gameState) { case GameState.Menu: string sTitle = "PONG"; Vector2 vTitle = fTitle.MeasureString(sTitle); Vector2 tCenter = new Vector2((float)(vWindowSize.X - vTitle.X) / 2, (float)50); string sMainMenu = "Press Enter to begin game!\nPress I for instructions\nPress S for settings\nPress ESC to Exit"; Vector2 vMainMenu = fText.MeasureString(sMainMenu); Vector2 vCentre = (vWindowSize - vMainMenu) / 2; //Draw the Main Menu on the screen spriteBatch.Begin(); spriteBatch.DrawString(fTitle, sTitle, tCenter, Color.PeachPuff); spriteBatch.DrawString(fText, sMainMenu, vCentre, Color.PeachPuff); spriteBatch.End(); break; case GameState.Play: spriteBatch.Begin(); player1.Draw(spriteBatch); player2.Draw(spriteBatch); string sPoints2 = "" + points2; string sPlayer1 = "Player 1"; string sPlayer2 = "Player 2"; Vector2 vPoints2 = fText.MeasureString(sPoints2); Vector2 vPlayer1 = fText.MeasureString(sPlayer1); Vector2 vPlayer2 = fText.MeasureString(sPlayer2); ball.Draw(spriteBatch); spriteBatch.DrawString(fText, "" + points1, new Vector2(75, 30), Color.White); spriteBatch.DrawString(fText, sPoints2, new Vector2((float)vWindowSize.X - (75 + (float)vPoints2.X), 30), Color.White); spriteBatch.DrawString(fText, sPlayer1, new Vector2((75 - ((float)vPlayer1.X / 2)), 0), Color.White); spriteBatch.DrawString(fText, sPlayer2, new Vector2((float)vWindowSize.X - (75 + ((float)vPlayer2.X / 2)), 0), Color.White); spriteBatch.End(); break; case GameState.Pause: sTitle = "PONG"; vTitle = fTitle.MeasureString(sTitle); tCenter = new Vector2((float)(vWindowSize.X - vTitle.X) / 2, (float)50); string sPauseMenu = "Press Enter to resume\nPress Escape to exit\n\nPress M to Return to the main menu\nPress R to restart"; Vector2 vPauseMenu = fText.MeasureString(sPauseMenu); Vector2 pCentre = (vWindowSize - vPauseMenu) / 2; //draw pause menu on screen spriteBatch.Begin(); spriteBatch.DrawString(fTitle, sTitle, tCenter, Color.PeachPuff); spriteBatch.DrawString(fText, sPauseMenu, pCentre, Color.PeachPuff); spriteBatch.End(); break; case GameState.GameOver: string sGameOver = "Press R to restart \n\nPress M to return to the main menu\n\nPress ESC to exit"; string sWinner1 = "Player 1 Wins!"; string sWinner2 = "Player 2 Wins!"; string sGameOverTitle = "Game Over"; Vector2 vGameOverTitle = fTitle.MeasureString(sGameOverTitle); Vector2 tGameOverCenter = new Vector2((float)(vWindowSize.X - vGameOverTitle.X) / 2, (float)50); Vector2 vGameOver = fText.MeasureString(sGameOver); Vector2 gCentre = (vWindowSize - vGameOver) / 2; Vector2 vWinner = fTitle.MeasureString(sWinner1); Vector2 wCenter = new Vector2((float)(vWindowSize.X - vWinner.X) / 2, (float)100); spriteBatch.Begin(); spriteBatch.DrawString(fTitle, sGameOverTitle, tGameOverCenter, Color.PeachPuff); spriteBatch.DrawString(fText, sGameOver, gCentre, Color.PeachPuff); if (ball.points2 == 10) { spriteBatch.DrawString(fTitle, sWinner1, wCenter, Color.PeachPuff); } if (ball.points1 == 10) { spriteBatch.DrawString(fTitle, sWinner2, wCenter, Color.PeachPuff); } spriteBatch.End(); break; case GameState.Exit: string sExit = "Would you like to exit\nPress Y to exit and N to continue"; sTitle = "PONG"; vTitle = fTitle.MeasureString(sTitle); tCenter = new Vector2((float)(vWindowSize.X - vTitle.X) / 2, (float)50); Vector2 vExit = fText.MeasureString(sExit); Vector2 cCentre = (vWindowSize - vExit) / 2; //draw exit menu on screen spriteBatch.Begin(); spriteBatch.DrawString(fTitle, sTitle, tCenter, Color.PeachPuff); spriteBatch.DrawString(fText, sExit, cCentre, Color.PeachPuff); spriteBatch.End(); break; case GameState.Instructions: sTitle = "PONG"; vTitle = fTitle.MeasureString(sTitle); tCenter = new Vector2((float)(vWindowSize.X - vTitle.X) / 2, (float)50); string sInstructions = "INSTRUCTIONS:\nUse the paddle to hit to ball to your opponent\nIf the ball goes past your paddle your opponent gets a point\nThe ball gets faster every time it hits a paddle\nThe first player to 10 points wins!\n\nCONTROLS:\nUse the W and S keys to move Player 1\nUse Up and Down to move Player 2\nPress P to pause the game\nPress ESC to exit the game\n\nPress M to return to the menu"; Vector2 vInstructions = fInstructionMenu.MeasureString(sInstructions); Vector2 iCentre = (vWindowSize - vInstructions) / 2; //draw instructions on screen spriteBatch.Begin(); spriteBatch.DrawString(fTitle, sTitle, tCenter, Color.PeachPuff); spriteBatch.DrawString(fInstructionMenu, sInstructions, iCentre, Color.PeachPuff); spriteBatch.End(); break; case GameState.Settings: sTitle = "PONG"; vTitle = fTitle.MeasureString(sTitle); tCenter = new Vector2((float)(vWindowSize.X - vTitle.X) / 2, (float)50); string sSettings = "Press E for easy and H for hard\nPress M to return to the menu\n\nPress P for Pink Theme\nPress B for Black Theme\nPress G for Green Theme\nPress R for Rave\nPress C for Chaning Colors"; string sEasy = "EASY"; string sHard = "HARD"; Vector2 vEasy = fTitle.MeasureString(sEasy); Vector2 vHard = fTitle.MeasureString(sHard); Vector2 vSettings = fText.MeasureString(sSettings); Vector2 sCentre = (vWindowSize - vSettings) / 2; //draw settings on screen spriteBatch.Begin(); spriteBatch.DrawString(fTitle, sTitle, tCenter, Color.PeachPuff); spriteBatch.DrawString(fText, sSettings, sCentre, Color.PeachPuff); if (difficulty == Difficulty.Easy) { spriteBatch.DrawString(fTitle, sEasy, new Vector2(20, (float)vWindowSize.Y - (float)vEasy.Y), Color.Yellow); spriteBatch.DrawString(fTitle, sHard, new Vector2((float)vWindowSize.X - (float)vHard.X, (float)vWindowSize.Y - (float)vHard.Y), Color.PeachPuff); } if (difficulty == Difficulty.Hard) { spriteBatch.DrawString(fTitle, sEasy, new Vector2(20, (float)vWindowSize.Y - (float)vEasy.Y), Color.PeachPuff); spriteBatch.DrawString(fTitle, sHard, new Vector2((float)vWindowSize.X - (float)vHard.X, (float)vWindowSize.Y - (float)vHard.Y), Color.Yellow); } spriteBatch.End(); break; } base.Draw(gameTime); }
private void MainLoop(object sender, EventArgs e) { /* Clears the Screen */ CreateGraphics().FillRectangle(new SolidBrush(Color.Black), 0, 0, 800, 600); pongBall.Draw(this.CreateGraphics()); right.Draw(this.CreateGraphics()); left.Draw(CreateGraphics()); pongBall.calculate(); if (pongBall.getX() <= 0) { left.setPoints(left.getPoints() + 1); if (left.getPoints() >= numberOfPointsToWin) { CreateGraphics().FillRectangle(new SolidBrush(Color.Black), 0, 0, 800, 600); CreateGraphics().DrawString("Right WINS!", new Font("Arial", 72), new SolidBrush(Color.White), new PointF(100, 100)); t.Enabled = false; } right.setX(770); right.setY(250); left.setX(30); left.setY(250); pongBall.setX(400); pongBall.setY(300); pongBall.setXVelocity((int)(randomObject.Next(4, pongBall.getMaxSpeed() * 2) - pongBall.getMaxSpeed())); pongBall.setYVelocity((int)(randomObject.Next(4, pongBall.getMaxSpeed() * 2) - pongBall.getMaxSpeed())); } if (pongBall.getX() >= 800) { right.setPoints(right.getPoints() + 1); if (right.getPoints() >= numberOfPointsToWin) { CreateGraphics().FillRectangle(new SolidBrush(Color.Black), 0, 0, 800, 600); CreateGraphics().DrawString("LEFT WINS!", new Font("Arial", 72), new SolidBrush(Color.White), new PointF(90, 100)); t.Enabled = false; return; } right.setX(770); right.setY(250); left.setX(30); left.setY(250); pongBall.setX(400); pongBall.setY(300); pongBall.setXVelocity((int)(randomObject.Next(4, pongBall.getMaxSpeed() * 2) - pongBall.getMaxSpeed())); pongBall.setYVelocity((int)(randomObject.Next(4, pongBall.getMaxSpeed() * 2) - pongBall.getMaxSpeed())); } if (pongBall.getY() >= 600) { pongBall.setYVelocity(-pongBall.getYVelocity()); } if (pongBall.getY() <= 0) { pongBall.setYVelocity(-pongBall.getYVelocity()); } if (pongBall.getX() <= left.getX() + left.getWidth() && pongBall.getX() >= left.getX()) { if (pongBall.getY() <= left.getY() + left.getHeight() && pongBall.getY() >= left.getY()) { pongBall.setXVelocity(-pongBall.getXVelocity()); } } if (pongBall.getX() <= right.getX() + right.getWidth() && pongBall.getX() >= right.getX()) { if (pongBall.getY() <= right.getY() + right.getHeight() && pongBall.getY() >= right.getY()) { pongBall.setXVelocity(-pongBall.getXVelocity()); } } CreateGraphics().DrawString(right.getPoints() + "", new Font("Arial", 72), new SolidBrush(Color.White), new PointF(100, 100)); CreateGraphics().DrawString(left.getPoints() + "", new Font("Arial", 72), new SolidBrush(Color.White), new PointF(600, 100)); Console.WriteLine("Pong Ball Position - X: " + pongBall.getX() + " Y: " + pongBall.getY()); Console.WriteLine("Paddle Left Position - X: " + left.getX() + " Y: " + left.getY()); if (right.getPoints() >= numberOfPointsToWin) { CreateGraphics().FillRectangle(new SolidBrush(Color.Black), 0, 0, 800, 600); CreateGraphics().DrawString("LEFT WINS!", new Font("Arial", 72), new SolidBrush(Color.White), new PointF(90, 100)); t.Enabled = false; return; } if (left.getPoints() >= numberOfPointsToWin) { CreateGraphics().FillRectangle(new SolidBrush(Color.Black), 0, 0, 800, 600); CreateGraphics().DrawString("Right WINS!", new Font("Arial", 72), new SolidBrush(Color.White), new PointF(100, 100)); t.Enabled = false; return; } }
/// <summary> /// Här ritas alla textures ut vid olika tidpunkter. Först ritas menyskärmen ut, spelet kollar ifall den är false så ritas loading screenen ut. /// Efter 5 sekunder ritas själva spelet ut. Draw metoden i main tar metoder från de andra klasserna, alltså ritas iget ut direkt ifrån main. /// Penga regnet loopas bara igenom här och ritar ut alla mynt som finns i listan, det är update som rör på mynten. /// </summary> //Här ritas all spelgrafik ut #region Draw metod för main protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.White); spriteBatch.Begin(); menuScreen.Draw(spriteBatch); //Ritar ut alla väljbara bakgrunder ifall menyskärmen är aktiv #region if (menuScreen.GameState == true) { menuScreen.Draw(spriteBatch); //Ritar ut alla mynt som finns i listan for (int i = 0; i < coins.Count; i++) { coins[i].Draw(spriteBatch); } backGround1.Draw(spriteBatch); backGround2.Draw(spriteBatch); backGround3.Draw(spriteBatch); backGround4.Draw(spriteBatch); backGround5.Draw(spriteBatch); backGroundFont.Draw2(spriteBatch); } #endregion //Ritar ut loading screen i 5 sekunder if (globalTimer > 0 && globalTimer < 5) { backGroundFont2.Draw3(spriteBatch); } //Ifall menyskärmen inte visas och ifall blobala timern är större än 5, gör följande if (menuScreen.GameState == false && globalTimer > 5) { //Ifall intersect är ett nummer från 1 till 5, rita ut respektive nummers bakgrundsbild #region if (backGround1.Intersect) { backGround1.Draw4(spriteBatch); } if (backGround2.Intersect) { backGround2.Draw4(spriteBatch); } if (backGround3.Intersect) { backGround3.Draw4(spriteBatch); } if (backGround4.Intersect) { backGround4.Draw4(spriteBatch); } if (backGround5.Intersect) { backGround5.Draw4(spriteBatch); } #endregion //Ritar ut paddlar, boll och bonus #region rightPaddle.Draw(spriteBatch); leftPaddle.Draw(spriteBatch); ball1.Draw(spriteBatch); score1.Draw(spriteBatch, Window); box.Draw(spriteBatch); #endregion } spriteBatch.End(); // TODO: Add your drawing code here. base.Draw(gameTime); }