A ram by the paddock that does not want a rider. Climb on and hold on: the longest rides go on the board.
| 1 | --!strict |
| 2 | -- Rodeo Ram's client half. This file runs on each player's own game, not |
| 3 | -- on the world's host: main.luau says when your ride starts and how it |
| 4 | -- ended (with net.send), and this keeps the ride's clock at the bottom of |
| 5 | -- your screen, ten times a second, with nothing sent while it runs. |
| 6 | |
| 7 | local net = require("@potluck/net@0.1") |
| 8 | local ui = require("@potluck/ui@0.1") |
| 9 | local sound = require("@potluck/sound@0.1") |
| 10 | local world = require("@potluck/world@0.2") |
| 11 | |
| 12 | local clock: number? = nil -- the timer that keeps the clock going |
| 13 | local started = 0 |
| 14 | local best: number? = nil |
| 15 | local passed = false |
| 16 | |
| 17 | local function seconds(t: number): string |
| 18 | return string.format("%.1f s", t) |
| 19 | end |
| 20 | |
| 21 | local function stop() |
| 22 | if clock then |
| 23 | world.cancel(clock) |
| 24 | clock = nil |
| 25 | end |
| 26 | end |
| 27 | |
| 28 | -- on the ram: { best = the record, if there is one } |
| 29 | net.on("ride", function(info: any) |
| 30 | stop() |
| 31 | started = world.time() |
| 32 | best = info and info.best |
| 33 | passed = false |
| 34 | clock = world.every(0.1, function() |
| 35 | local t = world.time() - started |
| 36 | local line = "Riding " .. seconds(t) |
| 37 | if best then |
| 38 | if t > best and not passed then |
| 39 | passed = true |
| 40 | sound.play("sparkle", { volume = 0.6, caption = "Past the record" }) |
| 41 | end |
| 42 | line ..= if passed then " · past the record!" else " · record " .. seconds(best) |
| 43 | end |
| 44 | ui.show(nil, "ride", line, { at = "bottom" }) |
| 45 | end) |
| 46 | end) |
| 47 | |
| 48 | -- off again: { time = how long, record = whether it's the longest yet } |
| 49 | net.on("done", function(info: any) |
| 50 | stop() |
| 51 | if info.time < 0.5 then |
| 52 | ui.hide(nil, "ride") |
| 53 | return |
| 54 | end |
| 55 | local line = "You rode " .. seconds(info.time) |
| 56 | ui.show(nil, "ride", if info.record then line .. ", the longest yet!" else line, { at = "bottom" }) |
| 57 | world.after(4, function() |
| 58 | if not clock then |
| 59 | ui.hide(nil, "ride") |
| 60 | end |
| 61 | end) |
| 62 | end) |