đź’Ž Collect the gems

Contents

    Type of project

    Game

    Project overview

    Collect the Gems is a game where you run and jump around a small world to find three hidden gems. Each gem spins to catch your eye, and when you touch one it disappears, plays a sound, and updates the on-screen counter. When all gems are collected, you get a “You found them all!” message and a celebration sound.

    This project demonstrates player movement with physics, collision-based pickup logic, counters/variables, win conditions, event-driven animations, and feedback (text + sound).

    Try it out

    1. Open Flock XR and go to the Demo menu.
    2. Select đź’Ž Collect the gems
    3. Press Play.
    4. Use W/A/S/D to move, and Space to jump. Hold left mouse to look.
    5. Find the three gems. You should see:
    – gems spinning in place
    – a sound and “Gem collected!” when you touch one
    – the on-screen “gems left” count going down
    – a “You found them all!” message and a win sound when you reach zero

    Explore the code

    Open the code and look for these parts:

    A reusable “stairs” function
    A custom function called stairs(levels, width, x, z) that uses a loop to create steps. This is a great example of building level pieces without manually placing every block.

    A playable character
    A character is loaded, given dynamic physics, with the camera set to follow.
    A forever loop checks for input: moving forward/back/left/right and applying a jump force. It also uses a jumping variable plus a touching surface check so you can’t jump forever in mid-air.

    Jump animations using broadcasts
    When you jump, the project broadcasts “jumped” and plays Jump sequence of animations.
    When you land, it broadcasts “landed” and switches back to Idle.

    Gems + visual feedback
    Three gem objects are loaded (Gem1/2/3), highlighted/alpha adjusted, and continuously rotated in a forever loop so they sparkle and feel “collectable”.

    Collecting a gem (collision pickups)
    Three on collision blocks detect when the player intersects each gem. Each one:
    – hides the gem
    – subtracts 1 from gems left
    – plays a sound
    – updates the “gems left” UI text
    – makes the player say “Gem collected!”

    Win condition
    A forever loop checks: if gems left == 0 and won == false, set won to true, wait 1 second, then broadcast win.
    The on event “win” block prints “You found them all!” and plays a victory sound.

    Remix ideas

    Try extending the project with your own ideas:

    Add more gems and update the “gems left” starting value.

    Add a “danger zone” (lava/water) that resets the player to the start if they fall in.

    Add a timer (“Time: 32s”) and show a best time when the player wins.

    Make gems worth different points (small = 1, big = 3) and track a score instead of a gem countdown.

    Add a locked area that only opens when all gems are collected.

    A similar project you could create

    Create a checkpoint trail mini-game:
    – Reuse the same player movement + jump + camera follow code.
    – Replace gems with glowing checkpoints.
    – When the player touches a checkpoint, hide it and show the next checkpoint.
    – Keep a count of “checkpoints cleared”.
    – After the final checkpoint, trigger a win message and sound.
    It’s the same core pattern (spinning/visible targets + collision pickups + counter + win condition), but adds a set unlock order to gameplay.

    Updated on December 18, 2025