<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Onyedikachi E. Ibeabuchi on Medium]]></title>
        <description><![CDATA[Stories by Onyedikachi E. Ibeabuchi on Medium]]></description>
        <link>https://medium.com/@eonyedikachi?source=rss-1f94c928c22b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*95EQNNr2oQSbYJvG.jpg</url>
            <title>Stories by Onyedikachi E. Ibeabuchi on Medium</title>
            <link>https://medium.com/@eonyedikachi?source=rss-1f94c928c22b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 12:35:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@eonyedikachi/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[My TIIDELab Experience 1.0 (First Month).]]></title>
            <link>https://eonyedikachi.medium.com/my-tiidelab-experience-1-0-first-month-28c5ea299e1d?source=rss-1f94c928c22b------2</link>
            <guid isPermaLink="false">https://medium.com/p/28c5ea299e1d</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[backend-developer]]></category>
            <category><![CDATA[tiidelab]]></category>
            <dc:creator><![CDATA[Onyedikachi E. Ibeabuchi]]></dc:creator>
            <pubDate>Fri, 11 Sep 2020 07:31:59 GMT</pubDate>
            <atom:updated>2021-02-26T09:38:58.208Z</atom:updated>
            <content:encoded><![CDATA[<p>Two days to the month of August, I got an email from <a href="http://tiidelab.com/">TIIDELab</a> stating I got accepted into the cohort 2 Software Development Fellowship, 2020.</p><figure><img alt="TIIDELab Logo — Think, Innovate, Ideate, Develop and Execute" src="https://cdn-images-1.medium.com/max/400/1*XgBZsyWJHDe9PyBHXuFg0w.jpeg" /><figcaption><strong>Think | Innovate | Ideate | Develop | Execute</strong></figcaption></figure><h3>Introduction</h3><p>Now, a brief summary of my journey into the <a href="http://tiidelab.com/">TIIDELab</a> house. I applied for the first cohort with very high hopes of getting in due to my Computer Science background but got my hopes dashed with a rejection. I kept in touch with some acquaintances I met during the interview and followed <a href="http://tiidelab.com/">TIIDELab</a> and a few management staff on Twitter. I followed the training updates of the selected fellows, asked a few about what they were learning/building and was thrilled at how much they were growing.</p><p>When applications for the next cohort was opened, one of the fellows notified me and I applied immediately, this time with a more open mind. I took the required online test, got a score (66.67%) below the pass mark (70%), thought this was the end of the road for me but was shocked when an email from <a href="http://tiidelab.com/">TIIDELab</a> hit my mailbox stating I made it to the next interview phase. During this interview, I was quizzed by experts in tech, business and human capacity building, provided answers to the best of my knowledge and here I am, a <a href="http://tiidelab.com/">TIIDELab</a> fellow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/639/1*BmOslnYkD2sfsn3BBt7I0w.jpeg" /><figcaption>Officially a TIIDELab Fellow</figcaption></figure><h3>What have I learned so far?</h3><p>Over the past month, I have been exposed to critical thinking, problem identification/framing, and clear communication techniques. Every morning (Mondays to Thursdays) fellow are required to take an 8 minutes Criteria Cognitive Aptitude Test (CCAT) of 20 questions, the goal is to be able to provide correct answers to about 50 questions in 5 minutes. So far I have progressed from scoring 35% to 75% and hope to improve as times goes on. Once a week fellows meet for non-technical training. During this period we are given various tasks that involve a real-world problem, in one of this meetings, my team was asked to identify problems and proffer solutions associated with the registration and issuance of Yellow Fever Card in Nigeria, we were able to do so by using the above-mentioned skills. As one of the most important skills that I am developing, critical thinking will be valuable for a developer as he/she is sometimes tasked with creating products that a minor error could result in loss of financial resources and the likes. These three skills act as pillars necessary for me to have a successful career as a developer not forgetting empathy.</p><p>I was shown how data structures and algorithm goes a long way to give meaning to a problem one is trying to solve with any given programming language especially with the introduction to Big O Notation.</p><p>Every fellow is required to learn basic HTML, CSS and JavaScript, irrespective of your track. So far, we have been taught HTML CSS and Git Version Control, with this knowledge, I built my portfolio (still work in progress though as features are been added as learning continues), find the link <a href="https://onyedikachi-portfolio.netlify.app/">here</a>. As someone on the Backend track, I so much love this as this will help me not only write code that works but one that is also efficient and with the proper API documentation. I also get to work with very smart individuals that challenge me, as fellows are from various fields of engineering and social science.</p><h3><strong>Moments and Highlights</strong></h3><p>One of the highlights of my first month was when my team won a challenge that gave us the privilege of making a team member the Head of House (HOH). Ah yes, the HOH is like the representative of all fellows. There is also the position of Deputy Head of House (DHOH) since the program is running simultaneously in both Abuja and Lagos, HOH and DHOH can not be fellows from a single location at a given time.</p><p>As someone that enjoys peer learning, I always look forward to the Friday meetups as this allows me to connect better with instructors and fellows, not forgetting to mention that classes are remote from Monday to Thursday.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*powQ72KFH4NS4M0az69Xzw.jpeg" /><figcaption>TIIDELab Fellow during a Task.</figcaption></figure><h3><strong>Where am I now?</strong></h3><p><a href="http://tiidelab.com/">TIIDELab</a> has made me see software engineering as a process were thinking and planning makes the writing of code much easier as I don’t just jump to writing code when trying to solve a problem without first checking to see how others have tried solving the same problem, using the insight I gained from such research to provide a better way of solving a said problem without reinventing the wheel.</p><p>Currently part of a team that is working on a Project Management Tool for both technical and non-technical users. Update on this project will be in my next article.</p><h3><strong>Conclusion</strong></h3><p>This awesome experience won’t have been possible without the entire management of <a href="http://tiidelab.com/">TIIDELab</a>, <a href="https://itf.gov.ng/">Industrial Training Fund, Nigeria</a> (ITF), <a href="https://neca.org.ng/">Nigeria Employers’ Consultative Association</a> (NECA) and wonderful instructors, not forgetting you reading this, thanks a million.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=28c5ea299e1d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create a Pong Game Using an Android Phone]]></title>
            <link>https://eonyedikachi.medium.com/create-pong-game-using-an-android-phone-b782579ee950?source=rss-1f94c928c22b------2</link>
            <guid isPermaLink="false">https://medium.com/p/b782579ee950</guid>
            <category><![CDATA[processing]]></category>
            <category><![CDATA[code-newbie]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[andriod-game]]></category>
            <dc:creator><![CDATA[Onyedikachi E. Ibeabuchi]]></dc:creator>
            <pubDate>Fri, 02 Aug 2019 23:33:56 GMT</pubDate>
            <atom:updated>2021-02-26T09:26:12.993Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Create a Pong Game Using an Android Device.</strong></h3><p>This article is for those interested in or already familiar with computer programming. In this article, you will learn some basic programming concepts by creating a Pong Game using the <a href="https://processing.org/"><strong><em>Processing Programming Language</em></strong></a> and <a href="https://android.processing.org/gallery/index.html"><strong>Android Processing Development Environment</strong></a> (APDE) on your Android Device.</p><figure><img alt="Pong Game Interface." src="https://cdn-images-1.medium.com/max/640/1*cDb4hucbiE1DUn2lIYSY8Q.png" /><figcaption><strong>Figure 1.0 Pong Game Interface.</strong></figcaption></figure><p>The above is our game interface after completion. The orange rectangles are paddles for two players (one on the left and the other on the right) with their respective scores and a ball that bounces when it hits any paddle or the top/bottom edges of the screen. A player scores a point when the ball passes the other player’s paddle.</p><p><strong>Setup Programming Environment<br></strong>The Android Processing Development Environment (APDE) Processing IDE will be used to create the Pong game. Follow the below steps to setup the programming environment on your device.</p><figure><img alt="Install APDE from Google Play" src="https://cdn-images-1.medium.com/max/360/1*D8IeTxYS5pk_6isDS3FnFQ.png" /><figcaption><strong>Figure 1.1 Install APDE from Google Play.</strong></figcaption></figure><ul><li>Download and install APDE from <a href="https://play.google.com/store/apps/details?id=com.calsignlabs.apde&amp;hl=en">Google PlayStore</a> (if you run into security issues, goto<strong> security</strong> in <strong>settings</strong> and allow installation from <strong>unknown sources</strong>).</li><li>Open the app and press the button to the right of the play button, it might be two angle brackets(&lt;&gt;) or a phone icon.</li><li>Choose “Preview” (the angle brackets -&lt;&gt;).</li><li>Now press the play button.</li><li>Install Sketch viewer if you are prompted to do so.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/1*1_trfILJXIWMgE0oUTiv6A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/358/1*DpdU6S3CWhXpgLGyyQbQ9w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/359/1*mm78dN_1NOqaV9urvWhh7Q.png" /><figcaption><strong>Figure 1.2 Setup APDE Programming Environment.</strong></figcaption></figure><p><strong>Introduction to Processing<br></strong><a href="https://en.wikipedia.org/wiki/Casey_Reas"><strong>Casey Reas</strong></a> and <a href="https://en.wikipedia.org/wiki/Ben_Fry"><strong>Ben Fry</strong></a> are the founders of the language, created to make programming interactive graphics easier. Like human languages, programming languages belong to families of related languages. Processing is an open-source language and a dialect of a programming language called Java; the language syntax is almost identical, but Processing adds custom features related to graphics and interaction. It is also implemented using languages such as JavaScript, Python and HTML5. In Processing, a program (a file with an organized collection of code) is called a <strong>Sketch</strong>. With this, our game can be called a sketch.</p><figure><img alt="Figure 1 — Languages related to processing" src="https://cdn-images-1.medium.com/max/823/1*FeyggNneRueImObsE5X33Q.jpeg" /><figcaption><strong><em>Figure 2. Languages Related to Processing.</em></strong></figcaption></figure><p><strong>Code Structure in Processing<br> </strong>In Processing, codes are organized into two components or functions: <strong>setup()</strong> and <strong>draw()</strong>. <strong>setup()</strong> is meant for code that runs only once like setting display (portrait or landscape) mode of our game while <strong>draw()</strong> houses code that runs continuously like drawing of objects or texts when the game is been executed. Comments can be added with the use of double forward slashes (//) followed by the text.</p><p>Sample code that shows the structure of Processing</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2f48a18c4c1296669728bcaecfb0c1f2/href">https://medium.com/media/2f48a18c4c1296669728bcaecfb0c1f2/href</a></iframe><p>Write/copy the above code in the blank sketch file.</p><p>Comments (text after the double forward slashes) are ignored by Processing during sketch execution. This helps you or someone that might come across your code easily read and understands what it does. They should be descriptive words that reflect what the code does. You will see the importance of comments when trying to fix errors that might be shown when trying to execute a sketch.</p><pre>fullScreen​();</pre><p>The above line of code is called a <strong>statement</strong> and is used to set our game to run in fullscreen (landscape) mode.</p><p><strong>Computer Coordinate System<br></strong>You are probably used to the coordinate system with the origin (0,0 point) at the center, shown on the left. However, in the computer system, the coordinate system is such that the origin is at the top-left with ​<em>x </em>​increasing horizontally to the right, and ​<em>y </em>increasing vertically downward shown on the right just like it shown below.</p><figure><img alt="Figure 2 — Regular Coordinate System(left) and Computer Coordinate System(right)" src="https://cdn-images-1.medium.com/max/1024/1*34n4KSauqjyhnCZ0bjGViw.jpeg" /><figcaption><strong><em>Figure 3.- Regular Coordinate System (left) and Computer Coordinate System (right).</em></strong></figcaption></figure><p>So, if the screen is 200×200 pixels, the upper-left is (0, 0), the center is at (100, 100), and the lower-right is (199, 199). The graph shown on the right represents that of your Android Device when in landscape/fullscreen mode.</p><p>Take note of your screen width and height by going to <strong>settings&gt;&gt;about phone&gt;&gt;hardware info&gt;&gt;screen resolution. </strong>The info should appear like this “720 x 1280”, the larger number is your screen width while the smaller one is your screen height since we will be using the landscape/fullscreen mode. You can actually get the width and height of your device screen by using <strong>system variables</strong> instead of going to settings on your device, this will be covered later in this article.</p><p>Write your screen width and height like its shown below at the top of your code in the sketch for reference purpose. Your device’s screen width and height may be different from what we have below.</p><pre>//screen Width = 1280 screen Height = 720</pre><p><strong>Drawing Basic Shapes in Processing<br></strong>Processing includes a group of functions to draw basic shapes. We can use the following statements to draw shapes such as circle, rectangle and text:</p><p>To draw a rectangle, use the function ​<strong><em>rect()</em></strong>​. Define the top-left point: specified by the values of ​<em>x </em>​and ​<em>y</em>​. Then the width and height of the rectangle: specified by the values of ​<em>width </em>​and ​ <em>height </em>​(Figure 4).</p><figure><img alt="Drawing a Rectangle in Processing." src="https://cdn-images-1.medium.com/max/526/1*yKW_ndUzy0whVrqfpXgg9w.jpeg" /><figcaption><strong><em>Figure 4. Drawing a Rectangle in Processing.</em></strong></figcaption></figure><p>Now, lets draw our game paddles as shown in Figure 1.</p><pre>​rect​(0, 0, 30, 170); ​//draws left paddle</pre><pre>​rect​(1250, 550, 30, 170); ​//draws right paddle</pre><p>The first line places the paddle at the top-left of the screen with width = 30 and height = 170.</p><p><strong>The second line places the other paddle at the bottom-right of the screen with the same width and height but this time the position is x = screen width — 30 (the paddle width) and y = screen height — 170 (paddle height). This makes the paddle not to disappear.</strong></p><p>To draw an ellipse, use the function ​<strong><em>ellipse()</em></strong>​. You need the center point specified by the values of ​<em>x </em>​and ​<em>y (</em>x- and y-coordinates for a rectangle are the top-left corner, but for an ellipse, they are the center of the shape)<em>. </em>​Then you’ll need ​the width and height of the ellipse: specified by the values, ​<em>width </em>​and <em>height</em> (Figure 5).</p><figure><img alt="Drawing an Ellipse in Processing" src="https://cdn-images-1.medium.com/max/674/1*htb2Ta_lWRMbq9BDVcFF_A.jpeg" /><figcaption><strong><em>Figure 5. Drawing an Ellipse in Processing.</em></strong></figcaption></figure><p>To draw our ball which is a circle, we have to make the width and height of the ellipse function equal, as they can both represent the diameter of a circle since Processing has no circle function. We want the ball at the centre of the screen when the game starts so x = screen Width/2 which is 640 and y = screen Height/2 which is 320. Hence the below code for the ball.</p><pre>​ellipse​(640, 320, 30, 30); ​//draws the ball (an ellipse at the //centre with equal width and height = a circle)</pre><p>To write text on the screen, use the function <strong><em>text().</em></strong> The first value is a set of words put in quotes or a number. The next is the <em>x </em>​and <em>y </em>​positions of the text (first value). The x and y positions specify the position of the left-bottom corner of the text (Figure 6).</p><p>We set the size of the text using <strong><em>textSize() </em></strong>​ with the parameter being a number.</p><figure><img alt="Displaying Text in Processing." src="https://cdn-images-1.medium.com/max/644/1*td_HK6PkihBpSzOlytuvGQ.jpeg" /><figcaption><strong><em>Figure 6. Displaying Text in Processing.</em></strong></figcaption></figure><p>We will place both players’ score 190 (this is not a rule but my choice) steps away from the ball on either side and on the same line. What this means is that the value of “y” will be the same but “x” will be 190 times less than ball “x position” for the left player and 190 steps greater than the ball “x position” for the right player’s score.</p><pre>text​(​”0&quot;​, 450, 360); ​//left player’s score<br> text​(​”1&quot;​, 830, 360); ​//right player’s score</pre><p>You will agree with me that our game will look awful without colours. Let’s go on and add colours to make our game look more appealing.</p><p><strong>Colour System in Processing<br></strong>There are two colour models that one can use in processing:<br>1. Grayscale (black and white) model.<br>2. RGB (red green blue) model.</p><p>In the Grayscale model, you specify one number ranging from 0 (black) to 255 (white). As the number increases from 0, the colour gets lighter and lighter, until it’s completely white at 255 (Figure 7).</p><figure><img alt="Grayscale Colour Model" src="https://cdn-images-1.medium.com/max/300/1*75NlHK6yvsl57q9A-3wQ4A.jpeg" /><figcaption><strong><em>Figure 7. Grayscale Colour Model.</em></strong></figcaption></figure><p>In the RGB model, we specify a set of three values, each ranging from 0 (none of that colour) to 255 (full on) for each of the three colours: red, green, and blue. Various colours can be derived by combining these three colours like the picture on the right in Figure 8.</p><figure><img alt="RGB Colour Model" src="https://cdn-images-1.medium.com/max/767/1*dB0Y-fNJK9TgtzGDx-J3Aw.jpeg" /><figcaption><strong><em>Figure 8. RGB Colour Model.</em></strong></figcaption></figure><p>The use of one parameter tells Processing to use the grayscale model, for example, <strong><em>background(255) </em></strong>sets the background to be white. And using three parameters tells Processing to use the RGB model. For example, ​ <strong><em>fill(0,0,255) </em></strong>​ sets our shapes’ colours to be blue.</p><p>The following functions are used to set colour:<br>1. <strong>background() </strong>— used to set the background colour.<br>2. <strong>fill() </strong>— used to set the interior colour of shapes.<br>3. <strong>stroke() </strong>— used to set the outline colour of shapes.</p><p><strong><em>Note: </em></strong>​<em>To set the colour for a shape, first write out your colouring functions </em>​<strong><em>fill() </em></strong><em>or </em>​ <strong><em>stroke() </em></strong><em>before drawing the shape. It’s like dipping a brush in a specific colour before painting. So to assign different colours to different shapes (say shape 1 and shape 2), set the colour for shape 1 first, draw shape 1, and then set the colour for shape2 and draw shape 2. Also, the background colour</em><strong><em> </em></strong>​<em>needs to be set before any drawings.</em></p><p>Do not bother if you don’t understand certain things here now, it gets better as we progress.</p><p>We have not specified any colours for our game background or shapes, they are set to grey and white respectively by default. Add the following code to define background, shapes and shapes outline colours.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/24dccfb6dd20763ffbbda1ac16f096d9/href">https://medium.com/media/24dccfb6dd20763ffbbda1ac16f096d9/href</a></iframe><p>Line 11 sets the colour of the paddles to orange, line 12 sets the paddles’ outline colour to blue and line 16 sets the colour of our ball to white with its outline colour set to white by default since it was not specified.</p><p>Wow! Our game interface is now set, We can now make our ball to move.</p><p><strong>Before we do that let&#39;s take a look at things that might prevent our game from not executing:</strong></p><ul><li><strong>Not putting a semicolon “;” at the end of a statement.</strong></li><li><strong>Not putting corresponding closing braces “}” or brackets “)”.</strong></li></ul><p><strong>To avoid this, it’s best to write the closing braces or brackets right after you write the opening braces so you don’t forget.</strong></p><p><strong>Variables<br></strong>You sure have come across a variable in math with phrases like “find the value of x”. In programming, variables are used to store values like numbers, words (that we call text), etc. We use variables so that we can change our values at a later time in our code. For our game, to make the ball move, we have to continuously change its ​<em>x </em>​and ​<em>y </em>positions as the code is executed.</p><p>There are various data types, that is, values it can hold :</p><ul><li>int - integer with examples such as 1,2,3.</li><li>float - decimal numbers such as 3.142 (pi), 9.8 (gravity).</li><li>boolean - true, false.</li><li>string - text.</li></ul><p>We have different data types because sometimes we may need to use a number that doesn’t have decimal points, like the age of someone for example - you can’t be 19.4 years old! And sometimes you may want to store a combination of letters and numbers so you’ll need a string data type instead.</p><p>Variables in Processing can take two forms viz:<br>1. Built-in or System Variable.<br>2. User-Defined Varaibles.</p><p><strong>Built-in or System Variables<br></strong>These are variables that come with the Processing language. Processing takes charge of creating and modifying the values in them. We will be using system variables like ​<strong><em>mouseX </em></strong>​and ​<strong><em>mouseY </em></strong>to move paddles later<strong><em> </em></strong>​<em>, </em>​which hold the x and y positions of the part of the screen your finger touches<em>.</em></p><figure><img alt="System variables" src="https://cdn-images-1.medium.com/max/541/1*m3Xsfu4-ifMEmZqQs-qnfQ.jpeg" /><figcaption><strong>Figure 9. System Variables.</strong></figcaption></figure><p><strong>User-Defined Variables<br></strong>These are variables created by you the programmer. There are two steps in creating a variable:<br>1. Declaration<br>2. Initialization</p><p><strong>Declaration<br></strong>This is defining the data type and name of a variable. The format for declaring a variable is:<br> datatype ​ name;</p><pre>int age;</pre><p><strong>Conventions for Declaring Variables<br></strong>Generally, we use a variable name that describes what the variable will be used for. Additionally, there are several styles for writing the variable name when it contains more than one word. One convention is the camel case (eg. ​<strong>camelCase </strong>​). With this, the first word starts with a small letter and every subsequent word starts with a capital letter.</p><p><strong><em>Note: </em></strong><em>You also cannot have spaces between your variable names. For example, you </em>​<strong><em>can’t </em></strong><em>call a variable </em>​<strong><em>ball X </em></strong>​<em>but rather, </em>​<strong><em>ballX </em></strong><em>and no use of special symbols except an</em><strong><em> underscore </em></strong><em>(“</em><strong><em>_</em></strong><em>”)</em><strong><em> </em></strong>​<em>. You cannot give your variables names that have the same names as functions and variables defined by Processing such as </em>​<strong><em>width, height, mousePressed, mouseX, mouseY, rect(), setup(), draw() </em></strong><em>etc, these are called reserved words. So don’t use the reserved words above in your programs (sketch). Use other words, be creative!</em></p><p><strong>Initialization<br></strong>Now that we have declared a variable, the next step is to assign some value\data to it. The format for initializing a variable is:<br> name = value;</p><pre>age = 20;</pre><p>We can combine the declaration and initialization into one step: the format for combining declaration and initialization is:<br> datatype ​ name = value;</p><pre> int ​ age = 20;</pre><p>Note that the values of variables can be changed (increased or decreased) during execution. Arithmetic operations can be used to change the values of variables. The table below shows symbols that represent basic arithmetic operations in Processing (it is usually the same for most languages).</p><figure><img alt="Arithmetic Operators" src="https://cdn-images-1.medium.com/max/571/1*UCvhQkv77XPStIJb9mL0Yg.jpeg" /><figcaption><strong>Figure 10. Arithmetic Operators</strong></figcaption></figure><p>Now that we’ve declared and initialized a variable, the next step is to use it. Let&#39;s modify our game to use variables to store the following:</p><ul><li>Screen width and height of type <strong>float.</strong></li><li>Ball <em>x </em>​and <em>y </em>positions, width and height of type <strong>int</strong>.</li><li>Left paddle <em>x </em>​and <em>y</em> positions of type <strong>float</strong>.</li><li>Right paddle <em>x </em>​and <em>y</em>​ positions of type <strong>float</strong>.</li><li>Paddle width and height (remember that the left and right paddles should both have the same width and height) of type <strong>float</strong>.</li><li>Left player score’s number, <em>x </em>​and <em>y</em>​ positions of type <strong>int</strong>.</li><li>Right player score’s number, <em>x </em>​and <em>y</em>​ positions of type <strong>int</strong>.</li><li>Text size of type <strong>int</strong>.</li></ul><p>Also, we want to have the ball move at a certain speed and direction by:</p><ul><li>Creating and using variables for the ball’s <em>x </em>​speed and <em>y </em>​speed.</li></ul><p>We will use descriptive variable names and the <strong>camelCase</strong> naming style.</p><p>Modified code with variables declaration, initialization and usage.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/87cfa773abae29dd70ef661bdae432b1/href">https://medium.com/media/87cfa773abae29dd70ef661bdae432b1/href</a></iframe><p>Lines 49 and 50 makes the ball move by increasing the value of x-position and y-position (ballX and ballY) respectively.</p><p><strong>Here are things that might prevent our game from not executing:</strong></p><ul><li><strong>Misspelling the variable that was declared during usage.</strong></li><li><strong>Assigning a value that is not allowed for a given data type eg. age = ten.</strong></li></ul><p><strong>To avoid this, it’s best to use simple/descriptive words and avoid reserved words for variable names.</strong></p><p>Our ball now moves when we execute our game but disappears when it gets to the bottom edge of the screen. How do we resolve this? We would have to perform a certain action when some conditions are true, which in this case is bounce the ball <strong><em>if </em></strong>it hits the top <strong>and</strong> bottom walls <strong><em>or </em></strong>any of the paddles. To do this, we will use <strong><em>relational operators, logical operators </em></strong>and <strong><em>conditional statements </em></strong>such as <strong><em>if</em></strong>, <strong><em>if-else</em></strong><em> </em>and<em> </em><strong><em>if-else-if</em></strong><em> statements. </em>Let&#39;s look at relational operators and the structure of an if-else statement.</p><p><strong>Conditional Statements<br></strong>Conditional statements are used to perform certain actions when some conditions are true or false. Relation operators are used in conditional statements. In Processing, codes are usually executed in the order in which they appear but this can be altered with the use of conditional statements.</p><figure><img alt="Relational Operators" src="https://cdn-images-1.medium.com/max/657/1*HvV6jVU9PRrEbmG4fDfMAg.jpeg" /><figcaption><strong>Figure 11. Relational Operators.</strong></figcaption></figure><p>Relational operators are used to comparing only two values in a condition and then perform certain actions based on the outcome of the comparison.</p><p>Let’s look at the structure of the if, if-else and if-else-if statement.</p><p><strong>Structure of an if statement<br></strong>The structure of an <strong><em>if </em></strong>​statement is as follows:</p><p>if (some condition) {<br>&lt;code to be executed if the condition is true&gt;<br>}</p><pre> if (age &gt; 18) {<br>print ”You are eligible to vote”;<br>}</pre><p><strong>Structure of an if-else statement<br></strong>The structure of an <strong><em>if-else </em></strong>​ statement is as follows:</p><p>if (some condition){<br>&lt;code to be executed if the condition is true&gt;<br>} else {<br>&lt;code to be executed if condition is false&gt;<br>}</p><pre>if (age &gt; 18) {<br>print ”You are eligible to vote”;<br>} else {<br>print ”You are not eligible to vote”;<br>}</pre><p><strong>Structure of an if-else-if statement<br></strong>The structure of an <strong><em>if-else-if </em></strong>​ statement is as follows:</p><p>if (some condition) {<br>&lt;code to be executed if condition is true&gt;<br>} else if (some condition) {<br>&lt;code to be executed if condition is true&gt;<br>}</p><pre>if (age &gt; 18) {<br>print ”You are eligible to vote”;<br>} else if (age &lt; 18) {<br>print ”You are not eligible to vote”;<br>}</pre><p>To make our ball bounce when it reaches the bottom or top edge of the screen, we have to check <strong><em>if</em></strong> its y-position is greater than or less than the screen height then reverse the direction by multiplying with -1. To do this we have to use <strong><em>logical operators</em></strong> that allow us to perform a certain action(s) when multiple conditions are true, in this case, the conditions are y-position<strong><em> greater than </em></strong>screen height and y-position <strong><em>less than </em></strong>screen height with <strong><em>or </em></strong>as the logical operation. The table below describes the basic logical operators.</p><figure><img alt="Logical Operators" src="https://cdn-images-1.medium.com/max/653/1*sULatiHbxndgZTq4lTxZsQ.jpeg" /><figcaption><strong>Figure 12. Logical Operators</strong></figcaption></figure><p>Here is what the code to bounce our ball would look like.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1624f89f97d57e993204b70f95f812a7/href">https://medium.com/media/1624f89f97d57e993204b70f95f812a7/href</a></iframe><p>Our ball now bounces when it hits the top or bottom edge of the screen. Next is to make our game increase a player’s score when the ball hits the opponent&#39;s wall (left or right edge of the screen) and move the ball back to the centre of the screen. To do this, we have to do two things:</p><ul><li>check <strong><em>if</em></strong> the x-position of our ball is less than the screen width then increase the right player’s score and move the ball to the centre.</li><li>check <strong><em>if</em></strong> the x-position of our ball is greater than screen width then increase the left player’s score and move the ball to centre.</li></ul><p>Code to perform the above actions.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/08147084c2e81b68174de503cd41f1c5/href">https://medium.com/media/08147084c2e81b68174de503cd41f1c5/href</a></iframe><p>Our ball starts moving when we execute our game, I believe it will be nice if we can dictate when the ball starts moving. We can use the <strong><em>mousePressed </em></strong>system variable to decide when our ball should start moving, as its value is <strong><em>true</em></strong> when the screen is touched and <strong><em>false </em></strong>otherwise. To do this, we will create a variable, <strong><em>gameOn</em></strong>, of type <strong><em>boolean </em></strong>that will change from time to time when the screen is touched.</p><p>Let&#39;s go on and do that.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e70ba7a954193bf237d393c52f896760/href">https://medium.com/media/e70ba7a954193bf237d393c52f896760/href</a></iframe><p>Line 1 should be before the <strong><em>setup()</em></strong><em>, that is, where variables are declared </em>and lines 3 - 6 inside the <strong><em>draw()</em></strong> functions before the code that makes our ball to move.</p><p>Our game is almost done, we just have a few more tasks to complete, that is, make the ball bounce when it hits any of the paddles and moves the paddles when touched. Before we do that I will like us take a look at <strong><em>functions</em></strong> and how we can use them to organize our code.</p><p><strong>Here are things that might prevent our game from not executing:</strong></p><ul><li><strong>Not putting a semicolon “;” at the end of a statement.</strong></li><li><strong>Not putting corresponding closing braces “}” or brackets “)”.</strong></li></ul><p><strong>To avoid this, it’s best to write the closing braces or brackets right after you write the opening braces so you don’t forget.</strong></p><p><strong>Functions<br></strong>A function is a block of organized, reusable code that is used to perform a single or related action. You have already seen and used various functions like <strong><em>setup()</em></strong>, <strong><em>draw()</em></strong>, <strong><em>background()</em></strong>, <strong><em>fill()</em></strong>, <strong><em>rect()</em></strong> etc. These are called <strong><em>built-in functions</em></strong> provided by Processing but we can write our own functions as well which are know as <strong><em>user-defined functions</em></strong>.</p><p>For example, Processing doesn’t have a function called <strong><em>circle() </em></strong>to draw a circle. Won’t it be great if we had this? A circle is just an ellipse with the width equal to the height so we can use the <strong><em>ellipse() </em></strong>​ function to create a circle, just like we used it to draw our ball. To do this we have to define and call the function. Well now, let’s create a function that draws our ball!</p><p><strong>Structure of a function definition<br></strong>This is the structure of a function definition:</p><pre>Return type functionName(datatype parameter1, datatype paramenter2, …){<br>statements;<br>}</pre><p>We will name our function <strong>displayBall()</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3e0a899648fa8b02d1e684199865e805/href">https://medium.com/media/3e0a899648fa8b02d1e684199865e805/href</a></iframe><p>The above code should be written outside the <strong><em>setup()</em></strong> and <strong><em>draw()</em></strong> functions. To use the function to draw our ball, we have to call it in the <strong><em>draw()</em></strong> function.</p><p><strong>Structure of a Function call<br></strong>This is the structure of a function call:</p><pre>functionName(value1 or variable1, value2 or variable2, …);</pre><p>Let&#39;s use the above structure to call the <strong><em>displayBall()</em></strong> function to draw our ball.</p><pre>displayBall(​ballX,​ ballY, ​balldiameter); // call displayBall //function</pre><p>The above code should replace the initial code that uses ellipse to draw our ball in the <strong><em>draw() </em></strong>function.</p><p><strong>Function Name<br></strong>In the function <strong><em>displayBall(), </em></strong>​<strong>displayBall</strong> is the name of the function and follows the same <strong>camelCase </strong>naming convention as variables.</p><p><strong>Return Type<br></strong>The word <strong><em>void </em></strong>is the return type of the function. Return type specifies what data type (<strong>int</strong>, <strong>float</strong> etc.) the function will return and <strong><em>void </em></strong>means the function does not return any final value. We will look at an example in which we return something.</p><p><strong>Parameters<br></strong>What goes in the brackets when we define a function, such as (int x, int y, int diameter) are called parameters. Parameters allow the function to use data from outside the function within the function. When a programmer wants to use a function, he must know the number of parameters the function requires and the datatypes of those parameters. In our <strong><em>displayBall</em> </strong>example, the <strong><em>displayBal</em>l</strong> function requires 3 int parameters to run.</p><p>So when we called the <strong><em>displayBall()</em></strong> function in <strong><em>draw()</em></strong>, we supplied three int variables, that contained numbers, to it like this.</p><pre><strong>displayBall</strong>(​ballX,​ ballY, ​balldiameter);</pre><p>We also supply numbers/variables to functions like <strong><em>rect(), ellipse(), </em></strong>​etc<em>.<br></em>Let’s look at a function in which we return something from that function.</p><p>Check out this code we added previously.</p><pre>boolean gameOn; //hold boolean value to determine when to start game</pre><pre>    if (mousePressed)//check if screen was touched <br>{ // beginning of if statement      <br>       gameOn = true;<br>}// end of if statement</pre><p>Let&#39;s go ahead and make it a function that returns the boolean value of gameOn. We will name the function <strong>setGameMode</strong>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1811fb74a944dc8c521422b058f25a25/href">https://medium.com/media/1811fb74a944dc8c521422b058f25a25/href</a></iframe><p>We just have to call it in place of the previous lines code in the <strong>draw() </strong>function like this:</p><pre><strong>setGameMode</strong>();</pre><p>Note: The function code must be written outside the <strong>setup</strong>()<strong> </strong>or<strong> draw</strong>() function.</p><p>Our paddles have to move from top to bottom, which is the same as the y-position of both paddles. We will use the <strong><em>constrain</em></strong>() function to make our paddles movement fixed to the y-axis of our screen, by constraining rectYRight and rectYLeft to not exceed a maximum and minimum value. This ensures that the paddles do not go off the screen.</p><p>Syntax of the constrain function.</p><pre>constrain(amount, low, high)</pre><ul><li>amount: int or float value to constrain</li><li>low: int or float minimum limit.</li><li>high: int of float maximum limit</li></ul><p>Here is our <strong><em>movePaddle</em></strong>() function:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d4a9af8893fd2a79dfa27d0c2bfa8630/href">https://medium.com/media/d4a9af8893fd2a79dfa27d0c2bfa8630/href</a></iframe><p>The if-else statement makes only the paddle being touched to move. We can now call our <strong><em>movePaddle</em></strong>() inside the <strong><em>draw</em></strong>() function after the <strong><em>displayBall</em></strong>() function call.</p><p><strong>Variable Scope: Global vs Local Variables<br></strong>The variables that we have been defining thus far have been outside the <strong><em>setup</em></strong> and <strong><em>draw </em></strong>functions. These variables are called <strong><em>global variables. </em></strong>​Global variables can be used anywhere, which is how we have been using them.​ <strong><em>Local variables</em></strong>, on the other hand, are usually created in a function and can only be used within the functions in which they are defined and their values are lost after the function exits if they are not returned or stored in a variable outside the function when they were called. We will look at how we can save the value in a <strong>local variable </strong>returned by a function so that it doesn’t get lost after the function exits.</p><p>Let&#39;s create a function to check if the ball has overlap any of the paddles. We will name the function <strong>doesOverlap</strong>() of type <strong><em>boolean.</em></strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dcbbed26dae6e1067b050f10c5dc7b56/href">https://medium.com/media/dcbbed26dae6e1067b050f10c5dc7b56/href</a></iframe><figure><img alt="Ball and paddle overlap" src="https://cdn-images-1.medium.com/max/1024/1*9m52WjGhg5AsUvxelZKQPQ.jpeg" /><figcaption><strong>Figure 13. Ball and Paddle overlap</strong></figcaption></figure><p>The function checks if the ball overlaps the paddles and returns true or false. We first calculate the top, bottom, left and right edges of the ball and the paddle.</p><p>Then we check for four things:<br>1. Does the bottom edge of the ball overlap with the top edge of the paddle<br>2. Does the top edge of the ball overlap with the bottom edge of the paddle<br>3. Does the left edge of the ball overlap with the right edge of the paddle<br>4. Does the right edge of the ball overlap with the left edge of the paddle</p><p>If all four conditions are true, we return true from the <strong>doesOverlap </strong>function, else we return false.</p><p>Next, we will create two <strong>boolean </strong>variables of global scope, <strong>hasOverlappedRightPaddle </strong>and <strong>hasOverLappedLeftPaddle</strong>, that will take the value the <strong>doesOverlap</strong>() returns. We will use the variables in the functions that will check for when the ball and any paddles overlap to reverse ball direction.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/603ce0b27a70f0417e33a4e31d09bfc9/href">https://medium.com/media/603ce0b27a70f0417e33a4e31d09bfc9/href</a></iframe><p>We can now call both functions inside our <strong>draw</strong>() function like we did others.</p><pre>checkLeftPaddle(); // call function to check left paddle and ball //overlap<br>checkRightPaddle();// call function to check right paddle and ball //overlap</pre><p>We should place all code that checks when the ball hit any of the walls together to be a single function. This time we will set <strong>gameOn </strong>value to false if the ball hit left or right walls, so the ball won’t move until the screen is touched again. <strong>checkWall</strong>() can be used as the function name.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6785161a4e7274004680e4884b1c2a88/href">https://medium.com/media/6785161a4e7274004680e4884b1c2a88/href</a></iframe><p>Our <strong>draw</strong>() function should look like this now.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b4bbeb8c398b4bde18adc5004e8549f2/href">https://medium.com/media/b4bbeb8c398b4bde18adc5004e8549f2/href</a></iframe><p><strong>Here are things that might prevent our game from not executing:</strong></p><ul><li><strong>Misspelling a function that was defined during function call.</strong></li><li><strong>Naming a function with reserved words.</strong></li></ul><p><strong>To avoid this, it’s best to use simple words that describe the action the function will perform and avoid reserved words for function names.</strong></p><p>Wow, our game is finally complete now and can be enjoyed with friends.</p><p>You can check out the complete code for this game on GitHub <a href="https://github.com/eonyedikachi/Android_Pong_Game">here</a>.</p><p><strong>References.<br></strong>1. Lessons from SuaCode Africa organized by <a href="http://nesesafoundation.org/"><strong>Nesesa Foundation</strong></a>.<br>2. <a href="https://processing.org/books/">Getting Started with Processing</a>. Book by <a href="https://en.wikipedia.org/wiki/Casey_Reas"><strong>Casey Reas</strong></a> and <a href="https://en.wikipedia.org/wiki/Ben_Fry"><strong>Ben Fry</strong></a>.<br>3. Official site of Processing language <a href="https://www.processing.org/"><strong>https://www.processing.org</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b782579ee950" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>