Sign in
game

Rodeo Ram

by Potluck · version 1 · Checked for all ages

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: a mini game. Climb on (Interact) and hold on as long as you
3-- can: it bucks harder the longer you stay. Your longest ride goes on the
4-- board, and a new record is announced to everyone. Hit it to hear the
5-- best rides so far.
6--
7-- The clock at the bottom of the rider's screen is its client half
8-- (client.luau, named in potluck.toml), which runs on the rider's own
9-- game: this file tells it when a ride starts and how it ended, and it
10-- counts the seconds itself.
11
12local world = require("@potluck/world")
13local tweak = require("@potluck/tweak")
14local game = require("@potluck/game@0.1")
15local sound = require("@potluck/sound@0.1")
16local net = require("@potluck/net@0.1")
17
18local knobs = tweak {
19 fleece = { "#d8cfbf", label = "Fleece color", order = 1 },
20 horns = { "#8c7b62", label = "Horn color", order = 2 },
21 buck = { 9, min = 2, max = 25, label = "Buck force", order = 3 },
22 temper = { 1, min = 0.3, max = 3, label = "Temper", order = 4 },
23}
24
25local Ram = world.creature {
26 name = "Rodeo Ram",
27 speed = 2.6,
28 rideable = true,
29 seat = 1.55,
30 count = 1,
31 home = "paddock",
32 body = {
33 { "fleece", size = { 1.2, 0.9, 1.6 }, at = { 0, 1.0, 0.05 }, color = knobs.fleece },
34 { "saddle", size = { 0.8, 0.12, 0.6 }, at = { 0, 1.5, 0.1 }, color = "#7a2e22" },
35 { "head", size = { 0.5, 0.5, 0.56 }, at = { 0, 1.2, -0.98 }, color = "#4a4038", head = true },
36 { "horn_left", size = { 0.24, 0.3, 0.3 }, at = { -0.34, 1.42, -0.9 }, color = knobs.horns, head = true },
37 { "horn_right", size = { 0.24, 0.3, 0.3 }, at = { 0.34, 1.42, -0.9 }, color = knobs.horns, head = true },
38 { "eye_left", size = { 0.08, 0.08, 0.04 }, at = { -0.14, 1.28, -1.27 }, color = "#e8d36a", head = true },
39 { "eye_right", size = { 0.08, 0.08, 0.04 }, at = { 0.14, 1.28, -1.27 }, color = "#e8d36a", head = true },
40 { "leg_front_left", size = { 0.22, 0.6, 0.22 }, at = { -0.38, 0.3, -0.5 }, color = "#4a4038", leg = true },
41 { "leg_front_right", size = { 0.22, 0.6, 0.22 }, at = { 0.38, 0.3, -0.5 }, color = "#4a4038", leg = true },
42 { "leg_back_left", size = { 0.22, 0.6, 0.22 }, at = { -0.38, 0.3, 0.55 }, color = "#4a4038", leg = true },
43 { "leg_back_right", size = { 0.22, 0.6, 0.22 }, at = { 0.38, 0.3, 0.55 }, color = "#4a4038", leg = true },
44 },
45}
46
47local SNORTS = { "Hrrnk!", "Get OFF!", "Baaah!", "Not today!" }
48
49local function seconds(t: number): string
50 return string.format("%.1f s", t)
51end
52
53function Ram:spawned()
54 self.rode = nil
55 self.started = 0
56 self.buck_in = 2
57end
58
59-- the ride's over, however it ended: on the board it goes
60local function finish(ram)
61 local who = ram.rode
62 ram.rode = nil
63 if not who then
64 return
65 end
66 local t = math.floor((world.time() - ram.started) * 10) / 10
67 if t < 0.5 then
68 net.send(who.id, "done", { time = t })
69 return
70 end
71 local best = game.board("longest ride", 1)[1]
72 local record = not best or t > best.value
73 game.score("longest ride", who.id, t)
74 net.send(who.id, "done", { time = t, record = record })
75 if record then
76 world.say(who.name .. " rode the Rodeo Ram for " .. seconds(t) .. ". A new record!")
77 else
78 ram:say(seconds(t) .. "! Best is " .. seconds(best.value) .. ".")
79 sound.play("ding", { at = ram })
80 end
81end
82
83function Ram:tick(dt: number)
84 if self.rode and not self.rider then
85 finish(self)
86 end
87 if not self.rider then
88 self:wander()
89 return
90 end
91 -- it bucks more often, and harder to stay on, the longer you ride
92 local riding = world.time() - self.started
93 self.buck_in -= dt * knobs.temper
94 if self.buck_in <= 0 then
95 self.buck_in = world.random(0.8, 2.2)
96 self:hop(0.9)
97 local chance = 0.15 + riding * 0.05
98 if world.random() < chance then
99 self:throw_rider(knobs.buck)
100 self:say(SNORTS[math.floor(world.random(1, #SNORTS + 1))])
101 sound.play("bleat", { at = self, pitch = 0.8 })
102 finish(self)
103 end
104 end
105end
106
107function Ram:ridden(player)
108 self.rode = { id = player.id, name = player.name }
109 self.started = world.time()
110 self.buck_in = 1.5
111 local best = game.board("longest ride", 1)[1]
112 net.send(player, "ride", { best = best and best.value })
113 self:say("Hold on!")
114 sound.play("bleat", { at = self })
115end
116
117function Ram:hit(player)
118 local top = game.board("longest ride", 3)
119 if #top == 0 then
120 self:say("Nobody's lasted yet. You?")
121 return
122 end
123 local parts = {}
124 for i, s in top do
125 table.insert(parts, i .. ". " .. s.name .. " " .. seconds(s.value))
126 end
127 self:say(table.concat(parts, " "))
128end