O'Reilly logo

Monkey Game Development by Michael Hartlef

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action — spawning some cities in the game

To spawn some cities, follow the ensuing steps:

  1. Open the mainClass.monkey file, if you haven't done so already.
  2. Inside the SetupGame method, to create three cities, we will use a FOR loop.
    score = 0
    'Create 3 cities
    For Local i:Int = 1 To 3
    
  3. Call the CreateCity function. The x position will be at one-fourth of the canvas width. After that, close the FOR loop.
    CreateCity((cWidth/4) * i)
    Next
    

What just happened?

We told our script to create three cities once the game starts.

Rendering the ground and the cities

As we actually want to see the cities in the game, we need to add something to ensure it happens.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required