Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Learning Java by Building Android Games - Third Edition

You're reading from  Learning Java by Building Android Games - Third Edition

Product type Book
Published in Mar 2021
Publisher Packt
ISBN-13 9781800565869
Pages 686 pages
Edition 3rd Edition
Languages
Author (1):
John Horton John Horton
Profile icon John Horton

Table of Contents (24) Chapters

Preface 1. Chapter 1: Java, Android, and Game Development 2. Chapter 2: Java – First Contact 3. Chapter 3: Variables, Operators, and Expressions 4. Chapter 4: Structuring Code with Java Methods 5. Chapter 5: The Android Canvas Class – Drawing to the Screen 6. Chapter 6: Repeating Blocks of Code with Loops 7. Chapter 7: Making Decisions with Java If, Else, and Switch 8. Chapter 8: Object-Oriented Programming 9. Chapter 9: The Game Engine, Threads, and the Game Loop 10. Chapter 10: Coding the Bat and Ball 11. Chapter 11: Collisions, Sound Effects, and Supporting Different Versions of Android 12. Chapter 12: Handling Lots of Data with Arrays 13. Chapter 13: Bitmap Graphics and Measuring Time 14. Chapter 14: Java Collections, the Stack, the Heap, and the Garbage Collector 15. Chapter 15: Android Localization – Hola! 16. Chapter 16: Collections and Enumerations 17. Chapter 17: Manipulating Bitmaps and Coding the Snake Class 18. Chapter 18: Introduction to Design Patterns and Much More! 19. Chapter 19: Listening with the Observer Pattern, Multitouch, and Building a Particle System 20. Chapter 20: More Patterns, a Scrolling Background, and Building the Player's Ship 21. Chapter 21: Completing the Scrolling Shooter Game 22. Chapter 22: What Next? 23. Other Books You May Enjoy

Reusing the Pong engine

Feel free to copy and paste all the code in this section. It is nearly identical to the structure of the Pong game. What will vary is the other classes we will create (Bullet and Bob) as well as the way that we handle player input, timing, updating, and drawing within the BulletHellGame class.

As you proceed with this section, glance over the code to notice subtle but important differences, which I will also point out to you as we proceed.

Coding the BulletHellActivity class

Edit the BulletHellActivity class to look like this next code:

import android.app.Activity;
import android.view.Window;
import android.graphics.Point;
import android.os.Bundle;
import android.view.Display;
// This class is almost exactly
// the same as the Pong project
public class BulletHellActivity extends Activity {
// An instance of the main class of this project
     private BulletHellGame mBHGame;
@Override
protected void onCreate(Bundle savedInstanceState...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}