Create a Game with Arduino and Processing | Achraf Mad | Skillshare
Search

Playback Speed


1.0x


  • 0.5x
  • 0.75x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 1.75x
  • 2x

Create a Game with Arduino and Processing

teacher avatar Achraf Mad, Creative Engineer

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

    • 1.

      1 Introduction with Marketing

      3:22

    • 2.

      2 Hardware and Software Requirements

      1:39

    • 3.

      5 Circuit Design and Connection

      7:29

    • 4.

      6 Arduino Coding

      10:37

    • 5.

      7 Processing Coding Initializing Variables

      11:48

    • 6.

      8 Processing Coding Read Incoming Data

      8:51

    • 7.

      9 Processing Coding Play Function

      13:26

    • 8.

      10 Processing Coding Finsihing the Code

      10:26

    • 9.

      11 Testing Arduino

      2:41

    • 10.

      12 Practical Testing the GamePlay

      2:13

    • 11.

      Download and Install Processing Software

      1:39

  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.

100

Students

--

Project

About This Class

Create a Game with Arduino and Processing

Creating a Game might be Complex! but in this course we'll make it Easy, Simple and Fun, Mix Arduino Hardware with Games

What you'll learn

  • Designing a Game from Scratch using Processing with a score system, objects that move and hardware interaction with components inside the game
  • Mixing Arduino Powerful hardware with Processing Powerful Software
  • Control your main Game Character using an Arduino hardware Sensor Reading
  • Add a scoring system and how to change your main character with different shapes
  • Designing your own game and mix it with your Arduino board
  • Create a link between a Game that you will design and code and an Arduino Hardware
  • Hardware and Software Requirements
  • Working Principle in brief
  • Ultrasonic Sensor Working Principle
  • Circuit Design and Connection
  • Arduino Coding
  • Processing Coding
  • Pictures and Scoring System

Requirements

  • Basic experience in Electronics
  • Basic experience in Programming
  • A Will to apply, not just watch

Description

In this course, we will teach you how you can easily create a link between a Game that you will design and code and an Arduino Hardware.

This is the new Arduino project-based course from the Educational Engineering Team.

We all have once in our lifetime played A Flappy bird Game or any other game, but what about designing your own game and mix it with your Arduino board, the board that you already know and most likely have to produce an interactive Game that combined hardware gameplay with software processing to learn while having fun playing!

If you follow the instruction explained in this course in the end you will get a chance to play this game using your Arduino board and you will have fun by practicing with the Arduino hardware to control a game on your PC.

We are using an ultrasonic sensor to control a plane or any item inside our game, you can control a plane, you can control a bird and make it jump inside your game, and this is just the beginning.

At the end of this course, we will also cover how to add a scoring system and how to change your main character with different shapes.

The goal of the game is simple, Use the Arduino hardware and the circuit design that we are going to provide to control your game without touching your keyboard or mouse.

I'm sure that you will have fun while learning in this course.

What you will learn in this course:

  • Hardware and software requirements.

  • What are the things that you need regarding the hardware and what are the software that we are going to use, how to download and install each of them?

  • Working principle of this course and brief.

  • Ultrasonic sensors working principle.

  • Design and connect our simple circuits and start the Arduino coding process.

  • Processing coding and in the end, we will cover pictures and scoring systems inside games and how you can easily implement them again.

  • You will get to learn Arduino and processing and practice hardware and action while having fun and playing games.

A lot of information is waiting for you inside this course, join now and start making your own.

Who this course is for:

  • Electronics Geeks
  • Arduino Geeks
  • Anyone interested in making amazing electronics Projects
  • Anyone interested in making amazing Microcontroller Projects

Meet Your Teacher

Teacher Profile Image

Achraf Mad

Creative Engineer

Teacher

Hello, I'm Achraf.

A passionate engineer who loves to share his knowledge with the world

See full profile

Level: All Levels

Class Ratings

Expectations Met?
    Exceeded!
  • 0%
  • Yes
  • 0%
  • Somewhat
  • 0%
  • Not really
  • 0%

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.

Transcripts

1. 1 Introduction with Marketing: Hello and welcome to this new course in which I'm going to teach you how to create a game with Arduino and processing software. This is Azure from educational engineering team. In this course, we will see how you can easily create a link between a processing sketch and an Arduino code. This is the new Arduino project-based course from educational engineering team. We all have once in our lifetime, played Flappy Bird game or any other game. But health we played on our PC and control it using our Arduino board, the board that we already have. If you follow the instructions in this course and then do this course, you will get a chance to play this game using your Arduino board. And you will have fun by practicing with the Arduino hardware to control again on your PC. Now, in this course, we are using an ultrasonic sensor. Control a plane or any item inside our game. You can control a plane, you can't control a belt and make it jump inside your game. And this is just the beginning and the end of this course. We will also cover how to add scoring system and how to change your main character with different shapes. The goal of the game is symbol. Use the hardware or the Arduino hardware and circuit design that we are going to provide to control your game without touching the keyboard or the mouse. I'm sure that you will have fun while learning in this course. So let's cover what you will learn in this course exactly. At the beginning, we will cover the hardware and software requirements. What are the things that you need regarding the hardware and the software that we are going to use, how to download and install each of them. Then we'll talk about the working principle of this course. In brief. After that, we will talk about the ultrasonic sensor working principle. Then we will design and connect Our symbol circuits and start the Arduino coding process. Once we are done with the Arduino code, we will move on to the processing coding. And at the end, we will cover pictures and scoring systems inside games and how you can easily implement them. Again, this is an informative learning experience. You will get to learn Arduino and processing and practice how it works connection while having fun and playing games. Thanks for watching this introduction. See you inside. 2. 2 Hardware and Software Requirements: Hello and welcome to this new lesson in which we are going to discuss the hardware and software requirements. Now, regarding the software requirements, we will need the Arduino software, which we are going to use to write our C code for the Arduino board, and we will upload our code to Arduino. The next software is that processing software in which we are going to design and called our game. Processing software has a lot of potential. And you are going to explain everything about the software in this course. We will also need a circuit design and simulation software, and we'll use more than one software. We will use our free online platform for the simulation and for the circuit design. We will use Tinkercad software. All of the software are explained and the process of downloading and installing each of them as explained in details in this course. Now regarding the hardware requirements, we will need an Arduino board and ultrasonic sensor. You can easily get an ultrasonic sensor online for less than $5 and an Arduino board for less than $10. If you are facing problem purchasing them, you can't robust a message and we can help you with that. So these are the hardware and software requirements for this course. So let's dig in. 3. 5 Circuit Design and Connection: Hello and welcome to this new lesson in which we are going to design our circuit. Now the first thing is go and open up the franchising software, which is a circuit design software that we are going to use to connect our components. Now go to the breadboard bones. And from there, you can simply zoom out using the mouse Chrome. Go to the Arduino section here. Drag on Arduino. Then look for ultrasonic. And usually you won't easily find an ultrasonic sensor. And this software. Now, usually you won't have ultrasonic sensor on this software. So what you need to do in this case is the following. We need to go to the Google and write ultra sonic sensor. Arduino. Then write fly. As you can see, ultrasonic sensor uprising library and go with the first result. Okay, let's see the data. As you can see once you click viewer all, you will get a chance to download the ultrasonic sensor. You need to save it somewhere inside your device. And once you save it, you can drag it and it's robots here. Now, as you can see, this is the ultrasonic sensor module that we have downloaded. And this is not the module that we want, so we need to go back and make sure that we are downloading the Fc ESR 045 zinc module. And this is it. Now, click the alphas ID, peas, addFive, and click Save and do the same thing, drag it and robots here. And now we have our ultrasonic sensor. This is how the other module to financing. Now, what we need to do first is to connect the US are 0 force sensor to the Arduino board. Now, we can't skip using the breadboard since there is only four wires here. Now we have VCC and ground. Now, we already know that the VCC must be connected to the VCC or five volts and the ground must be connected with the ground. Okay, Let's zoom in right here. Now change the coloring that ground two-block. And the VCC tore it. Okay, that's it. Now, red and black. Now, as there is just one, since there is no need for any additional connections, we just need to connect these pens. Now we can connect that regard been this one to digital pin number 11 right here. And we can also connect the ICO pin right here. This is just, I'll pin number 10, right here. You can change the bin number. We can connect them to Prince number 89. But make sure that you memorize the bins. Now let's change the coloring for the students. As you can see, a very simple circuit. Now, what we need to do is buy the Arduino code for this circuit. If you like. Most people like simulation, you can always go and open up that Tinkercad simulation environment for Arduino. Sign in or sign up using your Google account. Or you can create an account. Now once you sign in, you will get a chance to go to the circuits section and create new circuit. Now, you can choose Arduino and drag, and you'll have these spots here. As you can see, this is an Arduino ball and W Bush. And then you can go back here, look for ultrasonic. And thus you can see we have two sensors, the three bin and for prints and so we need the four pins. And so now we can easily connect Vcc over VCC. If I ground with the ground, just like in our previous design. If you want to change the coloring, you can read. Now that regard pen is connected to pin number 8. The Jacobian is connected to the number nine. Let's make sure that we have the same. Here's three gosh, okay, triggers to build a, it's less smooth this. And let's move this one to the number nine. And the E equals connected to pin number eight. Now you can arrange these pens and you can change the color. So let's choose yellow and green. Okay, very good. Now this will be our simulation environment for the Arduino coding. And we are going to try it on Arduino code in the next lecture is to control the ultrasonic sensor and get readings from this sensor. That splits all this lesson. This is how you can easily design on connect your circuit. We just need an Arduino ball and an ultrasonic sensor. The power source will be the USB cable from our laptop or computer. If you have any question, please ask in the Q&A board. Thanks. Flushing. This is. 4. 6 Arduino Coding: Hello and welcome to this new lesson in which we are going to code our Arduino board. Now the first step is going to the Arduino IDE software. Let's create a new sketch and let's zoom in. Now. The first thing will be declaring that trigger and equal bins. So we will use constant, integer and let's name it triggers print. And another integer for the equal. Now, if we went back to our design, we can see that that regard is connected to pin number nine. And that equals connected to pin number eight. Now, let's add another variable. Okay, Now, let's go to the setup before adding more variables. And said these two pins as input and out, soul used pinMode function, which is a function that you must be very familiar with to set each of these two pins as input, inputs and outputs. So go here, right, triggers pen and output. So that regard pen will be the output pin. And the second bend, which is the equal pen, will be. Then. Now we need to start the serial communication satellite, serial.begin and choose the baud rate, 9,600. Now, this is everything you need to do in the setup methods. Let's move on to the loop method. Now inside the loop. First we need to declare two variables for that duration and the centimeter, which are things that we will read and we will use in our calculations for the sensor reading. So like long duration and centimeter. Now, the first step to use the ultrasonic sensor is to make the trigger pin law. So we need to use that satellite function and by pen and send another signal. So this is the first step. After that, we need to wait for a few milliseconds. So either delay in microseconds and make this delay, let's say three microseconds. Then we need to set the trigger pin too high. So we write the very same sentence, which is digitalWrite. To regard pin and we will send a high signal. Now what we have done here is symbol. We have sent Apollos alone and high pulse for the sensors to make sure that tool start reading until SART, the scanning process. Now after this, we need to wait for a few microseconds until the trigger pulse is sent. Again. This is the band Sloan thigh. So we would like Dewey microseconds. And let's wait for six microseconds. Now, we need to make that triggered pin law again. So what I've done five and sind low to the three gulp pin. Now we need to make equal been high and store the bounds pulse invariable duration. And to do that, we can simply live the following line, right? Duration and send a pulse in. They'll write equal Ben. Hi. So what we have done here is making the Ethiopian high and then storing that bounced balls inside this variable, which is the iteration variable. Now, to convert this duration, the reading that we did take from the sensor into centimeters, we need to do the following. Lights. Centimeters, which are the variable that we already defined. Michael seconds to 70 meters. And it will take the ration has been both. Now. This function will return, convert that into centimeters. And to make sure that we have the readings in inch as well, you can use long inch equals centimeters divided by 2.54. Now, we can print the results here. I'll do rent on the serial monitor and centimeters all an inch. Now, what is this, this method, this is basically a method that we will define that will take the microseconds for the duration as input and will return the centimeters or that the Russian in centimeters. So it's basically a conversion method. So here we can't call it long too. Cm micro to see, it's a shorter name for this method. So till ten microseconds to centimeters. And it will take as input like two seconds. Now, this method will return the microseconds divided by 29 and divide by two. Now this two is because the pulse travels from the sensor and again comes back. So we divided this microseconds variable by two to take only half of the total distance. We don't want to take the full distance because it will be the distance multiplied by two. So to make sure that we have the right distance, you must divide the microseconds by two. So this will return microseconds divided by 29, divided by two. And we will solve the result. And the CRM variable, which will give us the distance in centimeters. Now some people like to edit such codes. Okay, let's, let me save this code before I think this version of the code. Now, some people like to take the end result and they skip the whole thing. And instead of doing these calculations, they're just divide the pulse time or duration here and by 58 and store the result in distance like that. Distance will equal duration divided by 58. And it really depends on your project and what's your end goal is. But for us, what we need is that isn't in centimeters and you are printing this result. The serial monitor, just to make sure that we have the right reading. Now let's verify our code to ensure that we don't have any errors. Here. We have adoration. There is an erosion and the equal pen. Oh, this is a spelling error. K return microseconds. Now done combining, we don't have any elements. We just held our missing us here and I missing oh, here. So that's it. This is our code. And we can edit this code in the practical implementation section of this course. But this is the final version four. Now, once we write our processing code, we need to make sure that Arduino code and crossing code are aligned and cannot work together. And this will be tested in the final section of this course. But that's it for now. Thanks, flushing, this is Ashraf. 5. 7 Processing Coding Initializing Variables: Hello and welcome to this new lesson in which we are going to start using processing software and writing or cold, which is basically the game design process. Now, double-click the processing software. Now, as you can see, this is the window. Let's save our sketch inside the folder unless name it crossing. Now, barely. Hold. Okay, Now this is our window, and as you can see here, we have lines and these numbers refer to each of the lines. For debugging. We'll start by importing the Serial library by simply writing import processing Serial Node star. Now, once you have an error, you can't directly see that we will receive a message here. It's telling us that we have double stars. We only need one. Now. To increase the font size, go to the file, then preferences. And from there it is font size. Let's make it 36. And the console font size 24. Now it's more readable. Import processing the serial looks thought. Now we need to create a few variables. First, we need to create an object from the Serial library unless call it my tree. Let's go with my port. Now. Let's create a string variable to receive the incoming data. Okay, now we are receiving a warning here, and the value of the local variable is not used. It means that we have initialized the variable, but we haven't yet tissues. So this is not unusual. We can ignore it. Now, let's move on. We need to create an integer for the distance. And we need to create another integer for the incoming distance. That's it. These are the four variables that we need. Now, we need to set, since we are making this game like a flat earth game, we need to set the height and width location. So to do that, we'll tie and width. We need to create a float. And let's call it the y coordinates. And let's make it equal 45 and our float, and let's call it x coordinates. Let's make it equal 55. Now, let's add another variable for that gravity. And let's make it five times. We can adjust it. After that. Now, we need to create our variable that will represent the speed of pipes inside our game. So let's add in speeds. And to know exactly what are the pipes that I'm talking about. Let's open up the pen so that I can draw how the game will look on our sketch. Now, as you can see, these are called pipes. And usually you have more than one. And they have, they can have different coloring, different length, different width. And what you need to know about these pipes is that they will be the obstacles that our, There's all, let's say this circle. We'll try to avoid. So it will keep moving up and down between these pipes. And these Pi's will move in a specific speed. That's why we have created a variable and cold. It's Pete. Now, in order to clear these pipes, we need to create a specific class for them. And let's say that we want to create a class that's called pipe. Now, to do that, what you need to do is simple. You need to go back to our code. And the old class, then pipe and to curly parenthesis. Now we are creating a new class inside our processing software sketch. First, create a variable and call it top. And create another variable and call it bottom. Now the top will be, all will get its values from a random function. And the bottom will get its values from a random function as well. Now, each of these two functions will take the height variable and divide it by 3210 or a 100 to the horizontals. The same thing for the bottom, all the bathroom pipes. So here we have said the first variable for these pipes, the top and bottom. Now let's create two more floors, x for the width, plus a 150, and then under a float, and let's call it W. And let's give it an initial value of 75. Now, to color the pipes, we need to use the color function. So color by color will equal the color function. And you can choose the color. Here we are choosing to a 100 or 1000. These are R, G, B, G is basically green. If you need all the pipes, we read you Carl I 255 0, 0. Now, after doing this, we need to create a function. And let's call this function. So avoid by all of this is written inside the class pipe. And pipes are an essential part of our gain. So we need to concentrate when we are coding these pipes. Now the first thing that we need to do is to fill these pipes with the color that we have created here. And we need to draw a rectangle or pipes whole. Take a rectangular shape. And this rectangle rule, take x 0, then w, and top. Now, as you can see, the x 0, W on top are the rectangle, four points or four main focal points. And this is basically align that will draw a rectangle. Now, we need to draw another rectangle. It will take X height, but on this and W and bottom. Now, height minus bottom, it means that this will be the high minus the bottom of our variable. And it's basically are we to draw two rectangles and make sure that these rectangles are not throw, not being thrown one above the other. Fillers. I'll stands between them so that we can see more than one rectangle allow our game. Now, we will write an if statement to check the X value. Now if X is below 100, then we need to add points to the score. And we haven't yet said the scoring system, and we are going to do that inside the main loop. But for now, I need you to know that if x is below a 100, you need to add a point to the overall score and make it x equals the width. And the on button needs to be changed. So the button won't be around them. And the bottom will be random as well. And their value will be the height divided by two. And same for the bottom. As you can see, this is our pipe class. Now, the last thing that we need to do in this lesson is to create three objects using this pipe class. And to do that, we can simply write 50, 51 equals new point. Again by 2 equals new pi, pi by 3 equals new point. And as you can see, these are the three types that we will use in our game. That's it for creating the variables and the pulp class, we are going to solve all the issues and proceed coding in the next lesson, if you have any question, please ask in the few on the board. 6. 8 Processing Coding Read Incoming Data: Now that we have created the pipes, we need to set a few more variables before moving on to the setup method. The first one is the game over variable. So if the game is over, we need this variable to turn into Tool. And we need another variable for the scoring system. And let's give it an initial value of 0 and other valuable for the high score. And the initial value value will be 0. We will also need a variable for the points. And we know that each point is one. We need to add the birth color, which will equal collage. And we can skip 255, 0, 255. You can change the color to whatever you want. Now, let's create a void setup and void setup. And usually we have another method that's called void row. And we are going to code both of them. Now let's start with a void setup. Inside the void setup method. The first thing that we need to do is to sit or canvas size. So the size of for our game will be 400 by 700. And the first pipe, x will equal width plus, let's say 60. Second pipe to the x will equal width plus 200, foresee. And the third x will equal the width plus 300, 80. Now, these are basically where the three pipes will be placed. The first, second unfilled PI, and they will count on the width variable. Now that we have created. Now that my port variable, that is a serial port, we need to write my poles or equal new cereal, and we need to set the name. The propensity is for the serial port. So let's say that all Arduino be connected to come for. And we can change that. And we must use the very same baud rate as our Arduino code, 9,600. Now, like my post. The buffer until and give it a value of 10. So it will keep buffering and CLIL it does receive data. Now this is the void setup method. This is everything you need to write in this method. Now, the second method that we are going to use for our game is a serial event method, which is basically a method that will be responsible for reading the incoming data. So like void cereal event. Then this serial event method will take cereal my port as input. After taking serial my port as input, we need to read the incoming data. So light data, which shows these variables, incoming data. So the incoming data, all data in. And the serial event methods will equal the following. It will equal my port reads thing. So it will call the read string method to read them coming string and store it inside the incoming data variable. After that, it will print it on the serial monitor. So print a new line. How's the incoming data to make sure that you are getting something? After that, we can call the incoming distance, which is this variable, will equal to the integer method, which will turn the incoming data from string to integer. So now the three methods we'll trim the space is from the incoming data. And the integer method will convert this string into an integer and store it into the incoming distance variable. Now after doing that, we can print a new line. And in this line we can tell the user that the incoming distance is. Here. We can add plus and send the incoming distance variable to the serial monitor. Now, the last step is to check if the incoming distance is above one and below a 100. In this case, we need to do the following. Save the incoming data or the incoming distance, which is our variable in the distance Ultra all distance method. As you can see this, okay, sorry, not methods are valuable and the distance variable, so go here and store the incoming distance and the distance. Now, we will only save our values if it's in the range of one to a 100 centimeters. And I think other than that, one really won't really be usable for us. Because if you are more than a 100 centimeter away from the sensor, you won't get accurate results when it comes to playing. Again, plus when you are less than one centimeter away from the sensor, you will also, uh, you want, you will not also be able to get any accurate results. Now, in the next lecture, we are going to discuss that draw method. But that's it for this lesson. As you can see, we have initialize the void setup. We have created our canvas and sit three pipes, and we have initialized the serial port. Then we did three. The incoming data converts it to an integer from string to integer, print it out on the serial monitor, then checked if it's a specific range and took the final reading as integers into the distance variable. That's it for this lesson. Thanks for watching. This is asha. 7. 9 Processing Coding Play Function: Hello and welcome to this new lesson in which we are going to start with that drove function. Now, the little function from its name which will be used to draw things inside our Canvas. The first thing that we need to set is the background. And usually we set it to 0. You can't change the number depending on what you want the background to look. Then we need to add the three pipes. Pipe one, pipe, two pi, five pi over three. By now you can add a fourth pipe. So up to you. Now, we need to fill using that build color, which we already defined previously. And we need to create a shape for this belt. So let's choose an ellipse shape. You can choose a circle if you want. And it will take four variables. Build x coordinates and y coordinates. And you can choose 60. Then another 60. Now this line will do is drawing an ellipse, which is an oval shape on the screen. An ellipse with equal width and height is a circle, which is by default. But in our case, we are adding these four parameters. The first one is the x-coordinate, the second one is the y coordinate on that splay. And the third one is the width of the ellipse by default. And this one is the height of the ellipse by default. Now, since we are adding 60 here and 60 here, it will be a circle. If you own this to look like an ellipse, you have to add like 80 here and 16 year. And it will look differently. But let's leave it to 40 and 60. And we will see how it goes when we are coding, when we are testing. Now. The next step is we need to use the play function. And this function must be defined outside that row. So let's create it to void play. Now, we've created a variable and call it game over. So again, or what is false? So if, again as not yet over and that play is initiated, we need to speed our game to two, and we need to choose the pipe speed. So pipe one dot x. Minus equal speed, which is 2 Pi over 2 root x minus equals speed. And type 3 root x minus equals P. Now what this will do is basically move the pipes. So it will move the pipes so that the game will look like it's a bird that is moving. And the bird will be move, will go up and down. The pipes will keep moving at a speed of two each time the play is initiated. Now, after doing this, we need to set the text size for our canvas to be, let's say 20. And use the fill function and fill with the RGB colors, 255, 255, 255. Then the text. And the text will print the score and the width divided by two. Now, what are these? Now, the first thing is the alphanumeric character to the supply, which is the variable, which is the score. The second is the x-coordinate of the text where you want to place the text on your screen. And the third is called an S of the text. Where do you want to place the text on the y coordinate? So fueled Sibley. Now you can add as it called an nth if you want, but this is more than enough. So this will print the score, this location, x and y. And with this size and the color will be 255, 255, 255 for this text. So you will see the score, the score on your Sibley had this location and you can't change this location depending on what you think is best for you. Now, this is if game over is true, but what if game over is false? Now, if game over equals false, okay? Sorry, this is if it is false, this will be if game over is true. In this case, we need to do the following. We need to set the speed to 0. And Pi 1 dot x minus equals speeds, which is 0. So it won't move by T2 that x will be minus equals speed. And Pipe 3 x t minus a equals speed as well. Now this means that the pipes will stop moving because the speed will be 0. Now, if the high score is below that score that we have here. In this case, we need to set the highest call to the new score, which is the score that we have here. Now, after this, we need to set the text size to 16, or let's make it 18. Change the fill color for the fixed 0150, and change the alignment, the alignment for the fixed using the text alignment on the right center. And the next tip will be plotting the text. Now, we will write three texts. Texts, okay? Okay, Now the first list, or the first text. Well, till the user click Play. Again. If you want to play again, the x coordinates for this test would be x, but by 2 divided by 2. Now the second dx dt would be the score, score. And it will be placed at the same width divided by 2. But we will change the height so that the text will come above each other. So divided by two minus 25. The third texts will be high score. High score. And we will dissipate the same x-coordinate. And we will change the y coordinate. Two minus 15. That's it. Now, after doing this, we need to check if the user did click his mouse. So we'll use an if statement. So if values of did press the mouse, we need to do the following. We need to wait for, let's say at 100 millisecond, said the score. To 0 and change them all to false. Because we want to start counting again. So we have to set these two. After doing that, we need to build x coordinates and y coordinates. The x coordinates will be, let's say a 100 and the y contents will be 50. We must do the same for the pipes. So pi x will equal width plus 15. Now copy this line and paste it three times 1, number 2, and 3, 50 to a 100. Now to get the accurate values for this, we need to go back. In our code. We have 6240 sixty two hundred forty, three hundred eighty. Now, change the one to random. I divided by two, height divided by two. And we need to do the same for the other two types. So this is the second type. And this is the third. That's it. Now, if that user placed with his mouth to play again, we will receive the score, elicit the game all of our flag, and place the burden on its original location. Place the pipes on their original location, and start the game again. So let's go back to our draw. Now we have the clear function that we just created. After hitting the play or after playing, we need to create another function for the success. Now, this will be created in the next lesson, but that's it for this lesson. We have said that play function and we have drawn the outline for our game. Thanks for watching this lesson. This is Ashraf. 8. 10 Processing Coding Finsihing the Code: Hello and welcome to the singular stone. And we're going to create the success function and finish up our coding process. Now, we already mentioned that we need a success function. And the main goal form the success function is to check if the bell or the object hit, did hit the pipes or not. Now, if it did hit the pipes, the game and the game will stop. If it didn't, the game won't proceed and we'll keep going. So usually we call the success function after the play inside that row here. And it will take as input, so it will take the first pipe, and it will take the second pipe. And it will also take the field pipe. Now, let's go and program the success function. First, we need to create this function so like void success. Now we already mentioned that it will take an input which is the pipe. So it will be pipe desk. Now, inside the success function, we need to do the following. We need to write an if statement. And this if statement will check, okay? If the y coordinates is below that tests, which is the top or the pair called this is above the height minus this button. Now, if any of these conditions is true, it means that there is a good chance that the bill did hit the pipe. Now, to double-check this. So if this condition is true or if this condition is true, we need to ask using another if statement. Now, inside this if statement, we need to ask about that. Build X called the S. If the x coordinates is above that, this dot x. And The bear x call limits is below that, this x plus this W to W. So now, if these two conditions are true, if the x coordinates is above that this x called the IP. And that build X is below, that is two x plus this width. It means that the bill did hit the area between the bike. Okay, let me explain this drawing. Let's place this right here. And let's bring that wrong. Now. Let's say that this is the result. Now we know that we have an x coordinate. This is the x and a y coordinate, and this is the why. Now we are talking about the x. If the x coordinate. Now these are the x coldness of the verse starts from here and it ends here. Now, if the build x coordinates is above the pipe, x cold air. So let's say that the X coordinates for the pipe starts from here. Now if the parent x-coordinates is above the test or the part that x call this means that let's say that our build is here. And if the x coordinates is below the Pi x plus this all by bit width. So now the second line means that we are sure that this build is above the x coordinates of this and below this area. So it will be trapped in this area. This is not this does not mean that the bill did hit the pipe because this just checks if the build is in the x-coordinates range of the pipe. Now what about the y coordinates? They are checked right here. If the bear y-coordinates is below the top of the pipe. Now this is the top of the pipe. And this is to check if the y-coordinates of the pipe. As you can see, these are the wildcard, this starting from here to here. Now, if the y-coordinates is below the top, it means that there's a good chance that this bear did hit the pipe. Now, we made sure by checking the x coordinates. After that. Now the built y-coordinates, if they are above the high, more or less that is took button. Now this is the height of our canvas. And this is the test look button. And basically the bottom is this area. Now this area minus this area will equal this area. So here we are asking if the bill is in this area. Now, if it is in this area and the y direction, and if it is in this area in the x direction, it means that it did hit the pipe. So these two if statements are basically to check if the parent is all exists between these two and these two in the x and y directions, it means that it did enter the green area here. And in this case, what we need to write is game over equals true. Just that. Now this will tell, or software or our game, that the game is over and show the score to the user, uninstalled the game. Now, when we go back to our man bro function, Let's go back here. We call the success function three times. After doing that, we will write a final if statement. If else. Now, if the incoming distance is above 10, then in that case we need the bill. Y coordinates. Minus equal gravity. We need to change the gravity of the, we need to use the gravity to change the world while coordinates. Now else or otherwise, the bear y coordinates plus equal gravity. Now, these lines means the following. Now, if the incoming distance is above 10, if we are receiving more than 10, we need to change the y coordinates of the Bayer depending on the gravity value. And we can't change the gravity value from this area. We have already defined the gravity here to 5. Now, what this will do, this if statement will do. Let's go back to this. Okay? Well, this if statement will do it will move the bird up and down so that it can avoid hitting the pipes and the game will move on. Now this is a very essential IF statement because without it, the build will stay on its location and it will most likely hit one of the pipes. So to avoid this, we must solve this. And we are only moving the bird and the y direction because as you can see in this game, the beard is here and it's moving up and down. And the y direction. And the pipes are moving. Pipes are moving. So the game will make you feel that the build is moving also in the x direction, while it's only moving in the y direction. So the bell would keep moving up and down. And the y coordinates depending on the gravity value and depending on the incoming distance value from the ultra sonic sensor. So by now, I think that you understand everything regarding this cold. All of the lines were pixel blend in details. So if any of these lines isn't clear for you, I'll be more than happy to explain it again. That's it for this lesson. Thanks for watching. This is Asherah. 9. 11 Testing Arduino: Hello and welcome to this new lesson in which we are going to upload the Arduino called. And before uploading it to the actual albumin ball lifts uploaded to the simulation environment. So select all didn't copy. And go to the simulation environment here. And go to the coding section. Select text and phloem here, remove everything and paste your code. This is opcode for the ultrasonic sensor. Now click Start Simulation. And as you can see here, we have the values on the serial monitor. And these values are related to the ultrasonic sensor here. As you can see, we have the object about a 113 centimeters, and it's showing a 112 centimetres, will choose an accurate result. We have like 76 centimeters here and same here. So our code is working just fine. So as you move this closer, as you can see, now, this mean that our Arduino code is working just fine. So select this algorithm called Copy. And this is the same chords. So we need to go to the Tools after connecting our Arduino board, right-click on the Windows logo and select the Device Manager. And from there, Moore's Law ports. And as you can see, we have Arduino connected at calm for. So I can go to the Tools, make sure that come fall selected. Verify your code's done combining, now upload your code. And this will upload our code to the Arduino bold, as you can see, done uploading. Now, what we are going to do in the next lesson is to check if the Arduino is sending serial data and to try out the processing software. Thanks for watching this lesson. This is. 10. 12 Practical Testing the GamePlay: Hello and welcome to this new lesson. Now, we are going to start this game. As you can see if you went to the serial monitor here, you can see that Arduino is receiving readings from the sensor. And as I move my hand, as you can see in the video, the sensor is giving different readings depending on my hand location. Now, let's close this and go to the processing code. Here is our processing code. And we need to change the board. And since it's all become four. And our code and advise managers, we will leave it like that. Just click the Run button. As you can see, this is the game. And since we haven't moved the highest score, 0, that's called a 0. And when we click, it showed as you can see, you should play again, more of a play again button. And as you can see, as I move my hand, the ball is moving up and down. Okay? That's it. Now, you can adjust the pulse width and length to play the game. And pink it more easy for you or your kids to play it. And you can minimize the size of the ball or the bear. You can't change it with a bird. And as you can see, as you click on that visibly inside your game, you can easily start playing the game again. That's it. This is the demonstration of the project. If you have any question, please ask in the Q&A board. Thanks for watching this. Is Ashraf from. 11. Download and Install Processing Software: Hello and welcome to this new lesson in which we're going to explain how you can easily download and install processing software and go to Google and write processing software and click Download. Now once you are here, you just need to select your operating system. Mac, Linux, or Windows. We have 12 64-bit. Click here. And the download will start. Hey, it shouldn't take long. Now once the nanos is done, click Open File and you will get this window. Now, double-click the processing software, as you can see here we have it. Now, let's extract it to our documents folder so that we can use it. Then click Okay. Now, once it's done, a foreign to our document folder, you will find that we have processing software right here. So double-click, double-click that processing dot EXE file. And as you can see, it will start running the processing software. And this is that we'll commit message. That's it. Thanks for watching this lesson. See you next.