Android Game Development - Create Your First Mobile Game | Sandip Bhattacharya | Skillshare

Playback Speed


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

Android Game Development - Create Your First Mobile Game

teacher avatar Sandip Bhattacharya, Software Development Teacher, Developer

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

18 Lessons (3h 12m)
    • 1. 1 Introduction to the Course

      2:37
    • 2. 2 Create the Project

      11:06
    • 3. 3 A high level overview of project Flappy Bird

      5:20
    • 4. 4 Create BitmapBank class

      4:51
    • 5. 5 Create GameView class

      7:04
    • 6. 6 Create GameThread class

      10:35
    • 7. 7 Create BackgroundImage class

      5:19
    • 8. 8 Continue constructing the GameEngine

      4:27
    • 9. 9 Finish the Framework

      23:13
    • 10. 10 Draw the bird, apply Gravity and interact via Touch

      27:28
    • 11. 11 Draw the Tubes

      31:30
    • 12. 12 Change Tubes randomly

      7:46
    • 13. 13 Scoring System

      7:12
    • 14. 14 Collision Detection

      4:46
    • 15. 15 Add Sound Effects

      11:00
    • 16. 16 Design GameOver screen

      8:33
    • 17. 17 It's GameOver

      17:54
    • 18. 18 Course Wrap Up

      1:09
  • --
  • 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.

647

Students

2

Projects

About This Class

Hi, do you want to learn how to build Android Games in Java?

My name is Sandip. I have published more than ten android games on Google Play. So, I happen to know a little bit about android game development and in this class, I’ll show you exactly how to create this awesome Flappy Bird game using Android Studio and Java.

This class is perfectly suitable for anyone who wants to learn the game development fundamentals like creating an efficient Game Loop, handling the Touch Event, Collision Detection, Playing Sound Effects, Score, saving Personal Best, designing XML Layout, creating Different Levels for your game with increasing difficulty, etc. If you want to learn the basic framework for games then this is the right class for you.

And, if you want to learn android game development by writing code in Java then you’ll enjoy this class. While my previous class focused on using Android’s View class, this class is aimed to provide a solid foundation for a more dedicated Android class for game development: SurfaceView.

I believe the best way to learn mobile game development is by making one. So, I will walk you through the process of creating this game, from start to finish, step by step in a completely hands-on fashion.

At the end of the class, you’ll be able to build a complete Flappy Bird game using Java which you can be used as a framework or template for any game you build or publish in Play Store. You'll have a clear understanding of the core concepts behind a 2D game. You’ll have an improved Java skill. You

You probably know that android is the largest eco-system for gaming so if you’re serious about your career in the gaming industry, this is a great place to start. Or, if you just want to learn programming then Java is an excellent language which is also the preferred/default language for Android and building games is great fun. Over the years, I have helped hundreds of students in making their Android games and there’s absolutely no reason why you can’t as well. So, Enroll now and let’s get started.

Meet Your Teacher

Teacher Profile Image

Sandip Bhattacharya

Software Development Teacher, Developer

Teacher

Hello, I am Sandip and I am a Programmer, Online Course Creator, YouTuber, and Entrepreneur from India. I have 13+ years of overall programming and teaching experience including Android apps and games development, Web development, and multiple programming languages including C, C++, Java, PHP/MySQL, and jQuery. I obtained my B. Tech and M. Tech degree, both in Computer Science & Engineering. Intellectual Curiosity, Creativity, and Deep Honesty are the three pillars of my life.

I have trained many aspirant computer science students and software professionals one-on-one in various software practices all over the world. I am currently creating video-based online courses for different online learning platforms and working from Kolkata, India. I have nearly 700 students on Skills... See full profile

Class Ratings

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

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

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 to the Course: Hi. Do you want to learn how to be laundered games in Java? My name is Cindy, and I have published more than 10 and board games in Google Play store. So I happen to know a little bit about game programming, and I will show you exactly how to create this flappy part game using under studio and Java . - This course is perfectly suitable for anyone who wants to learn the core concepts P and to the game, like creating an effective game. Luke Handling the Attachment Coalition Detection Playing sound effects Score. Seven. Personal Best Descending XML Leo. It's a If you want to learn a basic framework for games, then this is the right course for you. And if you want to learn came development by writing code in Java, then you really enjoyed this course. White. My previous court focused on using Anders Few class. This sport is aimed to provide a solid foundation for a more dedicated underclass for game development surface. I believe the best way to learn game programming is by making one, so I will walk you through the process of creating this game from start to finish step by step in a completely hands on fashion. After end up this course, you will be able to build a complete flappy part game using surface pew, which you can publish in place toe. It will have a clear understanding off the poor pond steps behind the coup de game. It will happen. Improved JavaScript. Android is the largest ecosystem. Forgive me. So if you are serious about your kid here in the gaming industry, this is a great place to start. Or if you just want to learn. Programming in Java is an excellent language, which is also the preferred language for android. And building games is a great fund. Over the years, I have helped thousands of students in making their android games, and there is absolutely no reason why you can't as well so enroll now and let's get started . 2. 2 Create the Project: being developing ABS, you need to create a project in under studio. Mostly, we're designing XML on right court in Java or Courtland. If you haven't installed and rest to do yet, go ahead and install and nurse todo from this link before you begin. I'm using version 3.1 point four at the time of recording. In this lecture, I will cover the basics of designing ex Emily out. I'm going to add an image button a text you and change some basic properties. Then I will show you how to get the click event on that image button by day. And you will be able to design this exim allowed on get the click event on Image start and their studio in the wake. Um grande is to do a window click starting new panders to do a project in the create ender project screen right, Flappy bird for the application name for companies. Moment. I'm going to use Sunday potentially a dot com, which is my website. So the package appears in diverse order that is calm dots and the party Sharia dot flappy bird. Click the three dots to change the project location. I'm going to state the project on my dick, stop just below the package name. You can see two check boxes for including support for C plus percent coddling. As we are using Java for this project, we can leave them on checked. Click next in the target under devices screen. Keep the default values and click next in the end, an activity to mobile screen. Select empty activity and click next in the configure activity screen. Keep the default values and click finish. Wait for under studio to configure and build your empty project. You need a play button in the main activity layout. When pressed, the game should start to do that. Copy and paste the main underscore background and play button images into the travel folder . Goto. The layout folder under Ari is double flick activity underscored main dot xml. Change the layout to related lee out Jesu background, too. Android Poland. Background At tribal. It's less mean, understood background. Next we can deal. It takes for you as we don't need that anymore. Go to design tap, select the text through and hit Delete key from the pellet, click buttons and drag and drop and image button on to the center of the layout. This causes the resource window to pop up. Click Project. Select a misplay. Click OK. The android image button component is an image you surplus, which displays a button with an image instead of text and can be pressed or clicked by the user. Go to take step and change this piece off court to and right colon background. Goto designed tap from the palate like common Next Dragon Drop. It takes food below the image burden. The undertakes poop component is a views upper class, which is capable of showing text click Dick Step James that takes to play lit and necessary codes change the take size Too attractive for SP S B stands for scale Independent picks is is a measurement unit and its skilled according to that, users prefer text size, so you should use this when defining tick size for low sizes. You should use creepy or density independent pixel position. Need to below the image button given margin. Top of 10 dippy change the color at Android Colon Color Slash are low underscored trade on the school dark. Now let's get the click event on image button. The purpose off this button is to start a game when it stopped. But for now, let's identify the click event. There are many ways to accomplish this. One technique is to write a method name in the on click property and implement a myth or in main activity, touch over right on Dracula. Non click start game Next to go toe Main activity toward Java defined start game by writing public for it. Start him. When those fantasies have you view open close calibrates. This method takes the view perimeter. Even if we don't need it, just import view by pressing all 10. Enter. If it is not imported automatically, right click on the package and create a new job. A class called Game Activity. Select Activity. A super class click OK, inside this class right click. Generate over, Admit Arts and select on Create. We will get back to this class later, open main activities or Java and go to the definition of start game. Use a lock statement to confirm that we're getting the ligament to ride lock statements. You can use the law class with the falling methods logged R D. I loved that. I it's It's the two parameters. Attack and message, respectively. So right, love that I for tag site Major Barton and for message right clicked import log by pressing alternators. If it is not imported, automatically click the Greenland button to run the app in android emulators. Click lock it Now click on the image, but none confirmed that we're getting the log information. So to recap, I have covered a little bit about designing a basic XML out. You also know how to get the click event on Image button on right to lock statement. Next, I'll give you a high level overview off our project. See with the next video. 3. 3 A high level overview of project Flappy Bird: in this lecture, I'll give an overview off our project and Android surface will class. Let's begin. Salafist Group provides a dedicated drawing surface embedded inside of you hierarchy. What's the difference between South Visit you and view when you create a custom view and override, it's on drama thought. All drawing happens on the white rate, which is also used for all user interactions. So if you need to update you rapidly or if the rendering takes too much time and affects user experience, then use surface. Will I have noticed surface prue contents in nice rendering mechanism that allows traits toe opted the surfaces content without using a handler, which is good for animation. I have also found that there much faster for any mission than rendering onto a few. Access to the underlying surface is provided further surface holder interface, which can be retreat by calling Get older. The surface will be created for you while the surface feels window is visible, you should implement surface created and self is destroyed to create and destroy the surface as the window is shown and hidden, we will establish several models in our program. Number one. Get the input data from the user number to store the data somewhere in our program. Number three display the results on the screen program models. Communication diagram is as follows. Game three Loop diagram is as follows. Each figure that is displayed on the screen off our android device is a job object with its own logic in your game. We have three objects off that type barred background image and to every object, has his X and Y coordinates that identify its location on the screen. I will act more properties when we create the classes. In the last lecture, we have created the game activity. We will sit. It's a few with the custom view. Say, give you that extend service will surface. Boo extends few class. That's why we could sated as our activities content view when created. That is when called New from Inside game activity. Gib, you initialize is and starts the game straight. Object Argh! Imbue implements surface holder got called back interferes and we need toe a right few mentors, like surface created. So it was changed and self is destroyed in self has changed. We don't do anything since it's not in our interest surface created is invoked when game activity content view is initialized in on create, and it simply starts again. Treat Surface destroyed is called when game activities on post on stop or on destroy life. Second metals are called, and we will stop the game. Take it from here. Gin treat is the one that refreshes our screen. The magic happens in its run method. Run will continue to execute in its while loop as long as the bullion is running. Variable is true. The first thing that ran meth or does as it's interstellar, while Lou is to lock the canvass. All the update and drama thoughts in the gaming jean object that will update our business logic in our case at once the background Tubes and BART. And finally it unlocks the canvas, draws our object with updated perimeters and goes to sleep for a specified amount of time that calls if peace are crimps per second. This game in gym class is where we will dry it all our business logic drying my thoughts, and it keeps instances off all displayed objects in our case. Background image barred tubes. A tutor. We will create bit map Bank class responsible for loading bit map instances from resources and keeping references to them. Similarly, we will create a class for loading and playing games sound. We will create up Constance Class, which instance Yates bit map bank, sound bank and gaming, Jean objects s static members and defiance Pure important starting methods. We will listen toe touch events by overriding the own touch event method and call our methods defined in game engine. When the action is motion event thought action underscored down. So in this lecture I have given a high level overview off the whole project. If things are not clear to you, don't worry. In the upcoming lectures, I will show you how to implement our framework. Step by step, Soudan. 4. 4 Create BitmapBank class: In this lecture, we will start creating our framework, starting with my bank class, responsible for loading bit map instances from resources and keeping differences. This class also defined several methods to get the dimension off our beat Mary midges. We will also define a method for Skilling the background image open and less to do right, click on the package and create a new Java class limit. Big bank Inside this class, right click Genetic con sector Put resources paramilitary in the constructor. We will pass resource object when calling this constructor copy and paste the background image in to Travel folder. This image has a dimension up 1024 by 512 pixels. Declare a class level beaten up object reference for this background in the constructor instance sheet background background it falls to bit map factory got de court results The source. Come on, r dot driver. I thought Matt bound The big factory class provides several decoding methods. Decode bite a decode file dick or resource etcetera for creating a bit map from Perea sources. Next, we will create some gate and retorts inside this class. - Next we will create the game Pew class suit then 5. 5 Create GameView class: in this lecture will create Give you class When this object is created. It initialize is and starts the game trick. Our game New implements surface holder got called back interface and we need to override a few methods like surface created, surface changed and suffers destroyed. Let's start open and nurse To do right, click on the package and create a new Java class game view. Select surface through as the super class. Place alternator on the red squiggly line and create the constructor that takes on Lee Context as perimeter imbue should implement surface holder. Don't call back. Press alternator on the red squiggly line and implement all the methods. Call in it view inside constructor next defined this method. This is where we initialized the surface holder and trade objects for it. It it for you. Surface holder order death it calls to they told us holder dot at call back. This said for possible True declare a gifted object reference in game bju. Instance Shit in In interview, put holder in the game set Constructor with this holder object, we will lock the canvas draw and then unlock and verse and pull stopped it in surface created middle chick for that red state. If it is not running, we will create a new game treat, object and start. The treat is we will simply call start if not him. Treat Dark is running him Trade closed toe new, he entered because the holder has been limited. Stop. The trade is tempted. I thought Start in surface changed. We don't do anything since it's not in our interest in surface destroyed meth or we will stop the treat if hims it docked is running came through it. Dart sit. He's running folds bullion. Try equals two. True while try It was a try catch, block game thread Start. Join to stop the said Trey Cause too falls catch, inject exception. That's it. Next, I will show you how to create the game. Ted Class. I know it's taking a while, but don't loose passions. You are building your own game framework based on which you can build any number of games with better court management. It is more than or theory for See you in the next video 6. 6 Create GameThread class: in this lecture, we will create our trade class from the previous lecture. We know that game view initially is the game trick object and called start gift. It is the one that refreshes our screen. The magic happens in its run without run will continue to execute in its look. As long as the bullion is running for table is true. It's Stunt Open and Nurse studio right. Click on the package and create a new Java class. Name it Game for it. Select Trade A Super class defined the constructor Public game Trade of interest fantasies Open close Colleague brace Put surface holder object as perimeter declared this variables since class scope surface older surface holder bullion. He's running long stock time coma Look time long delay Next inside the constructor, right this dot surface Older. He goes to surface older. He's running, he calls truth true. Next, we will overwrite the run method, which starts executing once we call start May 3rd on game Tate object from give you right John and select. The first method removed the super, he said. This Matar we will use a while loop, which keeps on looping Till is earning parable Palo is true in the constructor we have, said the fellow Toby. True So it enters off. I look by default. We will save the current time in milliseconds in stark time. Variable. Then we will lock the canvas, using the surface older object. Next, we will use a synchronous block for the service older inside which we will call methods for updating and drawing the background image. And we will define this myth or inside our game engine class. Then we will unlock the canvas and posed upped it. Finally, we will calculate the loop time, and if it's less than delay, we will call slip for the remaining duration. That is delay minus look. Time to maintain a steady animation, right? Why he's running. Start pain, he calls, too. System clock dot Up time. Millie's canvas canvas he calls, too, have a soldier dot lock and was no if gun was an article. Seasonal synchronized surface. Older ap constance dot Get game engine not update and drop background Image, canvas surface older dot Unlock and wasn't post canvas Luke time it calls to system clock dot up time. Elise, my nest. Start dying If look time less than delay. Try thread, dart sleep Deal it minus look time catch, Interpret exception log. Not he for tag right. Interpreted on for message. Right? Interrupted while sleeping. Import log. As you might have gazed, we will now define our app, constants and game engine class. Right Click on the package and create these classes quickly kept stance. Game engine. Create the constructor for game engine. Next, I will show you how to create background image class for your side schooling an emission suit there. 7. 7 Create BackgroundImage class: In this lecture, we will clear background image class which will be responsible for background image, side schooling and emission. Let's start open and their studio and create the background image class. Defend the constructor in the class scope declared this variables private int background in magics background image Why Background image velocity initialize in constructor background. The magics because 20 background image y it cost 20 background image velocity Because 23 the background image will be initially positioned at top left corner of the screen. That's why we gave X and Y positions to zero and zero for the velocity I have set three. Next we will define some gator and sit Irma thoughts Public int get ticks, Return back Guarantee magics public int Get white Return back Current of his way public for it Sit ticks into background The magics This docked background thematics He calls too back on the magics Public for it I said Why int that guarantee? Which Why this got background image? Why? Because to I won't do is why public into kid velocity return background image Felicity In the next lecture, we will continue constructing the framework were not too far from finishing the basic framework. So get excited and I will see you in the next video 8. 8 Continue constructing the GameEngine: in this lecture will continue creating game engine class this game engine classes where we'll diet all our business logic drying my thoughts and it keeps instances off all this place. Upticks in our case back aren't image Bart Dube's It's it. Let's go open and rest Radio Goto game engine declared. Background, image, background, image and instance She ate in constructor migrant image. He quotes to new going to Mitch inside game engine. We will define a mid thought for drawing the side schooling background image right public. Avoid abd it and draw background image canvas, canvas document background. Image, eggs by background. Image. Felicity for the right to live moment. Background image. Dark sit dicks, background image docked. Get ticks minus matt. Don't image not get velocity. If begun, emit X becomes less than minus background to it. We re initialize it to zero. If background image not get X less then minus AP constants dot Get to teach my bank dot Get back on with background image, not civics. Zero. Draw the bit map canvas docked. Drop it. Map AP constants Not get with that bank dot Get background comma background Image not yet takes coma back guarantee, mitch dot Get Why, coma? No. We will create the APP constants class next and finish the framework. Who will also be able to see some output in the next video? See you then. 9. 9 Finish the Framework: in this lecture, we will be creating have constants class and finish making the framework my day, and you will be able to do this. So let's begin open and Mr Do Goto app. Constants declare static object references. Static bit NetBank between bank static game engine, game engine Define Dimitar to initialize thes optical finances Public static. Avoid initial Asian context context but for bank cause, too. New bit map bank context. Start. Get resources. Remember that in the big bank class in the constructor we are going to receive is also subject game engine because to new, um engine define. Get with my bank public static bit. NetBank. Get to beat my bank. Return the trip bank define get game engine, public static game engine, get game engine Really done Game engine, goto game trait and defined the falling two methods Public bullion He's running. Return is running, - probably for it. Sit is running. Julian State is running because to state go to manifests copy and paste the activity tag below. Remove the intemperate attack and changed the name to game activity. Go to main activity. Instead, start. Give me thought. We will launch game activity by calling start activity meth or using an intent object intent acts as the glue between two activities. Right intent intent, he calls too new in dent this game activity dot class start activity intent. We also need to call initialize meth or off app constants from main activity and passed the application context after set content. View right. Ap constants dot initial aviation This not get application context Finally, goto game activity on declared a gimp You object reference on instance shit in on create game view. Give you give you he calls too new give you. But these as context. Use this object to say the content view. Sit content for you give you now you can finish the main activity as it's no longer needed . Goto main activity and called Finnish metal run that. As you can see, the background image is not taking up the full screen. I will give you a quick challenge to fix this issue. Pause. The video now will come back. I hope you manage that. My solution is to create a myth or for scaling the bit map. But before that, we need to know screen with and height. So let's first declare that in app constants static into skin with comma screen height, then created, McCord said. Screen size to sit this interior variables. Private static, right? Sit screen sighs. Corn fixed context wouldn't know. Manage it w him because to cast this into window manager Okay, context, not get system service context dot When do underscore service display display? Because to W him got get default display display metrics metrics because to new display matrix display dot get metrics metrics int quit. He calls, too. Metrics not with big cells. Int height, he calls too. Mystics dot high pixels ap constants dot screen underscore with He calls to with AP constants dot screen underscored height because true height Next cold set skin size Inside initial Asian set screen size context. Goto with that bank and define scale image. Public it. Fat scale image. Mitt map. It's map float with Hi Trish. You because to get background with dont buy get background height int background skilled with cause, too. Cast this into integer without this you into AP constants. Dark screen underscore Hide Return bit map dot Create scaled with map mitt map coma, background. Skilled with coma AP constants Dark skin and discard height. Coma faults Call this method inside constructor background because to scale image background run that. - As you can see, the background image is leaving a trail once it leaves the right age off the screen. Challenge for you to fix this. You can pause the video now. Welcome back, I hope you manage. Set. If you haven't been, just follow along with me. Open game, engine inside, update and draw background image, myth. Or we will write our logic for that. If background image X becomes Liston, miners within parentis is background image UIT minus came to it. That means when their background image is living the right edge of the screen, we need to re initialize by grant. Emit X by adding background image with tow it tow. Create a continuous scrolling. The falling draw between myth or gets called on Lee win the background images living the right edge of the screen on a right tulip animation. But when the background image takes becomes less than minus background image with that means when the background image is living. The left it off the screen, we said, but don't image X 20 right here to start over the size. Schooling an emission. If by County Mich docked get takes, it is then minus. Have you spent it? Sees AP constants not. Get to 12 bank dot Get background with minus have constants, not screen. Underscore wit canvas not draw trap half constants. Not get the truck bank, not get background Coma background. Image dot get ticks plus AP constants not get between bank dot get background with Come on background. T Mitch not get away. Coma Now run that Perfect. So congratulations on making your own gaming primer. As we move on, we will keep on improving by adding more features into it. Next, I'll show you how to draw the part on canvas, apply gravity and interact fire, touch. 10. 10 Draw the bird, apply Gravity and interact via Touch: in this lecture, I will show you how to draw the flying bar on canvas up like gravity and interact for touch . By the end of this lecture, you'll be able to do this open and extra do. We will create a frame by frame animation for the BART in frame by prime animation. We will be changing frames repeatedly so that it appears continuous to the human eye and we feel that it is animated. A frame is referred to an image. So to implement this type of animation, one needs to have a state up images which describe emotion for a one game. I have four bark frames. Let me copy and paste this Bart frames in my travel folder. Next, go toe bitten up bank and declare an area bit Map Mitch map open close brackets. Bard initialize that area in constructor Bard. He goes to new, Which map four. Bart zero close to between factory not de court resource. How he is coma, huh? Docked travel not barred under school from one. Next, we will define some gator. My thoughts public bit map. Get to bart and frame return Bard frame public int get bad with return Partido not get with public into get barred height return bar Zito that get tight. Next, we will define the partners that will keep track off X Y coordinates. Card in frame editor, right click on the package and create a Java class. Name it Bart Genet, the constructor public bard in the class scope declared the Falling Variables Private int bar Dicks Bar Dwight got in frame public static into max fame initialized in constructor, Keeping in mind that the Bard will be positioned at the center of the screen originally and vertically, bar Dicks equals two AP constants, not screen. Underscore wit divided by two minus have constants dot Get between bank dot Get bad with the red is red, too. Bar Dwight, because to have a constant dark spin and a score height, they were ready to my nest. Once stents dot get to be 12 bank dart. Get barred height. Did you read too? Got in FIM because 20 and Max for him should be tree. Next we will drive some gator and sit in my thoughts. Public int get going from return carrying for him public public and get takes return bar dicks public hint I get why return barred way public Avoid septics int bar dicks This not bionics cause to Marnix Public Boy it Sittway int by light This docked bar Dwight He wants to MARTA way next Goto game engine and declare an object apart. Berg bark instead she it in Constructor Buck because to New Bart. Then we will write the myth ord in game engine for updating and drawing the BART. We will first get the current frame from Bard Object and call Drop it map may 3rd on canvas . Then we will inclement the frame. And if it exits the max frame, we re initialize it to zero. Let's right the court public ward update and draw barred canvas, canvas and current framed because to bard dot Get going for him canvas, not drop it. Map for big map Use happy constants dot Get between bank dot Get barred current frame for left use bard dot Get ticks for top use. Barred, not get why, and we don't need a paint object. That's why use now in cumin dickering for him, sky and frame plus plus if garden frame good. But then Bard, not Max for him Karen frame he caused to zero Barred. Not, said Karen Frame Karen for him. Next, Goto gim treat and call this myth or inside the synchronized block, of course. Tense docked. Get Kim engine not up. Didn't draw barred canvas run that brilliant. Next, we will introduce gravity in our game, goto up constants and declared static int gravity. Initializing constructor. Gravity cost to tree. We will add a variable for Felicity in barred class and initialize in constructor comma Felicity Felicity because to Syria. Cool right guitar and sitar for Felicity Public int get velocity Return Felicity Public Right said Relies ity and Felicity this dart Felicity Because to Felicity Goto game engine inside Update and draw Bart meth ord. We need to check if the Y coordinate off. The Bard is less than screen height minus body. That is, if the bar is inside the screen, who will add gravity with this velocity and say it? Why coordinate with its velocity, right? If Bud not get, why, please. Then AP constants Dark screen on disk or hide minus AP constants dot Get Petra bank start. Get bad height, bard dot said Velocity bard dot get Felicity plus at constance dot gravity. But Dot said, Why Bard Not get Why? Plus, but Dot get Felicity. So for the first call velocity zero Gravity's three current velocity zero plus three cost. Two tree. We will say it the Y coordinate with tree in the next call. Velocity is three. Gravity is three. Can velocity is three plus tree that it's six. Who will say it? Why coordinate with six This way? The displacement in why direction gets increased part amount of time and we see a gravity bubble on the part. Run there. As you can see, jeopardy is working, but we need a mechanism that the gravity only starts acting once we tap on the screen to start again. Tap should also give the barge some a poor sift or jump. We need to define number one and integer credible in game engine for storing game. State number two. An indigent constant velocity under school when underscored, jumped for the amount of support shipped. Let's do that. Go to game engine and declared static int games. Did it initialize in constructor against it close to zero. Put the first if condition inside update and draw barred in another. If give against it probably cause to one next. Goto app on stance and declare static int Felicity Quinn jumped initialized inside initialization. I have constant, not Felicity, and the school win underscored jumped because to minus 40. Change it toe ap constants dot gravity Next inside game view. We need toe over right on touch. Event to detect motion event on the screen like tap or place on the screen. Right on. But she event int action because two event dot Get action if action probably cause too motion event dot action and just go down. Ap constants dot Yet game engine dot games dit because to one AP constants God get Kim Engine start. Bard Not sent velocity consents Thought Felicity when jumped. Return True. Run that Excellent now are part response to touch, but we have one issue. When Bard y is gated, then or equal toe screen height minus barred height, that is when the bar touches the bottom edge of the screen. We're not able to move it up. Can you fix that? Pause the video. Now we'll come back. I hope you have managed that as well. When the bar touches the bottom edge of the screen, the inner if condition gets false and hence the state velocity or the state, why myth or don't get called? But by adding this in the if statement, we can fix that or by not get velocity plays, then zero Run that one second. Fantastic. I hope you injured this lecture and learned a few new things from it. Next, I'll show you how to draw a few sets off tubes which randomly appear from right to live with random positions and reappear again and again. 11. 11 Draw the Tubes: in this lecture, I'll show you how to draw a few sets off cubes with random positions that come from right to live and reappear again and again. By the end of this lecture, you will be able to do this open and nice to do. I'm going to copy my tube images in travel folders. What? The images have a damaged enough 90 by 554 pixels. Next goto beat were bank and declare two bit compatibles bit map duped up. Coma do bottom Instance She ate in constructor duped up because to meet my factory dot decode resource hot he is Oh, my, uh not driver. Not do you wonder Score top similarly right to bottom. He calls too between factory dot to good resource Obvious Mama, our got driver dot to underscore Barton. Next we will define gator mature toe Get details about two images Probably Big 12 get duped up. He done duped up public with map Get to bottom return Do bottom public int get do bullet it done duped up dot Get with public and get to height return duped up not get tight Since all tubes have the same width and height, we can return any tubes with Next, we will create the tube class responsible for maintaining to position in random fashion, right click on package and create a new Java class. Name it to you, declare to interject variables to hold X coordinate and top to upset. Why that its top to bottom it's y coordinate five it hint. Do Bix Come on, stop! Do upset White cynical Next declare and memorable in class scope. Private, random, random. Next, create the constructor and initialize public Do and do wicks comma int Top to upset way. This docked two weeks because to two weeks this dot stop to offset. Why? Because to top do boxid white random, he calls too new random. Next, we will define a constant for the gap between the top two on bottom to say, 600 pixels will doapp constants and declare static int gap between top and bottom tubes. Inside. Initial Asian cities follow to 600. You can experiment with different values if you want. Next, we will ride some gator and sitting methods as usual public int get top to upset. Why return top two of Sittwe public int get do wicks Britain do wicks public and get top two y return. Talk to upset. Why minus happy constants dot Get to between bank dot get do height public int Get bottom to boy. Return top to offset Why, plus have constants dot gap between top and bottom tubes public. Avoid said Do Bix int two weeks this dot two weeks Because to do Bix public Avoid said talk to upset. Why this not talk to upset? Why he calls to stop to offset? Why not? That the Y coordinate for the top edge off the tube is top to offset. Why miners to fight and the y coordinate for the top Each off bottom two is talked to Upset y plus Gap. Why we need this. We will called Robert Web McCord shortly, which takes top left, coordinate off the beaten path image. That's why next we will define the method for drawing the tubes Goto game engine and declare an aerialist off Type two are released. Do you dupes initialized in constructor dupes called True new at least who will define few new for edibles in app constants. Let's do that quickly. Static int number off tubes, static int duplicity static and mint tube upset. Why static and Max To offset white and static int? This tends between tubes. Not that we will animate two sets up tubes at a time Mean to upset? Why is the minimum Y value off the bottom? It's off the top to Max to offset. Why is the maximum y value off the bottom? It's off the top two Next initialized variables inside insulation AP constant not number of tubes. He calls to to AP constants, not duplicity. He calls to 12 AP constants. DOT meant to upset Why? Because to cast please into in teacher constants dot gap between top and bottom tubes directed by two points. It'll happy constants Dr Max to upset White Because to at constance dot screen underscore height minus ap constants Dot meant to upset. Why minus ap constants dot gap between top and bottom tubes AP constants dot distance between tubes he calls truth happy constants dot skin, underscore wit and to three by four, these values are just my assumptions, and you can certainly experiment with different values. If you want. Let's quickly create a method and put this court inside. I will limit set game constants public static, Boyd said. Given constants. Next, call this myth or from initial ation. Just before instance, Sheeting Gaming, Gin Object said game constants. Next Goto game engine and defined a random object turned them random inside. Constructor, right? Random Because to new fandom now just below the tubes, at least definition. We will write a for loop to general to two objects with random positions and add them to our tubes. A realist for and I first toe zero I place then constants dot number of tubes I plus plus int do wicks because to have constants, start skin underscore wit plus I and to happy constants dart This test between tubes int top to offset. Why? Because true ap constant dot mean to upset Why plus random docked next int ap constants dot max To upset White my nest hap constants dot mean to upset. Why last one to do Because to new do do wicks top to offset away dupes. Not at do I have positioned to tubes here for the first situation. The fellow off I is zero so two bigs will be called to screen with the next tube is separated by three foot units off the screen with From the fast You we are generating talk to upset. Why in between mean to upset why and Max to upset why he was in the next 10 myth or after and numb object? Then I have created a to object using the values and added to a realist, we will define the update and drawer tubes method in game engine. Next, when the 1st 2 goes away from the left edge off the screen, we said two bigs in the chart position again. We also randomly changed the top to upset way. This way we confer actually create an infinite number of tubes coming in there. None. Fashion finally would decrease two bigs by to publicity and draw the top two on bottom tubes. Public Reut update and drawer tubes. Canvas canvas Ive Gibbs did it because to one four int I he cost 20 I leads them ap constants dot Number of tubes I plus plus If dupes docked, get hi dark, get do Wicks Liz, then minus ap constants dot Get it, matt bank dot Get to with tubes dot get hi dot Set to mix dupes dart get hi dot get two weeks plus hap constants dot Number of cubes into have constants dot distance between tubes int top to offset Why he caused to ap constants dot i mean to upset Why plus random docked next int hap constants dot max To upset White My nest constants dot meant to upset. Why last one dupes dot get i dot said Talk to offset Way Top two of Sittwe dupes dot get hi Dot said two weeks Dupes not get hi dot Get two weeks, my ness happy constant dart Duplicity canvas dot Drop it map forbid pap use ap constants dot Get between bank dot Get duped up for left use dupes dot get hi dot Get do wicks for top right dupes dot Get i dot get top DuPuy. We don't need a depend objects to use now Can was dot drop it met Have constants, not get 12 bank dot Get to bottom coma dupes dot get hi dot Get two weeks. Come on, dupes dot get hi dot Get bottom to boy coma. Finally, we will call the myth or from our trade game trip. Yep, constants. Not get dimension dot update and drawer tubes. Canvas hopes we have many mystic just, Goto said. Talk to upset by definition and change, too Thinned. Talk to upset. Why that's it. Run that excellent. So in this lecture, you have learned how to create a few sets up Dube's with random positions that come from right to live and reappear again and again. Next, I'll show you how to select a set up to from multiple tubes having different colors. See you in the next video. 12. 12 Change Tubes randomly: in this lecture, I'll show you how to change jobs and family. By then, you will be able to do this. Let's start open in the studio. Copy your second. Set up two images into travel folder. I'm going to copy the day tubes. Remember both types of tube should have the same dimensions. Next. Goto between bank and declared to beat member tables for top and bottom mitt Map rate cooped up comma red to bottom. Instance. She ate in constructor. Red Tube Top equals two Vitra factory dot Because resource obvious, come on r dot tribal dot rate and the score to underscore top. Similarly right. Read to bottom because to bit more. Factory Dark Deco Resource Hardy is kama are not travel dot Great underscore to underscore Button, who will define the methods for getting the two bit maps Public bit trap. Get to it. Duped up. Return. Great Tuto Public bit map. Get ready to bottom return. Read to bottom. Next, we will introduce a new indigent variable for two color into Georgia. We will, as you jury cost to green one Acosta rate. We will define a method to generate a number either zero or one. Call this matar from constructor, so each time it do was created, a color will be assigned to it either zero or one. Based on these values, we will either draw green to or read to in game engine Public Void said to color two colors close to random dot next int to declared to color in class level. Private int two colors. Let's also define a myth out forgetting to color public int get to color. Did turn tube color goto game engine and write the logic for drawing tubes inside. Update and draw tubes. If dupes not get hi dot get to color double because 20 got this two lines on a piston is best one second. Change this to get rid to talk and change this To get to bottom, we will also call set to color to generate a new color. Once a tube goes out off the left edge of the screen, dupes dot get i dot said to color. Run that awesome. So in this lecture you have learned how to change tubes randomly. Next, I'll show you how to implement a scoring system for our game. See you in the next video 13. 13 Scoring System: in this lecture, we're going to explore how to create the scoring system off our game. By the end of this lecture, you'll be able to do this. Let's start open and nice to do. We need to keep track off. Which, too, is our active scorer, are escorting to scoring. Two is the two that is currently located in front of the Bard, so I will declare to interject for tables 14 score and the other for tracking scoring. Two. Let's do that inside commission int score int Scoring too initialize inside constructor school because 20 escorting do because 20 Next, we'll write our logic inside update and draw tubes method. The idea is we will check the current two against the bar position if the right age off the two passes the lifted off the Bard without hitting, we can assure that we made a school. Now we have two tubes in the tubes. Analyst. So the index Paris from 0 to 1 when the 1st 2 with index below zero lives left age off the screen. It reappears after the second. To this way, the tubes keep coming initially escorting too busy you if that condition is satisfied. We will increment, score and scoring to buy one escorting to become skated than one. We will Jeanne. She lies it to zero this way. Scoring two perfectly varies between zero and one, thus can be used as an index for tubes. At least this trick will also help when we will implement code for coalition deduction, because we can then focus only on the current to and not all the tubes. Let's right the court inside update and drawer tubes at the beginning. If dupes not get according to dot get do wicks less, then Bard docked. It takes minus constants, not get bit netbank dot Get to with score plus plus according to Plus Plus, if, according to We're that, then after constants dot number of tubes minus one, escorting to he calls to zero. To draw the score, we need to declare a paint object. I will name it. Score print bent score bent. Instead, she it in constructor score print because two new event score print dot sit color color dot red score print dot sit dick size 100 score print dot sit text airline bent dot a line dot lift, perhaps it. The paint color to rate have tested the fellow off 100 Toby Good for displaying Score and Alan toe the left. You can create a static variable in app constant for storing tick size If you want, the final thing would be to draw the school right inside update and drawer tubes. Canvas dot draw text Bt four point plus scored coma, coma and then 10 Coma score print Run that. Obviously there is no coalition. At this moment on Lee, the score gets increased as the Bard posits that do so in this lecture. I have shown you how to create a scoring system. Next, I'll show you how to detect coalition between the two and the bar. Soap it. Excited. See you in the next lecture. 14. 14 Collision Detection: in this lecture, I'll show you how to predict coalition between the bar and the two. By the end of this lecture, you will be able to do this. Let's start. We have a coalition. If 12 bigs is less than bod X plus barbed wit and two point a stop do opposite why is get it then, by the way, are to Point B. Bottom two y is less than bod y plus barred height open under studio. Let's write code inside update and drawer tubes at the beginning. If dupes not get according to dot, get two weeks less, then bard dot it takes class happenstance dot get with my bank dot get, but with and dupes dot get according to dot Get top to upset. Why that then bard dot Get white Ford dupes not get escorting to not get bottom two y Let's, then bard dot i get why plus ap constants dot Get with my bank dot Get about height against it. He caused to do love dot de for attack. I'm gonna write game and for message. I'm gonna right over changed the next If two else if press control all too ill to format the code. Run that. - Excellent . So in this video, we have written code for pollution detection. Next, I'll show you how to play sound effects. See there. 15. 15 Add Sound Effects: by adding will sound effects. We can make our game more interesting and fun in this picture. I'll show you how to add sound effects to organ by the end of this lecture will be able to do this. The 100 Multimedia prime work includes support for playing a variety of common media types so that you can easily integrate audio video etcetera into replication. Media Player class can be used to control playback off audio or video files and streams. In order to use Media Player, we have to call a static method off this class called Create This method returns. An instance off Media Player class is syntax is as follows. The second perimeter is the name of the audio file that you want to play. You have to make a new folder under our ideas with Name Bro and plays out if ice into it. Once you have created the Media player object, you can call some methods to start or stop the music. These matters are listed below. Media player dot start Media player got pause Uncalled to start matter, the music will start playing from the beginning if this method is called again after the pause method. The music would start playing from where it is lived and not from the beginning. In order to start music from the beginning, you have to call reset method. It's sin taxes, media player dot visit Apart from the start and pause meth. Or there are other methods provided by this class for better dealing with audio or video files. These methods are is playing seek to get duration, said Looping, etcetera open and a studio. I will create a folder inside Arias name tro. Next, I will put my audio files there. Next, we will create a separate class to load and manages the audio files right click on package and create a class I will limit. Sound Bank denied the constructor public sound ring context context. We will call this constructor from initial Asian retort off app. Constant So declared a sound bank object reference in that constants. Static sound bank sounding. Instance it inside initial ation without so Meg because to new sewn bank context, creating meth or to get the sound rank object. Public static sound bank gets own bank return sounding. Next, we will construct the sound in class. Copy that context in class level variable context for next this dot context because to context Next, go to sound rang and declared media player objects for each sound media please Shoes Coma point coma hit comma. Instead, she ate in constructor Jewish because to media players docked. Create contexts From what r dot draw docked Sushi point Because to media players dot create context. Come on r dot draw dart point hit because to media player dot create context. Come on our dot draw dot hit wing because to media players dot create context. Coma are dot We're all docked wing right then this is intimate thoughts public. Avoid place shoes if su ish not because to no shoes Not stocked public. Freud play point. If Point Nordic goes to now, Point Dr Stocked public. Boyd. Play it if hit. No articles to nal hit Docked stock Public Boyd Play wing If WING Not because to now wing dot start Next Goto game view and inside untouched event. If the game steady zero, we will change came Steptoe one and play the search sound. If game status not zero, we will play wing sound right? If at font stents not get game engine dark games did. It probably caused 20 help constants not get game engine not gives. Did it? He caused one. AP constants. Not get sound. Bank dot Place shoes ills constants dot gets on bank dot Play wing Next Goto game engine and write quote for playing the point and hit sound effects inside opted and drawer tubes. AP Constants Docked gets owned bank docked. They hit constants, not gets own rank dot play point run that. So in this lecture, I have explained how you can play a sound clip using media player class. Next, I'll show you how to design the game of us. Great. See you there. 16. 16 Design GameOver screen: game over screen Is the ending point off your game? In this lecture, I will demonstrate the basics of designing Exim allowed for game over by then, you learn how to design this. Let's start open and rest todo right. Click on package and create a new job, a class I will name It came over. Select app combat activity as Super class and click OK inside the class. Type on, create and select the first method from the drop down list that takes a bundle. Object as perimeter after Super Call, Right said Content View Hot dot layout dart game on the school over. Now we need to create and design that game. Underscore over dot XML File Goto Arias layout Right click New layout Resource file Name it gave on the scoreboard for root element type realistically out. Click OK in December. You from the palate dragon. Drop a button on lift up. Go take step changes, takes property to distort. Click on the red squiggly line and praise all turn enter to insult layout. Underscore Alan Parent left to True right restart for own click property. I'll write this method in Java later. Change the background at android colon color for us less How long the school blue underscored. Dark tens takes color to white cash if it if it If. If you were pending off 10 dippy go to design tap, drag and drop another button on right up. Go to take step. Click on the red squiggly line to insert layout. Underscore Align Parent Right to True Who to take step copy Paste. The falling property fell appears on click background takes color betting I've exit for on click and exit for text. Put some padding ineligible out. Right reading 10 dippy Change the background operatively out. I'm not going. Background at travel for us Less men on the school background checked out. Put now for displaying the score, etcetera. Click the layout, Stab Cilic, linear load, particle and dragon Drop in the center of little bloat. Go to the take step and change the layout. Underscore wit and lay out on the score. High properties to wrap content Go to descend tap for displaying score dragon drop another linearly out Original into the particle in allowed using component tree drop takes pills or what? They're just the first excuse takes to score column space I will change the second takes Whose i D TV school changes dick size to talk to six sp James Text color at Android Colon Color for us less hollow underscore orange in the school dark I will change. This takes pooh sticks using Java letter. You don't need the i d for the fast takes you, so just delete it. Copy and paste this whole original linear load. Will you change the first exposed takes to personal best for the second takes to get it up to Texas Property change text color to hollow. Understood Green underscored Dark. I will change the I D to TV personal best. Also programmatically changes stakes in Java. Next movie game over. Image in trouble. Goto designed tap and call up the two hora Gentle India loads next from the palate. Images drag and drop and image you into the particle linear load and select image dill It Older layout underscore weight properties to display at Justin textbooks. I'd say, though it's totally up to you. Check the final work. So to recap, you have just learned how to design inevitably complex Exim allowed. Next, I'll show you how to save your personal best score using shared preferences. Locals. Tourist tactic in Android You'll also know how to implement, restart and exit Fisher. By the end of the next lecture, you will have a complete flappy bird game, so get excited and I will see you in the next video. 17. 17 It's GameOver: game over signals a player that the game has ended. In this lecture, I'll show you how to display the score and say personal best using shared preferences Lucas Tourist Technique in Android. He will also know how to implement restart and exit feature. By the end, you will have a complete game like this. So when the BART got hit by it to the game is over and the player is transferred to game over screen along with the school . Using an intent object Intent can carry data types as key value pairs called extras. Using pu dextromethorphan, we can add the score veloute to intent. The start activity method can start game over activity specified by the intent, but we have one problem. We don't have context available. He had in game engine, so let's create a context variable in APP, constants to store gave activity, contexts, static context, game activity, context and initialized in game activity. Right below the super cool constants, I thought game activity context he caused to this next Goto game engine where a coalition is detected, right? No context context. It was to have constants dot game activity context, intent indent because to new intent context comma him over not class intent. Start put extra scored comma school context dot start activity, indent activity, corn fixed start finish or to give more Dari java. We will receive the score from intent. Object is that on? Create right int scored because to get intent docked, get ticks does dot getting school next. We're going to store the highest score using shared preferences, shared preferences allow you to save and Richard data in the form of Kiva LaPierre. That will persist even when you close their share preferences. Is application specific, that is, the data is lost on part, forming one of the falling options on uninstalling the application on clearing the application data through settings. To get access to preferences, we have three meters to choose from. Get preferences, get shed preferences, get default shared provinces. In this lecture, we will go with get yet preferences. That method is defined as follows. Get yet preferences String perhaps underscore name, comma int moat, but perhaps underscore Name is the name of the file. More disease operating mood. The falling court can be used to get the shared preferences shared preferences brave because toe get yet preferences. Open toes fantasies within double courts. My Pref Comma 004 Private mode to edit and save the changes. Call edit on shared preferences Toe. Get it? She had preferences. Start editor Object. Add values with Mitt or such as Put Lilian forcing Exeter Comet A new values with Comet It's in taxes. Shared preferences, not editor editor, because to pay, if not edit editor not put into within fantasies within double courts. Score comma school editor dot com it to read values use methods such as getting gets thing . It's it. We will create a share preferences object and define an integer variable to store travel. The first perimeter off getting is the key. I will name it Score SP, but you can name whatever you want. The second parameter is the default value follow to return. If this preference does not exist, right shed preferences Brief because to get shared preferences My brief comma zero int score sp Because to brief, I thought getting scored SP comma zero create the shot preferences start editor object shed provinces not editor editor because to brief dot head it next unit to check with at the school that we get from the intent is hard then school SP If it is true, we will assign score in schools, speak using portent method right If score created, then score sp scoreless speak he caused to scored editor. Not putting score is speed coma scores speak Finally, Comet, your changes editor dot com It next we need to programmatically change that takes viewers text to do this Declared to takes poor differences in class level Digs view TV Score Coma TV Personal Best associate By calling find the way i d TV score he caused to find view Way i d are not I d. Dart TV score to be about some of the best he caused toe Fine view Why I did r dot i d thought TV Personal Best call Set text on text to handle to display score and personal best TV score dot said text school to be personal. Best Dark said text score sp Next we'll right that they stuck me Thought public. Avoid pretty start field ville intent intent because took new intent. Game over dark This coma main activity dark class start activity indent finish right, they exit may 3rd public Avoid exit view feel finish. Go to manifests and copy paste and activity tag below change the name to dot came over. Now we know that toe have I draining the battery and android device that is left idle quickly falls asleep, but certain app, such as games, need to keep the screen turned on. At this point, I will give you the challenge to make the game activity full screen. Set it to be portrait only and keep the skin turned on. You can pause the video. No good luck. Welcome back, Hope you, man, is that my solution is as follows. Goto gave activity and right inside on create after super cool. This not request window feature window dot Feature No title this dot Get window Not said flags wouldn't to manage it. Not Leo Problems dot Flag and the school Full screen coma window manager, Not Leo Problems dot flag under school full screen this dot Get window dot at flags, window manager dot player problems dot flag and the school. Keep underscore screen underscore own import window and window manager if required. Next goto android manifest and add these two lines inside the open activity tax for every activity and right Gordon Conflict gingers. What condition? Fight. Keyboard Didn't android Colon screen orientation portrait One final touch Run that Great . So to recap, you have just learned how to programmatically change It takes pills text say personal best using shared preferences on implement restart and exit feature Finally, you have a complete game ready to be published in place toe Congratulations. 18. 18 Course Wrap Up: when you started this course, you were embarking on a new and rewarding journey as a game developer. So congratulations and thank you for your commitment and devotion. You have successfully learned Android came programming that will help you in your Katya education are freelancing projects. I'm proud of you. If you have any queries, please ask them in the Q and a section I always get back to my students within a day or two . Please fill free to live an honest review, and I would appreciate if you write a few sentences and not just click 1 to 5 stars but actually leave a few sentences about what you're injuring about this court's or what I can do to make this course even better. I can't wait to hear your feedback and see your reviews. Finally, I hope you tried applying the concepts. Start in your projects along with me. If you would like to show me what you have created, Please toe. I love looking at my students accomplishments. Have a great day or night, thanks again for taking interest in this course, happy learning