O'Reilly logo

HTML5 Game Development HOTSHOT by Makzan

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

Generating coins and diamonds

In this task, we create the economy of the game by generating the coins and diamonds.

Prepare for lift off

Before getting into the code, let's summarize how the buildings affect the coins and diamonds:

  • The generation of coins and diamonds depends on the number of buildings
  • By default, each coin is generated within a fixed duration
  • More coin generators speed up the coin generation process
  • The merchant building trades 200 coins for a diamond once in a while, unless there are not enough coins
  • These buildings are where the population resides
  • We count the number of power supplies to know the maximum population capacity

Engage thrusters

To generate coins and diamonds, perform the following steps:

  1. First, we define the tickCountForMerchantDiamond ...

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