Things that go bump in the night...
It's time to create some "Game Mechanics" whenever our avatar bumps into a "treasure icon". Let's open "Event Sheet 1" and insert a couple of global variables to hold the "amount of treasure discovered" and generate a "random amount" whenever this prototype starts.
Step #7: Right-click inside "Event Sheet 1" and "Add a global variable" for "treasure amount" and another for "treasure found". (See the illustration below.)
Step #8: Click "Add Event". Select "System > On start of layout". Add an action to this event #2. Select "System > Set value". A pop-up appears and you'll type the information below.
- Global variables hold the "amount of treasure generated", and the "amount found".
- Event #2: When this prototype starts, a random amount of treasure — from 50 to 500 coins — is generated for this gaming session and stored in the "`treasureAmount`" variable.
- Event #3: Whenever the avatar bumps into the treasure chest, we add that amount to its "treasure Found" variable and remove those coins from the "treasure Amount". If we don't do this, a clever gamer will repeatedly bump into the treasure chest and "earn(?)" a vast fortune! This is an important step because when we have more than one treasure chest, we want to ADD each of them to the avatar's "amount found". We also make this treasure chest disappear to show that it was discovered and prevent the avatar from "double dipping into the cookie jar". (If you catch my meaning?)
Step #9: This might be a good time to add a "Heads Up Display" (HUD) telling the gamer how much they discovered. A "HUD" could be a text object simply stating, "You found XXX coins".
Test what we have so far! OR, Compare your code to these examples: