This example of a clicker game uses global variables to track taps and multipliers as the player aims to make as much money as possible.
The ‘score’ is tracked using the global number Currency and over time the game adds TapNumber (which is the amount of currency received either per second or per tap on the device screen) multiplied by the Multiplier variable to keep the currency increasing.
Player’s can then use this currency to upgrade the products which then increase the amount of currency earned and the cycle continues.
The products are simple sprites which have instance variables to track their current level and their passive and active earning totals. The passive earning count is how much just having the product contributes to the TapNumber variable, whereas the active earning count is how much currency is added every time the player taps the specific product.
Once the player has amassed enough currency, an upgrade button for a product will become visible on the screen. When pressed, the relevant amount of currency is removed from the player’s total and the product’s level increases by one. Their passive and active earning values are set accordingly. The same upgrade button system is used to allow the player to purchase extra multipliers which increase the Multiplier global variable, thus allowing them to earn more currency.
A key feature of a clicker game is the ability to earn currency while the app is suspended. This is relatively easy to set up using the unixtime expression. Unixtime is a standard representation of time on a lot of systems and it’s the current time in milliseconds since January 1st 1970. By recording the unixtime when the game is suspended and reopened, we can calculate the difference, turn that into seconds and then award the player the appropriate amount of currency depending on how much time has passed.
The final feature in the basic clicker game is the ability to save progress. The project simply uses Construct’s inbuilt save game system, creating a new save every ten seconds, though realistically in a real game this probably isn’t frequent enough. The project contains a Boolean which tells the game whether it’s been loaded before. If the Boolean is false, the game has previously been loaded on the device and the save data is then loaded. Note if you’re building this game yourself, it’s best to implement savegames last or disable them once you’ve confirmed they work – if you’re saving and then make changes to the layout for example, the new layout won’t be loaded as it’s not present in the save data!