Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint

9.3. Creating the game objects

The asteroid avoidance game is going to have two main objects: the asteroids and the player rocket. Each of these objects are going to be created as JavaScript classes. You might be wondering why you're going to use a class for the player when there is only one of them. The short answer is that it's possible that you might want to add multiple players into your game, in which case it's going to make things much easier if the player is created with a class.

9.3.1. Setting up the asteroids

Using classes for your game objects means it's dead easy to reuse and repurpose them in another game. For example, in the asteroid avoidance game you're going to use the same asteroid class as the bowling game, with just a few changes.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial