Monkey Game Development:Beginner's Guide
上QQ阅读APP看书,第一时间看更新

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.