<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Visual Studio Archives - SoftUni Global</title>
	<atom:link href="https://softuni.org/tag/visual-studio/feed/" rel="self" type="application/rss+xml" />
	<link>https://softuni.org/tag/visual-studio/</link>
	<description>Learn Programming and Start a Developer Job</description>
	<lastBuildDate>Mon, 17 Oct 2022 06:57:59 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://softuni.org/wp-content/uploads/2022/04/cropped-SoftUni-Global-Logo-Square-notext-32x32.png</url>
	<title>Visual Studio Archives - SoftUni Global</title>
	<link>https://softuni.org/tag/visual-studio/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>How To Make A Pong Game in C#: Step-by-step Guide [Project Tutorials]</title>
		<link>https://softuni.org/project-tutorials/how-to-make-a-pong-game-in-csharp-guide/</link>
					<comments>https://softuni.org/project-tutorials/how-to-make-a-pong-game-in-csharp-guide/#comments</comments>
		
		<dc:creator><![CDATA[Nikol Ruseva]]></dc:creator>
		<pubDate>Thu, 01 Sep 2022 14:15:30 +0000</pubDate>
				<category><![CDATA[Step-by-Step Project Tutorials]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[game development]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[software development]]></category>
		<category><![CDATA[step-by-step]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<guid isPermaLink="false">https://softuni.org/?p=23082</guid>

					<description><![CDATA[<p>In this edition of the Project Tutorial series, we will create a simple Pong game with C#.</p>
<p>The post <a href="https://softuni.org/project-tutorials/how-to-make-a-pong-game-in-csharp-guide/">How To Make A Pong Game in C#: Step-by-step Guide [Project Tutorials]</a> appeared first on <a href="https://softuni.org">SoftUni Global</a>.</p>
]]></description>
										<content:encoded><![CDATA[		<div data-elementor-type="wp-post" data-elementor-id="23082" class="elementor elementor-23082" data-elementor-post-type="post">
						<section class="elementor-section elementor-top-section elementor-element elementor-element-5d5405e elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="5d5405e" data-element_type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-0d32134" data-id="0d32134" data-element_type="column">
			<div class="elementor-widget-wrap elementor-element-populated">
						<div class="elementor-element elementor-element-9216798 elementor-widget elementor-widget-text-editor" data-id="9216798" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>Pong is a two-dimensional sports game that is similar to table tennis. It is one of the earliest video games, first released in 1972. Since then, it has been recreated multiple times in different programming languages. Today, you will learn how to make <strong>your own version</strong> of the game using <strong>simple</strong> <strong>programming concepts in C#</strong>.</p><p>Let’s begin.</p>								</div>
				</div>
				<div class="elementor-element elementor-element-2041cf4 elementor-widget elementor-widget-heading" data-id="2041cf4" data-element_type="widget" data-widget_type="heading.default">
				<div class="elementor-widget-container">
					<h2 class="elementor-heading-title elementor-size-xl">Creating the Field</h2>				</div>
				</div>
				<div class="elementor-element elementor-element-c74cf06 elementor-widget elementor-widget-text-editor" data-id="c74cf06" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>First, you need to prepare the field with an upper and a lower border and two rackets. Declare two constants of type int that define the dimensions of the field &#8211; <b>fieldWidth </b>and <b>fieldLength. </b>To visualize the upper and the lower border, use the string method <b>Repeat </b>on the <b>fieldTile </b>character variable.</p>								</div>
				</div>
				<div class="elementor-element elementor-element-6a49652 elementor-widget elementor-widget-code-highlight" data-id="6a49652" data-element_type="widget" data-widget_type="code-highlight.default">
				<div class="elementor-widget-container">
							<div class="prismjs-default copy-to-clipboard ">
			<pre data-line="" class="highlight-height language-csharp line-numbers">
				<code readonly="true" class="language-csharp">
					<xmp>const int fieldLength = 50, fieldWidth = 15;
const char fieldTile = '#';
string line = string.Concat(Enumerable.Repeat(fieldTile, fieldLength));</xmp>
				</code>
			</pre>
		</div>
						</div>
				</div>
				<div class="elementor-element elementor-element-411639f elementor-widget elementor-widget-text-editor" data-id="411639f" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>Then create the game loop and <b>print </b>the borders on the console. The first line starts from coordinates <b>0,0</b> and the second one &#8211; <b>0, fieldWidth</b>(15).</p>								</div>
				</div>
				<div class="elementor-element elementor-element-f4a4827 elementor-widget elementor-widget-code-highlight" data-id="f4a4827" data-element_type="widget" data-widget_type="code-highlight.default">
				<div class="elementor-widget-container">
							<div class="prismjs-default copy-to-clipboard ">
			<pre data-line="" class="highlight-height language-csharp line-numbers">
				<code readonly="true" class="language-csharp">
					<xmp>while(true) 
{ 
    Console.SetCursorPosition(0,0);
    Console.WriteLine(line);

    Console.SetCursorPosition(0,fieldWidth);
    Console.WriteLine(line);
}
</xmp>
				</code>
			</pre>
		</div>
						</div>
				</div>
				<div class="elementor-element elementor-element-b3697b2 elementor-widget elementor-widget-text-editor" data-id="b3697b2" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>Next, make a variable for the rackets’ size &#8211; <b>racketLength, </b>for the character used to visualize them &#8211; <b>racketTile, </b>and for their positions &#8211; <b>leftRacketHeight </b>and <b>rightRacketHeight</b>.</p>								</div>
				</div>
				<div class="elementor-element elementor-element-4b97940 elementor-widget elementor-widget-code-highlight" data-id="4b97940" data-element_type="widget" data-widget_type="code-highlight.default">
				<div class="elementor-widget-container">
							<div class="prismjs-default copy-to-clipboard ">
			<pre data-line="" class="highlight-height language-csharp line-numbers">
				<code readonly="true" class="language-csharp">
					<xmp>const int racketLength = fieldWidth / 4;
const char racketTile = '|';
            
int leftRacketHeight = 0;
int rightRacketHeight = 0;</xmp>
				</code>
			</pre>
		</div>
						</div>
				</div>
				<div class="elementor-element elementor-element-138d7ce elementor-widget elementor-widget-text-editor" data-id="138d7ce" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>To make the rackets appear on the field,add a <b>for loop </b>in the game loop.</p>								</div>
				</div>
				<div class="elementor-element elementor-element-ecc7ef9 elementor-widget elementor-widget-code-highlight" data-id="ecc7ef9" data-element_type="widget" data-widget_type="code-highlight.default">
				<div class="elementor-widget-container">
							<div class="prismjs-default copy-to-clipboard ">
			<pre data-line="" class="highlight-height language-csharp line-numbers">
				<code readonly="true" class="language-csharp">
					<xmp>for(int i = 0; i < racketLength; i++)
{
    Console.SetCursorPosition(0, i + 1 + leftRacketHeight);
    Console.WriteLine(racketTile);
    Console.SetCursorPosition(fieldLength - 1, i + 1 + rightRacketHeight);
    Console.WriteLine(racketTile);
}</xmp>
				</code>
			</pre>
		</div>
						</div>
				</div>
				<div class="elementor-element elementor-element-0853386 elementor-widget elementor-widget-spacer" data-id="0853386" data-element_type="widget" data-widget_type="spacer.default">
				<div class="elementor-widget-container">
							<div class="elementor-spacer">
			<div class="elementor-spacer-inner"></div>
		</div>
						</div>
				</div>
				<div class="elementor-element elementor-element-000838a elementor-widget elementor-widget-heading" data-id="000838a" data-element_type="widget" data-widget_type="heading.default">
				<div class="elementor-widget-container">
					<h2 class="elementor-heading-title elementor-size-xl">Player Movement</h2>				</div>
				</div>
				<div class="elementor-element elementor-element-550d174 elementor-widget elementor-widget-text-editor" data-id="550d174" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>Make a loop that will continue until a key is pressed. After the loop, check <b>which key has been pressed</b> using a switch and <b>update the rackets’ positions</b> based on that. C<b>lear the previous positions</b> with another for loop.</p>								</div>
				</div>
				<div class="elementor-element elementor-element-7dbb766 elementor-widget elementor-widget-code-highlight" data-id="7dbb766" data-element_type="widget" data-widget_type="code-highlight.default">
				<div class="elementor-widget-container">
							<div class="prismjs-default copy-to-clipboard ">
			<pre data-line="" class="highlight-height language-csharp line-numbers">
				<code readonly="true" class="language-csharp">
					<xmp>while(!Console.KeyAvailable)
{
    
}
           
//Check which key has been pressed
switch(Console.ReadKey().Key)
{
    case ConsoleKey.UpArrow:
    if(rightRacketHeight > 0)
    {
        rightRacketHeight--;
    }
    break;

    case ConsoleKey.DownArrow:
    if(rightRacketHeight < fieldWidth - racketLength - 1)
    {
        rightRacketHeight++;
    }
    break;

    case ConsoleKey.W:
    if(leftRacketHeight > 0)
    {
        leftRacketHeight--;
    }
    break;
    
    case ConsoleKey.S:
    if(leftRacketHeight < fieldWidth - racketLength - 1)
    {
        leftRacketHeight++;
    }
    break;
}

//Clear the rackets’ previous positions
for(int i = 1; i < fieldWidth; i++)             
{
Console.SetCursorPosition(0,i);
Console.WriteLine(" ");
Console.SetCursorPosition(fieldLength - 1,i);
Console.WriteLine(" ");
}</xmp>
				</code>
			</pre>
		</div>
						</div>
				</div>
				<div class="elementor-element elementor-element-3e05056 elementor-widget elementor-widget-spacer" data-id="3e05056" data-element_type="widget" data-widget_type="spacer.default">
				<div class="elementor-widget-container">
							<div class="elementor-spacer">
			<div class="elementor-spacer-inner"></div>
		</div>
						</div>
				</div>
				<div class="elementor-element elementor-element-91b4156 elementor-widget elementor-widget-heading" data-id="91b4156" data-element_type="widget" data-widget_type="heading.default">
				<div class="elementor-widget-container">
					<h2 class="elementor-heading-title elementor-size-xl">Adding a Ball</h2>				</div>
				</div>
				<div class="elementor-element elementor-element-06be0a6 elementor-widget elementor-widget-text-editor" data-id="06be0a6" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>What you need to know about the ball is its <b>coordinates</b>, the <b>character representation </b>on the field, and its <b>direction</b>.</p>								</div>
				</div>
				<div class="elementor-element elementor-element-ee2595f elementor-widget elementor-widget-code-highlight" data-id="ee2595f" data-element_type="widget" data-widget_type="code-highlight.default">
				<div class="elementor-widget-container">
							<div class="prismjs-default copy-to-clipboard ">
			<pre data-line="" class="highlight-height language-csharp line-numbers">
				<code readonly="true" class="language-csharp">
					<xmp>int ballX = fieldLength / 2;
    int ballY = fieldWidth / 2;
    const char ballTile = 'O';

    bool isBallGoingDown = true;
    bool isBallGoingRight = true;</xmp>
				</code>
			</pre>
		</div>
						</div>
				</div>
				<div class="elementor-element elementor-element-473d62c elementor-widget elementor-widget-text-editor" data-id="473d62c" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>Let’s go back to the empty while loop that waits for a key to be pressed. It has to <strong>update the ball’s position.</strong></p>								</div>
				</div>
				<div class="elementor-element elementor-element-886c880 elementor-widget elementor-widget-code-highlight" data-id="886c880" data-element_type="widget" data-widget_type="code-highlight.default">
				<div class="elementor-widget-container">
							<div class="prismjs-default copy-to-clipboard ">
			<pre data-line="" class="highlight-height language-csharp line-numbers">
				<code readonly="true" class="language-csharp">
					<xmp>while(!Console.KeyAvailable)
{
    Console.SetCursorPosition(ballX, ballY);
    Console.WriteLine(ballTile);
    Thread.Sleep(100); //Adds a timer so that the players have time to react
    
    Console.SetCursorPosition(ballX, ballY);
    Console.WriteLine(" "); //Clears the previous position of the ball
    
    //Update position of the ball
    if(isBallGoingDown)
    {
    ballY++;
    } else
    {
    ballY--;
    }
    if(isBallGoingRight)
    {
    ballX++;
    } else
    {
    ballX--;
    }
}</xmp>
				</code>
			</pre>
		</div>
						</div>
				</div>
				<div class="elementor-element elementor-element-2a20d4a elementor-widget elementor-widget-text-editor" data-id="2a20d4a" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>However, this code does not limit the movement of the ball to the borders of the field. You need to add more conditions to the same while loop and declare variables to store the players’ points.</p>								</div>
				</div>
				<div class="elementor-element elementor-element-be03d22 elementor-widget elementor-widget-code-highlight" data-id="be03d22" data-element_type="widget" data-widget_type="code-highlight.default">
				<div class="elementor-widget-container">
							<div class="prismjs-default copy-to-clipboard ">
			<pre data-line="" class="highlight-height language-javascript line-numbers">
				<code readonly="true" class="language-javascript">
					<xmp>int leftPlayerPoints = 0;
int rightPlayerPoints = 0;
</xmp>
				</code>
			</pre>
		</div>
						</div>
				</div>
				<div class="elementor-element elementor-element-798a6f4 elementor-widget elementor-widget-code-highlight" data-id="798a6f4" data-element_type="widget" data-widget_type="code-highlight.default">
				<div class="elementor-widget-container">
							<div class="prismjs-default copy-to-clipboard ">
			<pre data-line="" class="highlight-height language-javascript line-numbers">
				<code readonly="true" class="language-javascript">
					<xmp>if(ballY == 1 || ballY == fieldWidth - 1)
{
isBallGoingDown = !isBallGoingDown; //Change direction
}

if(ballX == 1)
{
    //Left racket hits the ball and it bounces
   if(ballY >= leftRacketHeight + 1 && ballY <= leftRacketHeight + racketLength) 
   {
       isBallGoingRight = !isBallGoingRight;
   }
   else //Ball goes out of the field; Right player scores
   {
      rightPlayerPoints++;
      ballY = fieldWidth / 2;
      ballX = fieldLength / 2;
      Console.SetCursorPosition(scoreboardX, scoreboardY);
      Console.WriteLine($"{leftPlayerPoints} | {rightPlayerPoints}");
      if(rightPlayerPoints == 10)
      {
          goto outer;
      }
   }
}

if(ballX == fieldLength - 2)
{
    //Right racket hits the ball and it bounces
   if(ballY >= rightRacketHeight + 1 && ballY <= rightRacketHeight + racketLength) 
   {
       isBallGoingRight = !isBallGoingRight;
   }
   else //Ball goes out of the field; Left player scores
   {
      leftPlayerPoints++;
      ballY = fieldWidth / 2;
      ballX = fieldLength / 2;
      Console.SetCursorPosition(scoreboardX, scoreboardY);
      Console.WriteLine($"{leftPlayerPoints} | {rightPlayerPoints}");
      if(leftPlayerPoints == 10)
      {
          goto outer;
      }
       
   }
}</xmp>
				</code>
			</pre>
		</div>
						</div>
				</div>
				<div class="elementor-element elementor-element-bcddbdc elementor-widget elementor-widget-spacer" data-id="bcddbdc" data-element_type="widget" data-widget_type="spacer.default">
				<div class="elementor-widget-container">
							<div class="elementor-spacer">
			<div class="elementor-spacer-inner"></div>
		</div>
						</div>
				</div>
				<div class="elementor-element elementor-element-097e0c9 elementor-widget elementor-widget-heading" data-id="097e0c9" data-element_type="widget" data-widget_type="heading.default">
				<div class="elementor-widget-container">
					<h2 class="elementor-heading-title elementor-size-xl">Scoreboard Visualization</h2>				</div>
				</div>
				<div class="elementor-element elementor-element-e6e05a0 elementor-widget elementor-widget-text-editor" data-id="e6e05a0" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>To add a scoreboard, you need variables that store its position.</p>								</div>
				</div>
				<div class="elementor-element elementor-element-1265ac8 elementor-widget elementor-widget-code-highlight" data-id="1265ac8" data-element_type="widget" data-widget_type="code-highlight.default">
				<div class="elementor-widget-container">
							<div class="prismjs-default copy-to-clipboard ">
			<pre data-line="" class="highlight-height language-javascript line-numbers">
				<code readonly="true" class="language-javascript">
					<xmp>int scoreboardX = fieldLength / 2 -2;
int scoreboardY = fieldWidth + 1;
</xmp>
				</code>
			</pre>
		</div>
						</div>
				</div>
				<div class="elementor-element elementor-element-6ac099f elementor-widget elementor-widget-text-editor" data-id="6ac099f" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>The scoreboard is printed on the console every time a player increases their score. Let’s say the game ends when one of the players reaches <strong>10 points</strong>. You need to break out of the game loop with the <b>goto</b> command.</p>								</div>
				</div>
				<div class="elementor-element elementor-element-ce1e1d9 elementor-widget elementor-widget-code-highlight" data-id="ce1e1d9" data-element_type="widget" data-widget_type="code-highlight.default">
				<div class="elementor-widget-container">
							<div class="prismjs-default copy-to-clipboard ">
			<pre data-line="" class="highlight-height language-javascript line-numbers">
				<code readonly="true" class="language-javascript">
					<xmp>//Left Player
leftPlayerPoints++;
ballY = fieldWidth / 2;
ballX = fieldLength / 2;
Console.SetCursorPosition(scoreboardX, scoreboardY);
Console.WriteLine("${leftPlayerPoints} | {rightPlayerPoints}")

if(leftPlayerPoints == 10)
{
      goto outer;
}

//Right Player
rightPlayerPoints++;
ballY = fieldWidth / 2;
ballX = fieldLength / 2;
Console.SetCursorPosition(scoreboardX, scoreboardY);
Console.WriteLine("${leftPlayerPoints} | {rightPlayerPoints}")
if(rightPlayerPoints == 10)
{
      goto outer;
}
</xmp>
				</code>
			</pre>
		</div>
						</div>
				</div>
				<div class="elementor-element elementor-element-91f92b4 elementor-widget elementor-widget-text-editor" data-id="91f92b4" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>Outside of the game loop put a <strong>marker</strong>, clear the console and reset the cursor. Check who the winner is and print the appropriate message.</p>								</div>
				</div>
				<div class="elementor-element elementor-element-e3f817b elementor-widget elementor-widget-code-highlight" data-id="e3f817b" data-element_type="widget" data-widget_type="code-highlight.default">
				<div class="elementor-widget-container">
							<div class="prismjs-default copy-to-clipboard ">
			<pre data-line="" class="highlight-height language-javascript line-numbers">
				<code readonly="true" class="language-javascript">
					<xmp>outer:;
        Console.Clear();
        Console.SetCursorPosition(0,0);
        
        if(rightPlayerPoints == 10)
        {
        Console.WriteLine("Right player won!");
        } 
        else 
        {
        Console.WriteLine("Left player won!");
        }</xmp>
				</code>
			</pre>
		</div>
						</div>
				</div>
				<div class="elementor-element elementor-element-b36e965 elementor-widget elementor-widget-text-editor" data-id="b36e965" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>If you’ve followed all the steps your project should be finished and working now. You can always <strong>adjust the values</strong> of the variables. For example, you can make the field bigger or smaller or increase the speed of the ball to make the game more challenging.</p><p>To check out the final code and compare it to yours <strong>click the link below</strong>.</p>								</div>
				</div>
				<div class="elementor-element elementor-element-0c72984 elementor-widget elementor-widget-spacer" data-id="0c72984" data-element_type="widget" data-widget_type="spacer.default">
				<div class="elementor-widget-container">
							<div class="elementor-spacer">
			<div class="elementor-spacer-inner"></div>
		</div>
						</div>
				</div>
				<div class="elementor-element elementor-element-88292b4 elementor-widget elementor-widget-video" data-id="88292b4" data-element_type="widget" data-settings="{&quot;youtube_url&quot;:&quot;https:\/\/youtu.be\/K0hh_4Lp6_A&quot;,&quot;video_type&quot;:&quot;youtube&quot;,&quot;controls&quot;:&quot;yes&quot;}" data-widget_type="video.default">
				<div class="elementor-widget-container">
							<div class="elementor-wrapper elementor-open-inline">
			<div class="elementor-video"></div>		</div>
						</div>
				</div>
				<div class="elementor-element elementor-element-3738a62 elementor-widget elementor-widget-spacer" data-id="3738a62" data-element_type="widget" data-widget_type="spacer.default">
				<div class="elementor-widget-container">
							<div class="elementor-spacer">
			<div class="elementor-spacer-inner"></div>
		</div>
						</div>
				</div>
				<div class="elementor-element elementor-element-edfdd22 elementor-widget elementor-widget-text-editor" data-id="edfdd22" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<h2>Lesson Topics</h2><div><div><div>In this tutorial we cover the following steps:</div></div><ul><li><strong>Creating a Field</strong></li><li><strong>Implementing Player Movement</strong></li><li><strong>Adding a Ball</strong></li><li><strong>Scoreboard Visualization</strong></li></ul></div>								</div>
				</div>
				<div class="elementor-element elementor-element-93d53ef elementor-widget elementor-widget-spacer" data-id="93d53ef" data-element_type="widget" data-widget_type="spacer.default">
				<div class="elementor-widget-container">
							<div class="elementor-spacer">
			<div class="elementor-spacer-inner"></div>
		</div>
						</div>
				</div>
					</div>
		</div>
					</div>
		</section>
				<section class="elementor-section elementor-top-section elementor-element elementor-element-dc263e9 elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="dc263e9" data-element_type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-2f88ff6" data-id="2f88ff6" data-element_type="column">
			<div class="elementor-widget-wrap elementor-element-populated">
						<div class="elementor-element elementor-element-96efd1f elementor-align-center elementor-widget elementor-widget-button" data-id="96efd1f" data-element_type="widget" data-widget_type="button.default">
				<div class="elementor-widget-container">
									<div class="elementor-button-wrapper">
					<a class="elementor-button elementor-button-link elementor-size-lg" href="https://github.com/SoftUni/SoftUni-Project-Tutorials---Pong-Game-C-Sharp/" target="_blank">
						<span class="elementor-button-content-wrapper">
						<span class="elementor-button-icon">
				<svg aria-hidden="true" class="e-font-icon-svg e-fas-laptop-code" viewBox="0 0 640 512" xmlns="http://www.w3.org/2000/svg"><path d="M255.03 261.65c6.25 6.25 16.38 6.25 22.63 0l11.31-11.31c6.25-6.25 6.25-16.38 0-22.63L253.25 192l35.71-35.72c6.25-6.25 6.25-16.38 0-22.63l-11.31-11.31c-6.25-6.25-16.38-6.25-22.63 0l-58.34 58.34c-6.25 6.25-6.25 16.38 0 22.63l58.35 58.34zm96.01-11.3l11.31 11.31c6.25 6.25 16.38 6.25 22.63 0l58.34-58.34c6.25-6.25 6.25-16.38 0-22.63l-58.34-58.34c-6.25-6.25-16.38-6.25-22.63 0l-11.31 11.31c-6.25 6.25-6.25 16.38 0 22.63L386.75 192l-35.71 35.72c-6.25 6.25-6.25 16.38 0 22.63zM624 416H381.54c-.74 19.81-14.71 32-32.74 32H288c-18.69 0-33.02-17.47-32.77-32H16c-8.8 0-16 7.2-16 16v16c0 35.2 28.8 64 64 64h512c35.2 0 64-28.8 64-64v-16c0-8.8-7.2-16-16-16zM576 48c0-26.4-21.6-48-48-48H112C85.6 0 64 21.6 64 48v336h512V48zm-64 272H128V64h384v256z"></path></svg>			</span>
									<span class="elementor-button-text">Download Project</span>
					</span>
					</a>
				</div>
								</div>
				</div>
					</div>
		</div>
					</div>
		</section>
				<section class="elementor-section elementor-top-section elementor-element elementor-element-3cd15ec elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="3cd15ec" data-element_type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-56bfdb0" data-id="56bfdb0" data-element_type="column">
			<div class="elementor-widget-wrap elementor-element-populated">
							</div>
		</div>
					</div>
		</section>
				</div>
		<p>The post <a href="https://softuni.org/project-tutorials/how-to-make-a-pong-game-in-csharp-guide/">How To Make A Pong Game in C#: Step-by-step Guide [Project Tutorials]</a> appeared first on <a href="https://softuni.org">SoftUni Global</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://softuni.org/project-tutorials/how-to-make-a-pong-game-in-csharp-guide/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>How to Make Our Own Flappy Bird in Unity [Project Tutorials]</title>
		<link>https://softuni.org/project-tutorials/how-to-make-our-own-flappy-bird-in-unity/</link>
					<comments>https://softuni.org/project-tutorials/how-to-make-our-own-flappy-bird-in-unity/#respond</comments>
		
		<dc:creator><![CDATA[Aleksandar Peev]]></dc:creator>
		<pubDate>Tue, 08 Feb 2022 04:58:00 +0000</pubDate>
				<category><![CDATA[Step-by-Step Project Tutorials]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[flappy birds]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[software development]]></category>
		<category><![CDATA[step-by-step]]></category>
		<category><![CDATA[unity]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<guid isPermaLink="false">https://softuni.org/?p=11648</guid>

					<description><![CDATA[<p>In this article of the Project Tutorial series, we will create a simple Flappy Bird game, using Unity.</p>
<p>The post <a href="https://softuni.org/project-tutorials/how-to-make-our-own-flappy-bird-in-unity/">How to Make Our Own Flappy Bird in Unity [Project Tutorials]</a> appeared first on <a href="https://softuni.org">SoftUni Global</a>.</p>
]]></description>
										<content:encoded><![CDATA[		<div data-elementor-type="wp-post" data-elementor-id="11648" class="elementor elementor-11648" data-elementor-post-type="post">
						<section class="elementor-section elementor-top-section elementor-element elementor-element-5d5405e elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="5d5405e" data-element_type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-0d32134" data-id="0d32134" data-element_type="column">
			<div class="elementor-widget-wrap elementor-element-populated">
						<div class="elementor-element elementor-element-9216798 elementor-widget elementor-widget-text-editor" data-id="9216798" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p>In this demo, we will create our own Flappy Bird game using <strong>Unity</strong> and <strong>C#</strong>.</p><ul><li>Unity is, essentially, a well-rounded game engine that truly does simplify game development. While there may be better engines to choose from, learning Unity will only help you grow as a game developer.</li></ul><p>For this project, we are using the <strong>2020.3 LTS</strong> <strong>table release</strong>. To create this project you will need to have <strong>Unity</strong> and <strong>Unity Hub</strong> installed. You can <strong>download</strong> them from <a href="https://unity3d.com/get-unity/download">here</a>. To get the completed project, you can download it from the link below. (Link is available after successful registration)</p><ul><li><p>First, we open the <strong>Unity Hub</strong> and <strong>Create</strong> a <strong>2D Project</strong>.<img fetchpriority="high" decoding="async" class=" wp-image-11661 aligncenter" src="https://softuni.org/wp-content/uploads/2022/02/setup-path-300x160.png" alt="setup-path" width="677" height="361" srcset="https://softuni.org/wp-content/uploads/2022/02/setup-path-300x160.png 300w, https://softuni.org/wp-content/uploads/2022/02/setup-path-1024x545.png 1024w, https://softuni.org/wp-content/uploads/2022/02/setup-path-768x409.png 768w, https://softuni.org/wp-content/uploads/2022/02/setup-path-600x319.png 600w, https://softuni.org/wp-content/uploads/2022/02/setup-path.png 1101w" sizes="(max-width: 677px) 100vw, 677px" /></p></li><li><p>We create a <strong>Sprites</strong> folder in the game directory, and we import all the needed images for the game.</p></li><li>After we <strong>import</strong> the needed images, you can see that you have more than one bird. We slice it save it in a new folder called <strong>Animations</strong>.</li><li>We set it on the <strong>scheme</strong>, we can start the application and see if the bird will fall.</li><li>What we need to do next is create a script for our bird. We create a <strong>Bird.cs</strong> file in the Assets/Scripts folder. We <strong>create</strong> <strong>methods</strong> for the Bird to <strong>fly</strong> and <strong>set boundaries</strong> so it cannot fly outside our screen.</li></ul>								</div>
				</div>
				<div class="elementor-element elementor-element-6a49652 elementor-widget elementor-widget-code-highlight" data-id="6a49652" data-element_type="widget" data-widget_type="code-highlight.default">
				<div class="elementor-widget-container">
							<div class="prismjs-default copy-to-clipboard ">
			<pre data-line="" class="highlight-height language-csharp line-numbers">
				<code readonly="true" class="language-csharp">
					<xmp>using System;
using UnityEngine;

public class Bird : MonoBehaviour
{
    [SerializeField] private Rigidbody2D _rigidbody;
    [SerializeField] private float _force;
    [SerializeField] private float _yBound;

    private void Update()
    {
        if (Input.GetMouseButtonDown(0) && _rigidbody.position.y < _yBound)
        {
            Flap();
        }
    }

    private void Flap()
    {
        _rigidbody.velocity = Vector2.zero;
        _rigidbody.AddForce(Vector2.up * _force);
    }
}
</xmp>
				</code>
			</pre>
		</div>
						</div>
				</div>
				<div class="elementor-element elementor-element-411639f elementor-widget elementor-widget-text-editor" data-id="411639f" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<ul><li>Now we need to <strong>create</strong> pipes. We create <strong>Upper</strong> and <strong>Lower </strong>pipes. If the bird hits them the game will be over.</li><li>After we are done we create a <strong>MovingObject</strong> <strong>infinity</strong> <strong>runner</strong>. We need to <strong>constantly</strong> move the objects to the left. The speed <strong>increased</strong> by one, for every second that passes. We <strong>set boundaries</strong> for when the object is <strong>destroyed</strong>. We <strong>attach</strong> the script to the pipe. We can check if our scripts work.</li></ul>								</div>
				</div>
				<div class="elementor-element elementor-element-f4a4827 elementor-widget elementor-widget-code-highlight" data-id="f4a4827" data-element_type="widget" data-widget_type="code-highlight.default">
				<div class="elementor-widget-container">
							<div class="prismjs-default copy-to-clipboard ">
			<pre data-line="" class="highlight-height language-csharp line-numbers">
				<code readonly="true" class="language-csharp">
					<xmp>using UnityEngine;

public class MovingObject : MonoBehaviour
{
    [SerializeField] private float _speed;
    [SerializeField] private float _xBound;

    private void Update()
    {
        this.transform.position -= Vector3.right * _speed * Time.deltaTime;

        if (this.transform.position.x < _xBound)
        {
            Destroy(this.gameObject);
        }
    }
}</xmp>
				</code>
			</pre>
		</div>
						</div>
				</div>
				<div class="elementor-element elementor-element-b3697b2 elementor-widget elementor-widget-text-editor" data-id="b3697b2" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<ul><li>We can move to the <strong>spawner </strong>script. We create the <strong>class</strong> in the same scripts folder. We need a <strong>prefab</strong> to be <strong>spawned, </strong>and a time interval arrange by <strong>1 axis</strong> with a name &#8211; _yClamp. If enough time has <strong>elapsed</strong>, the object will <strong>spawn</strong>, and the <strong>elapsed</strong> time will <strong>reset</strong>.</li></ul>								</div>
				</div>
				<div class="elementor-element elementor-element-4b97940 elementor-widget elementor-widget-code-highlight" data-id="4b97940" data-element_type="widget" data-widget_type="code-highlight.default">
				<div class="elementor-widget-container">
							<div class="prismjs-default copy-to-clipboard ">
			<pre data-line="" class="highlight-height language-csharp line-numbers">
				<code readonly="true" class="language-csharp">
					<xmp>using System;
using UnityEngine;

public class Spawner : MonoBehaviour
{
    [SerializeField] private GameObject _prefab;
    [SerializeField] private float _time;
    [SerializeField] private float _yClamp;

    private float _elapsedTime;

    private void Update()
    {
        _elapsedTime += Time.deltaTime;

        if (_elapsedTime > _time)
        {
            SpawnObject();

            _elapsedTime = 0f;
        }
    }

    private void SpawnObject()
    {
        float offsetY = UnityEngine.Random.Range(-_yClamp, _yClamp);

        Vector2 pos = new Vector2(this.transform.position.x, this.transform.position.y + offsetY);

        Instantiate(_prefab, pos, Quaternion.identity, this.transform);
    }
}
</xmp>
				</code>
			</pre>
		</div>
						</div>
				</div>
				<div class="elementor-element elementor-element-138d7ce elementor-widget elementor-widget-text-editor" data-id="138d7ce" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<ul><li>After we are done we can put the <strong>spawner</strong> into action.  We create a <strong>spawner</strong> to spawn pipes, evey 2 seconds in the <strong>y-axis</strong>.</li><li>We add the functionality to the <strong>ground</strong> as well. If we hit play we can see the pipes and ground <strong>spawning infinitely</strong>.</li><li>In our next step, we need to make the game <strong>end</strong>. We add <strong>events</strong> to the Bird inside the Bird.cs class. As a <strong>bonus</strong> you can add sounds for different events. With <strong>OnCollisionEnter2D</strong>, our bird dies and we <strong>freeze</strong> the time.</li></ul>								</div>
				</div>
				<div class="elementor-element elementor-element-ecc7ef9 elementor-widget elementor-widget-code-highlight" data-id="ecc7ef9" data-element_type="widget" data-widget_type="code-highlight.default">
				<div class="elementor-widget-container">
							<div class="prismjs-default copy-to-clipboard ">
			<pre data-line="" class="highlight-height language-csharp line-numbers">
				<code readonly="true" class="language-csharp">
					<xmp>    [SerializeField] private AudioSource _audioSource;
    [SerializeField] private AudioClip _flapSound;
    [SerializeField] private AudioClip _hitSound;
    [SerializeField] private AudioClip _scoreSound;
    public static event Action OnDeath;

    private void OnCollisionEnter2D()
    {
        OnDeath?.Invoke();

        _audioSource.PlayOneShot(_hitSound);

        Time.timeScale = 0f;
    }
    
    private void Start()
    {
        Time.timeScale = 1f;
    }
</xmp>
				</code>
			</pre>
		</div>
						</div>
				</div>
				<div class="elementor-element elementor-element-550d174 elementor-widget elementor-widget-text-editor" data-id="550d174" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<ul><li><p>We need to <strong>create</strong> a button,  which starts our game.</p></li><li>We use the <strong>Observer</strong> <strong>Design</strong> <strong>Pattern</strong> and it&#8217;s commonly used in <strong>game development</strong>.</li><li><p>We create a new class called <strong>UIManager</strong>. In our class we add the following play button <strong>logic</strong>:</p></li></ul>								</div>
				</div>
				<div class="elementor-element elementor-element-7dbb766 elementor-widget elementor-widget-code-highlight" data-id="7dbb766" data-element_type="widget" data-widget_type="code-highlight.default">
				<div class="elementor-widget-container">
							<div class="prismjs-default copy-to-clipboard ">
			<pre data-line="" class="highlight-height language-csharp line-numbers">
				<code readonly="true" class="language-csharp">
					<xmp>    [SerializeField] private GameObject _playButton;
    [SerializeField] private TMP_Text _score;

    private void Awake()
    {
        Bird.OnDeath += OnGameOver;
    }
    
    
    private void OnDestroy()
    {
        Bird.OnDeath -= OnGameOver;
    }

    public void RestartGame() => SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);

    private void OnGameOver() => _playButton.SetActive(true);

</xmp>
				</code>
			</pre>
		</div>
						</div>
				</div>
				<div class="elementor-element elementor-element-b7f5a46 elementor-widget elementor-widget-text-editor" data-id="b7f5a46" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<ul><li><span data-preserver-spaces="true">What we need to do is create a <strong>text mesh</strong> for the score on our screen. In the Bird <strong>class</strong>, we add <strong>functionality</strong> so that the score will change. The <strong>OnTrigger</strong> event will <strong>trigger</strong> and <strong>play a sound</strong>.</span></li></ul>								</div>
				</div>
				<div class="elementor-element elementor-element-ee2595f elementor-widget elementor-widget-code-highlight" data-id="ee2595f" data-element_type="widget" data-widget_type="code-highlight.default">
				<div class="elementor-widget-container">
							<div class="prismjs-default copy-to-clipboard ">
			<pre data-line="" class="highlight-height language-csharp line-numbers">
				<code readonly="true" class="language-csharp">
					<xmp>public static event Action OnScore;

    private void OnTriggerEnter2D()
    {
        OnScore?.Invoke();

        _audioSource.PlayOneShot(_scoreSound);
    }</xmp>
				</code>
			</pre>
		</div>
						</div>
				</div>
				<div class="elementor-element elementor-element-473d62c elementor-widget elementor-widget-text-editor" data-id="473d62c" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<ul><li><span data-preserver-spaces="true">In the <strong>UI Manager</strong> we also need to add the <strong>functionality</strong> for the score. Each time the bird <strong>passes</strong> a pipe <strong>depending</strong> on the state we will get <strong>Awake()</strong> or <strong>OnDestroy()</strong> event. We <strong>increment</strong> the current number of the score when the score <strong>increases</strong>.</span></li></ul>								</div>
				</div>
				<div class="elementor-element elementor-element-886c880 elementor-widget elementor-widget-code-highlight" data-id="886c880" data-element_type="widget" data-widget_type="code-highlight.default">
				<div class="elementor-widget-container">
							<div class="prismjs-default copy-to-clipboard ">
			<pre data-line="" class="highlight-height language-csharp line-numbers">
				<code readonly="true" class="language-csharp">
					<xmp>private void Awake()
{
    Bird.OnDeath += OnGameOver;
    Bird.OnScore += OnScore;
}
    
private void OnDestroy()
{
    Bird.OnDeath -= OnGameOver;
    Bird.OnScore -= OnScore;
}
private void OnScore() => _score.text = (int.Parse(_score.text) + 1).ToString();</xmp>
				</code>
			</pre>
		</div>
						</div>
				</div>
				<div class="elementor-element elementor-element-b36e965 elementor-widget elementor-widget-text-editor" data-id="b36e965" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<p><span data-preserver-spaces="true"><img decoding="async" class="aligncenter" src="https://softuni.org/wp-content/uploads/2022/02/final-look-177x300.png" alt="final-look-app" width="184" height="311" /></span></p><p><span data-preserver-spaces="true">If we followed all the steps as shown in the <strong>video tutorial</strong>, our project should be working. What you learned in this tutorial will work for most of your projects in any <strong>engine</strong>. <strong>Unity</strong>&#8216;s pipeline is smooth, yet complex. <strong>Unity</strong> is, simply put, the world’s most popular <strong>game engine</strong>. It packs a lot of features together and is flexible enough to make almost any game you can imagine. <strong>Unity</strong> packs tools for <strong>2D</strong> and <strong>3D</strong> game development.</span></p>								</div>
				</div>
				<div class="elementor-element elementor-element-88292b4 elementor-widget elementor-widget-video" data-id="88292b4" data-element_type="widget" data-settings="{&quot;youtube_url&quot;:&quot;https:\/\/youtu.be\/HQVUGyto8Gg&quot;,&quot;video_type&quot;:&quot;youtube&quot;,&quot;controls&quot;:&quot;yes&quot;}" data-widget_type="video.default">
				<div class="elementor-widget-container">
							<div class="elementor-wrapper elementor-open-inline">
			<div class="elementor-video"></div>		</div>
						</div>
				</div>
				<div class="elementor-element elementor-element-edfdd22 elementor-widget elementor-widget-text-editor" data-id="edfdd22" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
									<h2>Lesson Topics</h2><div><div><div>In this tutorial we cover the following steps:</div></div><ul><li><b style="font-style: inherit; color: var( --e-global-color-text );">Project Creation</b></li><li style="font-size: 15px;"><strong>Project Setup</strong></li><li style="font-size: 15px;"><strong>Creating a Bird</strong></li><li><strong>Adding the Bird Script </strong></li><li><strong>Prefabs</strong></li><li><strong>Adding Moving Object</strong></li><li><strong>Defining Spawner</strong></li><li><strong>Setup Spawners Usage</strong></li><li><strong>Implementing Game Over Feature</strong></li><li><strong>Adding Score</strong></li><li><strong>Adding SFX</strong></li><li><strong>Testing Project</strong></li></ul></div>								</div>
				</div>
					</div>
		</div>
					</div>
		</section>
				<section class="elementor-section elementor-top-section elementor-element elementor-element-dc263e9 elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="dc263e9" data-element_type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-2f88ff6" data-id="2f88ff6" data-element_type="column">
			<div class="elementor-widget-wrap elementor-element-populated">
						<div class="elementor-element elementor-element-96efd1f elementor-align-center elementor-widget elementor-widget-button" data-id="96efd1f" data-element_type="widget" data-widget_type="button.default">
				<div class="elementor-widget-container">
									<div class="elementor-button-wrapper">
					<a class="elementor-button elementor-button-link elementor-size-lg" href="https://github.com/origami99/Flappy-Bird-Demo" target="_blank">
						<span class="elementor-button-content-wrapper">
						<span class="elementor-button-icon">
				<svg aria-hidden="true" class="e-font-icon-svg e-fas-laptop-code" viewBox="0 0 640 512" xmlns="http://www.w3.org/2000/svg"><path d="M255.03 261.65c6.25 6.25 16.38 6.25 22.63 0l11.31-11.31c6.25-6.25 6.25-16.38 0-22.63L253.25 192l35.71-35.72c6.25-6.25 6.25-16.38 0-22.63l-11.31-11.31c-6.25-6.25-16.38-6.25-22.63 0l-58.34 58.34c-6.25 6.25-6.25 16.38 0 22.63l58.35 58.34zm96.01-11.3l11.31 11.31c6.25 6.25 16.38 6.25 22.63 0l58.34-58.34c6.25-6.25 6.25-16.38 0-22.63l-58.34-58.34c-6.25-6.25-16.38-6.25-22.63 0l-11.31 11.31c-6.25 6.25-6.25 16.38 0 22.63L386.75 192l-35.71 35.72c-6.25 6.25-6.25 16.38 0 22.63zM624 416H381.54c-.74 19.81-14.71 32-32.74 32H288c-18.69 0-33.02-17.47-32.77-32H16c-8.8 0-16 7.2-16 16v16c0 35.2 28.8 64 64 64h512c35.2 0 64-28.8 64-64v-16c0-8.8-7.2-16-16-16zM576 48c0-26.4-21.6-48-48-48H112C85.6 0 64 21.6 64 48v336h512V48zm-64 272H128V64h384v256z"></path></svg>			</span>
									<span class="elementor-button-text">Download Project</span>
					</span>
					</a>
				</div>
								</div>
				</div>
					</div>
		</div>
					</div>
		</section>
				<section class="elementor-section elementor-top-section elementor-element elementor-element-3cd15ec elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="3cd15ec" data-element_type="section">
						<div class="elementor-container elementor-column-gap-default">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-56bfdb0" data-id="56bfdb0" data-element_type="column">
			<div class="elementor-widget-wrap elementor-element-populated">
							</div>
		</div>
					</div>
		</section>
				</div>
		<p>The post <a href="https://softuni.org/project-tutorials/how-to-make-our-own-flappy-bird-in-unity/">How to Make Our Own Flappy Bird in Unity [Project Tutorials]</a> appeared first on <a href="https://softuni.org">SoftUni Global</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://softuni.org/project-tutorials/how-to-make-our-own-flappy-bird-in-unity/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 
Lazy Loading (feed)

Served from: softuni.org @ 2026-06-06 06:43:42 by W3 Total Cache
-->