Skip to content

Tutorial: Add collectibles and scoring

Add coins and diamonds that players collect for points. Bali generates the art and sound, writes the logic, and helps you debug it when something doesn’t work the first time.

Cave arcade game, part 4 of 6. Each part builds on the one before. See all tutorials.

You’ll learn how to: describe a new mechanic so Bali gets it right, generate images and sounds as part of a feature, and use on-screen labels and logs to track down a bug.

Prefer to watch? Play the full video (15 min)

For a new feature, the more specific your prompt, the better Bali’s first attempt. Say what the player collects, what each item is worth and where it should appear. The video uses this prompt:

I want to add a collectible mechanic. Can you generate some coins and jewels as images? I want a gold coin that’s worth 100 points, and a diamond that’s worth 200 points that I can put in different rows. If the player collects them it will add to their score.

The collectible prompt in Bali’s chat, followed by Processing

Watch this step (00:00)

The asset generator opens with a request for each item and a prompt Bali wrote. Under Advanced Options you can see where each file will be saved and its size. Remove Background is turned on, so the items blend into the game. Edit the prompts if you like, then click Generate.

The asset generator with the Gold Coin Collectible prompt and Advanced Options open

Watch this step (00:35)

Once the images are done, Bali carries on with the feature and asks for a sound effect to play when the player collects an item. Play the sound in the card to preview it. If you want something different, change the prompt and generate it again. Click Done to move on.

The Generate Audio card with a Coin Collect Sound prompt and an audio player

Watch this step (01:08)

With the art and sound ready, Bali already knows what the mechanic should do. It writes the code for detecting when the player touches an item, awarding points and updating the score.

Watch this step (02:11)

Bali pauses to ask how the items should spawn. It suggests options such as fixed positions, patterns along rows, or items that move.

Bali explaining how collectibles are configured and offering to create example spawners

Watch this step (03:19)

Begin with items that don’t move. The player has to time their run, dodge the obstacles and pass through the item’s position to pick it up.

Watch this step (03:50)

On the first test, only one coin appears on screen, so something in the spawn logic isn’t right yet. Describe exactly what you see when you tell Bali.

Watch this step (05:47)

Ask Bali to add logging and to label each coin on screen, so you can see which coins spawn and where. In the video, the labels showed that some coins were spawning in the danger zone, so Bali moved them into rows with obstacles or platforms. When everything works, ask Bali to remove the debug labels.

Colored debug boxes labelled COIN 1 ROW 4, COIN 2 ROW 5 and COIN 3 ROW 9 in the game, with Bali’s explanation in the chat

Watch this step (06:38)

Small adjustments are quick to ask for. The video moves the coins up slightly so they sit in the middle of their rows and feel better to run through.

Watch this step (08:10)

Step 10: Add a second item with a different rule

Section titled “Step 10: Add a second item with a different rule”

Now add diamonds with their own spawning rule: they stay on the moving platforms they spawn on, so the player has to get onto the right platform to collect them.

Diamonds on the platform rows and coins lower down, with Bali’s summary of the diamond spawning logic

Watch this step (09:57)

A second mechanic layered on top of the first takes more back and forth. Keep refining your prompts until it works. In the video, it takes a few rounds before all three diamonds spawn and move the way they should.

Watch this step (13:00)

Play the game again in the Preview tab. When everything looks good, publish the updated game.

Watch this step (14:25)