Coding the Observer pattern in Scrolling Shooter

Now we are well versed on how the Observer pattern works and we have had a good look at the interfaces we will need to write and how they will be used we can put all the theory into action in the Scrolling Shooter project.

As the specific use for our broadcaster and observers is to handle the player's input we will code a class to handle the screen touches for the HUD. As a reminder, the GameEngine class will be a Broadcaster and two separate classes that handle user input will be Observers. As the HUD and the player's spaceship are very different things it makes sense for each of them to handle their own input.

We will code the UIController class which will be our first Observer (for the HUD play/pause ...

Get Learning Java by Building Android Games - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.