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
Share this Page URL
Help

3. Game #2, Rocket Commander > Time for action — creating some launchers in the...

Time for action — creating some launchers in the game

To create launchers follow the ensuing steps:

  1. Open the mainClass.monkey file.
  2. Inside the SetupGame method, add the left launcher by calling CreateLauncher. Its x position is 30 pixels and it has the A key as a trigger and 15 rockets to start with.
    Next
    CreateLauncher(30.0, KEY_A, 15)
    
  3. Add the right launcher using a different x position and S as the trigger key, but also specify that there are 15 rockets.
    CreateLauncher(cWidth - 30.0, KEY_S, 15)
    

What just happened?

You told the game to create two rocket launchers at the beginning of the game. Easy, isn't it? Creating those classes pays off now.

Updating the rocket launchers

In each frame, we want to check if one of the trigger keys was hit and then fire a rocket.


  

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