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 — modifying the launcher class

Time for action — modifying the launcher class

To modify the launcher class, follow the ensuing steps:

  1. Open the launcherClass.monkey file.
  2. Modify the Update method and add a CreateRocket call there. The parameters are the mouse coordinates and the X position of the launcher.
    Method Update:Int()
    If KeyHit(triggerKey) And cRockets > 0 Then
    CreateRocket(MouseX(), MouseY(), Self.x )
    cRockets -= 1
    

What just happened?

We have just activated the functionality that will create a rocket when you hit a trigger key.

Updating the rockets

As the game progresses, each rocket should move closer to its target position and check if it has been reached. We can do that with the UpdateRockets function.


  

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