Chapter 6. Advanced input and events

 

This chapter covers

  • Monitoring for events with event loops
  • Getting keypresses directly with getKey
  • Moving characters around the homescreen
  • Building a fun, interactive game with event loops

One day, you pick up your calculator, having made yourself several games and programs. You’ve shared them with your friends, and they think you’ve done a good job. You’re frustrated, though, because the games aren’t very interactive. You want something more immersive, where you move a hungry mouse around the screen, trying to collect pieces of cheese. You want to make the game challenging, so you need to add a way to lose: you add a hunger bar. You decide that the hunger bar will gradually fill and that the player will lose if the hunger bar fills up. In sketching out your game, you envision something like the screenshot in figure 6.1, with a moving mouse (M) chasing a piece of cheese (square).

Figure 6.1. You imagine making a Mouse and Cheese game.

6.1. Event loop concepts

6.2. getKey

6.3. The Mouse and Cheese game

6.4. getKey odds and ends

6.5. Summary

sitemap