|
1 | 1 | # Example: build a game loop |
2 | 2 |
|
3 | 3 | A complete worked example — a start menu, a walking character, collectibles that count |
4 | | -into the HUD, a hold-to-peek map, and a pause menu you can click. Everything is authored |
5 | | -in the app with the HUD editor and flow nodes. No code, no modules. |
| 4 | +into the HUD, a hold-to-peek map, a pause menu you can click, and a second level to |
| 5 | +travel to. Everything is authored in the app with the HUD editor and flow nodes. No |
| 6 | +code, no modules. |
6 | 7 |
|
7 | 8 | Allow about twenty minutes. Each step works on its own, so you can stop anywhere and |
8 | 9 | still have something playable, and every piece is visible to the people connected with |
@@ -92,6 +93,24 @@ Press Play, walk up to one and click it with the crosshair. It disappears for |
92 | 93 | **everyone**, the counter goes up on every screen, and clicking the empty space where it |
93 | 94 | was does nothing — it stays collected. |
94 | 95 |
|
| 96 | +A few dials, all optional: |
| 97 | + |
| 98 | +- **Make collectible into…** asks which variable it counts into (existing names are |
| 99 | + offered as chips, or type a new one) and whether it **respawns** after a few seconds. |
| 100 | + The respawn is built into the graph — a Delay off the click resets the Latch and |
| 101 | + re-arms the Once — so you can see it and change it in the node editor. |
| 102 | +- Run it on a **Group** and every mesh inside becomes a collectible sharing the group's |
| 103 | + variable, as one undo step. Add a new member later and run it again: the ones that are |
| 104 | + already collectible are skipped ("2 added, 3 skipped"). |
| 105 | +- Collectibles **reset when a new round starts** and when the game returns to its menu — |
| 106 | + that is the "reset each round" checkbox the recipe sets on its Latch and Once, derived |
| 107 | + from the shared round, so a Restart needs no extra wiring. And when you leave play |
| 108 | + mode, collected objects come straight back on your own screen ("only while playing" |
| 109 | + on the Visibility node), so the editor never loses an object to a running game. |
| 110 | +- **Collect Count** is the node that answers "how many are left" — it reads the |
| 111 | + collectible chains in the graph, not the score, so it is right after a respawn and |
| 112 | + after a round reset. **Actions ▸ Show collectibles left** wires it to a Text for you. |
| 113 | + |
95 | 114 | --- |
96 | 115 |
|
97 | 116 | ## 5. Hold a key to peek at a map |
@@ -143,6 +162,33 @@ That's the loop: menu → play → score → pause → end → menu. |
143 | 162 |
|
144 | 163 | --- |
145 | 164 |
|
| 165 | +## 8. A second level |
| 166 | + |
| 167 | +One scene is one level; a game can have many. |
| 168 | + |
| 169 | +1. Build your first level, then in the **Explorer** right-click the file grid and |
| 170 | + choose **Save scene as level…**. It lands in a `Levels` folder as an ordinary |
| 171 | + `.tpscene` file. **New scene…** gives you an empty one to build the next level in. |
| 172 | +2. Where the first level should end — a door, a portal, a Finish button — add a |
| 173 | + **Travel** node (Game group) and pick the destination level on its card. Wire any |
| 174 | + trigger into it, or use **Actions ▸ Level complete — travel to a level** on a button. |
| 175 | +3. Press it and **everyone travels together**: each player loads the level themselves, |
| 176 | + and anyone missing the file pulls it from whoever has it first. The game — state, |
| 177 | + round, score variables — **carries across the hop**; the new level's own collectibles |
| 178 | + start fresh, because their little graphs live in the level file. |
| 179 | + |
| 180 | +Two helpers that come with it: |
| 181 | + |
| 182 | +- **All Players** (Game group) is the group-travel gate: wire in a condition each player |
| 183 | + answers for themselves ("I am standing at the portal") and it fires once **every** |
| 184 | + player in play mode says yes — spectators in the editor don't count. Feed it into the |
| 185 | + Travel node and nobody gets left behind. |
| 186 | +- The **Debug** HUD element (Display group) is a little pill for building: game state, |
| 187 | + round, elapsed time, your variables, collectibles left, who is playing and fps. Click |
| 188 | + it in-game to expand. Take it off the screen when you ship. |
| 189 | + |
| 190 | +--- |
| 191 | + |
146 | 192 | ## Where to go next |
147 | 193 |
|
148 | 194 | - **[Node System](node-system.md)** — the logic nodes this example leans on: Latch, |
|
0 commit comments