Time for Some Fun: A React Native Game, Part 1

Writing books isn’t my day job. My regular job is as an architect (who, thankfully, still gets to hack code a lot) for a large financial firm, and in that capacity, I also do a lot of mentoring of more junior developers. In that role, every so often, I am

  • PDF / 408,155 Bytes
  • 34 Pages / 504 x 720 pts Page_size
  • 89 Downloads / 190 Views

DOWNLOAD

REPORT


Time for Some Fun: A React Native Game, Part 1 Writing books isn’t my day job. My regular job is as an architect (who, thankfully, still gets to hack code a lot) for a large financial firm, and in that capacity, I also do a lot of mentoring of more junior developers. In that role, every so often, I am asked by developers what they can do to improve their skills. My answer is always immediate: make a game! Game programming is, I’ve found, a unique endeavor, because it forces you to confront so many different problems, and it touches on a great many computer science topics, many in subtle ways that you don’t even realize at first. I’ve found that few other types of projects are as good an educational experience as game programming, and that’s why I think all developers should make games. Plus, games are, by their nature, fun. That’s the goal of a game, after all, and making a game tends, likewise, to be fun (even when the inevitable frustrations of things not working as expected come up). Now, in the previous chapter, we did, in a sense, make a game. However, I would argue that it wasn’t a game, per se (that certainly wasn’t the objective when I wrote the original Webix version); it was more of an app that happened to have an element of fun to it. In this chapter and the next, however, we’re going to create a straight-up game with React Native. In the process, we’ll have to confront some new problems and find some interesting solutions to them that will offer insights into React Native that you may not have gained in developing more traditional apps. Part of game programming tends to be finding ingenious solutions to problems, to make things work just the way you want, and that’s no less true when making a game with React Native, which offers you the opportunity to see things a little differently than you have to this point. © Frank Zammetti 2018 F. Zammetti, Practical React Native, https://doi.org/10.1007/978-1-4842-3939-1_7

271

Chapter 7

Time for Some Fun: A React Native Game, Part 1

So, let’s jump right in and talk about what kind of game we’re going to build. Make no mistake, this won’t be the next Fortnite or Halo or Angry Birds. It’s not going to make anyone a million bucks on the app store, but, as a learning experience, it’ll get the job done.

What Are We Building? As a kid, did you ever have one of those sliding puzzle games? You know, a plastic square with a bunch of numbered plastic tiles on it that you can slide around, the goal being to put the tiles in order. Well, that, in a nutshell, is what we’ll be building. In Figure 7-1, you can see what it looks like. It’s not a complex concept, to be sure, but it’s a proper game nonetheless.

Figure 7-1.  The FunTime game

272

Chapter 7

Time for Some Fun: A React Native Game, Part 1

Playing is as easy as can be: the player taps a tile, and if it’s beside the blank space, the tile slides into the blank space. That’s literally it for game mechanics. If and when the player gets all the tiles into the right order, he or she will be rewarded, such as it is