Author: John Horton
Pub Date: 2015
Size: 11 Mb
About This Book
– Acquaint yourself with Java and object-oriented programming, from zero previous experience
– Build four cool games for your phone and tablet, from retro arcade-style games to memory and education games, and gain the knowledge to design and create your own games too
– Walk through the fundamentals of building games and use that experience as a springboard to study advanced game development or just have fun
Who This Book Is For
If you are completely new to either Java, Android, or game programming and are aiming to publish Android games, then this book is for you. This book also acts as a refresher for those who already have experience in Java on another platforms or other object-oriented languages.
What You Will Learn
– Set up an efficient, professional game development environment in Android Studio
– Build your very own Android UI using easy to-use tools in Android Studio
– Add real-time interaction with Java threads and implement locking/handling screen rotation, pixel graphics, clicks, animation, sound FX, and many other features in your games
– Explore object-oriented programming (OOP) and design scalable, reliable, and well-written Java games or apps on almost any Android device
– Build and deploy a graphical pong-style game using advanced OOP concepts
– Explore APIs and implement advanced features such as online leaderboards and achievements using Google game services
– Make your game compelling to be the next big hit on Google Play market with a content update strategy and in-game marketing
Android is the fastest growing operating system (OS) with one of the largest installed bases of any mobile OS. Android uses one of the most popular programming languages, Java, as the primary language for building apps of all types. So, you should first obtain a solid grasp of the Java language and its foundation APIs to improve the chances of succeeding as an Android app developer.
This book will show you how to get your Android development environment set up and you will soon have your first working game. The difficulty level grows steadily with the introduction of key Java topics such as loops, methods, and OOP. You’ll then use them in the development of games. You will learn how to build a math test game, a Simon-like memory game, a retro pong-style game, and for the grand finale, a Snake-style, retro arcade game with real Google Play leaderboards and achievements. The book has a hands-on approach and is packed with screenshots.
- They make sense from an organizational point of view
- They are a proven way of structuring a program that works
- The nature of the system we are working on forces us to use them
In Android, we use threads for all of these reasons simultaneously. It makes sense, it works, and we have to use it because of the design of the system.
In gaming, think about a thread that receives the player’s button taps for “left”, “right”, and “shoot”, a thread that represents the alien thinking where to move next, and yet another thread that draws all the graphics on the screen.
Programs with multiple threads can have problems. Like the threads of a story, if proper synchronization does not occur, then things go wrong. What if our soldier went into battle before the battle or even the war existed? Weird!
What if we have a variable, int x, that represents a key piece of data that say three threads of our program use? What happens if one thread gets slightly ahead of itself and makes the data “wrong” for the other two? This problem is the problem of correctness, caused by multiple threads racing to completion, oblivious of each other—because they are just dumb code after all.
The problem of correctness can be solved by close oversight of the threads and locking. Locking means temporarily preventing execution in one thread to ensure that things are working in a synchronized manner. It’s like freezing the soldier from boarding a ship to war until the ship has actually docked and the plank has been lowered, avoiding an embarrassing splash.
The other problem with programs with multiple threads is the problem of deadlock, where one or more threads become locked, waiting for the right moment to access x, but that moment never comes and the entire program eventually grinds to a halt.
You might have noticed that it was the solution to the first problem (correctness) that is the cause of the second problem (deadlock). Now consider all that we have just been discussing and mix it in with the Android Activity lifecycle. It’s possible that you start to feel a little nauseous with the complexity.
Fortunately, the problem has been solved for us. Just as we use the Activity class and override its methods to interact with the Android lifecycle, we can also use other classes to create and manage our threads. Just as with Activity, we only need to know how to use them, not how they work.
Sadly, this book does not have the time to go into the mathematics of turning a dot on the screen into realistic three-dimensional characters moving around in a three-dimensional world. Certainly, the technology and math behind big-budget titles is very advanced and complicated. However, the basics of turning pixels into lines and lines into triangles, texturing a triangle, building objects out of triangles, and positioning them in a three-dimensional world are within the grasp of anybody who has learned high-school-level math. Often, we hear that great graphics don’t make a great game, which is true, but great graphics (at least for me) are one of the most exciting aspects of video games, even when they are displayed on a game that could be more fun to play by itself. If you want to see how to turn pixels into magical worlds, and start to appreciate what goes on behind the scenes of the top game engines and graphics libraries, you could start with Computer Graphics: Mathematical First Steps, P.A. Egerton and W.S Hall, Prentice Hall.