Sign in
creature

Mossback

by Potluck · version 1 · Checked for all ages

A slow, mossy friend from the paddock on the Green. Ride one if you can stay on: they buck.

1--!strict
2-- Mossback: a slow, mossy friend from the paddock on the Green.
3-- Walk up and press Interact to ride one. It doesn't love being ridden, so
4-- now and then it bucks. Turn Buck force up to see how far you fly, or
5-- Pat it while you ride and it calms down a little.
6
7local world = require("@potluck/world")
8local tweak = require("@potluck/tweak")
9local input = require("@potluck/input")
10local sound = require("@potluck/sound@0.1")
11
12-- Knobs show up in Tweak, so anyone can change them without code.
13local knobs = tweak {
14 speed = { 2.2, min = 0.5, max = 8, label = "Walking speed", order = 1 },
15 buck = { 6, min = 0, max = 25, label = "Buck force", order = 2 },
16 shell = { "#4f7a3a", label = "Shell color", order = 3 },
17}
18
19-- A body is a list of boxes: a name, a size and where its middle sits
20-- (x right, y up, z back: the head is at the front, at negative z).
21local Mossback = world.creature {
22 name = "Mossback",
23 speed = knobs.speed,
24 rideable = true,
25 seat = 1.6,
26 count = 3,
27 home = "paddock",
28 body = {
29 { "belly", size = { 1.2, 0.5, 1.5 }, at = { 0, 0.6, 0 }, color = "#8a7a52" },
30 { "shell", size = { 1.5, 0.6, 1.8 }, at = { 0, 1.05, 0.05 }, color = knobs.shell },
31 { "moss", size = { 1.1, 0.22, 1.3 }, at = { 0, 1.42, 0 }, color = "#6fa64a" },
32 { "tuft", size = { 0.4, 0.25, 0.4 }, at = { 0.25, 1.62, 0.2 }, color = "#86bb48" },
33 { "head", size = { 0.62, 0.55, 0.6 }, at = { 0, 0.95, -1.15 }, color = "#9c8a5c", head = true },
34 { "eye_left", size = { 0.12, 0.14, 0.06 }, at = { -0.17, 1.05, -1.46 }, color = "#1b1b1b", head = true },
35 { "eye_right", size = { 0.12, 0.14, 0.06 }, at = { 0.17, 1.05, -1.46 }, color = "#1b1b1b", head = true },
36 { "leg_front_left", size = { 0.34, 0.5, 0.34 }, at = { -0.5, 0.25, -0.55 }, color = "#7d6c47", leg = true },
37 { "leg_front_right", size = { 0.34, 0.5, 0.34 }, at = { 0.5, 0.25, -0.55 }, color = "#7d6c47", leg = true },
38 { "leg_back_right", size = { 0.34, 0.5, 0.34 }, at = { 0.5, 0.25, 0.6 }, color = "#7d6c47", leg = true },
39 { "leg_back_left", size = { 0.34, 0.5, 0.34 }, at = { -0.5, 0.25, 0.6 }, color = "#7d6c47", leg = true },
40 { "tail", size = { 0.2, 0.2, 0.3 }, at = { 0, 0.75, 1.05 }, color = "#7d6c47" },
41 },
42}
43
44local GRUMBLES = { "Hrrmf!", "Mmmf.", "Off you get!", "Blrrp." }
45
46-- Pat is an action in potluck.toml. While you ride a mossback its button
47-- pats it instead of getting you off (B or Shift still do).
48local patted: { [number]: boolean } = {}
49input.on("pat", function(player)
50 patted[player.id] = true
51end)
52
53function Mossback:spawned()
54 self.patience = 5
55 self.stroll = 0
56end
57
58function Mossback:tick(dt: number)
59 if self.rider then
60 -- a pat buys a little more patience
61 if patted[self.rider.id] then
62 patted[self.rider.id] = nil
63 self.patience += 1.5
64 self:say("Mmm.")
65 sound.play("grumble", { at = self, volume = 0.6, pitch = 1.3, caption = "Mossback hums" })
66 end
67 -- now and then a mossback has had enough
68 self.patience -= dt
69 if self.patience <= 0 then
70 self.patience = world.random(2, 6)
71 self:hop(0.7)
72 if world.random() < 0.5 then
73 self:throw_rider(knobs.buck)
74 self:say(GRUMBLES[math.floor(world.random(1, #GRUMBLES + 1))])
75 sound.play("grumble", { at = self })
76 end
77 end
78 return
79 end
80
81 -- wander the paddock, and come over to say hello to anyone close by
82 local friend = world.nearest_player(self.position, 6)
83 if friend and self:distance_to(friend.position) > 2.5 then
84 self:walk_to(friend.position, knobs.speed * 0.6)
85 else
86 self:wander()
87 end
88
89 -- mossbacks leave flowers where they've been
90 self.stroll += dt
91 if self.stroll > 25 then
92 self.stroll = 0
93 local here = self.position
94 if world.block(here) == "Air" and world.block(here - vector.create(0, 1, 0)) == "Grass" then
95 world.set_block(here, "Red flower")
96 end
97 end
98end
99
100-- Interact with one that's free and you climb on; this runs when you do.
101function Mossback:ridden(player)
102 self.patience = world.random(3, 7)
103 self:say("Mmmf?")
104 sound.play("grumble", { at = self, volume = 0.5, pitch = 1.2 })
105end
106
107-- Hit one and it complains.
108function Mossback:hit(player)
109 self:hop(1)
110 self:say("Oi!")
111 sound.play("grumble", { at = self, pitch = 1.4 })
112end