Sign in
creature

Ponies

by Potluck · version 1 · Checked for all ages

Sturdy little horses that graze the paddock. Hold an apple or carrots and they come to you, and Interact to feed one from your hand. Feed one three times and it trusts you: then Interact with a saddle in hand and it's yours to ride. Steer it with your movement, and it steps up anything a block high. Make a saddle at a workbench from leather and an iron ingot.

1--!strict
2-- Ponies: sturdy little horses that graze the paddock. Hold an apple or
3-- carrots and they come to you; Interact with one holding either and it
4-- eats from your hand. Feed one three times and it trusts you; then
5-- Interact with a saddle in hand (made at a workbench from leather and an
6-- iron ingot) and it's yours to ride: climb on, steer it with your
7-- movement, and it steps up anything a block high on its way. Saddled
8-- ponies are kept with the world (store), since the game brings back
9-- ponies by `count` after a restart. Bop one and it shies away. They give
10-- nothing: they're for riding.
11
12local world = require("@potluck/world@0.25")
13local tweak = require("@potluck/tweak")
14local store = require("@potluck/store")
15local sound = require("@potluck/sound@0.2")
16
17local knobs = tweak {
18 herd = { 3, min = 1, max = 8, label = "How many", order = 1 },
19 trust = { 3, min = 1, max = 8, label = "Feeds before one trusts you", order = 2 },
20 speed = { 4.5, min = 2, max = 7, label = "How fast one goes with a rider", order = 3 },
21 coat = { "#8a5a34", label = "Coat color", order = 4 },
22 mane = { "#3a2418", label = "Mane color", order = 5 },
23}
24
25local FOOD = { "Apple", "Carrots" }
26local SADDLE = "Saddle"
27
28local function likes(name: string?): boolean
29 return name ~= nil and table.find(FOOD, name) ~= nil
30end
31
32local HOOF = "#2a2420"
33local EYE, PUPIL = "#f4f2e8", "#141414"
34
35local function pony(saddled: boolean): { any }
36 local c, m = knobs.coat, knobs.mane
37 local b: { any } = {
38 { "body", size = { 0.62, 0.6, 1.2 }, at = { 0, 1.0, 0.05 }, color = c },
39 { "neck", size = { 0.36, 0.56, 0.36 }, at = { 0, 1.42, -0.52 }, color = c, head = true },
40 { "head", size = { 0.36, 0.36, 0.6 }, at = { 0, 1.7, -0.78 }, color = c, head = true },
41 { "muzzle", size = { 0.3, 0.24, 0.2 }, at = { 0, 1.6, -1.12 }, color = "#c8a888", head = true },
42 { "mane", size = { 0.12, 0.7, 0.44 }, at = { 0, 1.6, -0.46 }, color = m, head = true },
43 { "forelock", size = { 0.24, 0.12, 0.1 }, at = { 0, 1.9, -0.88 }, color = m, head = true },
44 { "ear_left", size = { 0.08, 0.16, 0.06 }, at = { -0.12, 1.96, -0.62 }, color = c, head = true },
45 { "ear_right", size = { 0.08, 0.16, 0.06 }, at = { 0.12, 1.96, -0.62 }, color = c, head = true },
46 { "tail", size = { 0.14, 0.6, 0.14 }, at = { 0, 0.92, 0.7 }, color = m },
47 }
48 for _, s in { -1, 1 } do
49 local n = if s < 0 then "left" else "right"
50 table.insert(b, { "eye_" .. n, size = { 0.04, 0.1, 0.1 }, at = { s * 0.19, 1.76, -0.86 }, color = EYE, head = true })
51 table.insert(b, { "pupil_" .. n, size = { 0.04, 0.07, 0.065 }, at = { s * 0.205, 1.755, -0.875 }, color = PUPIL, head = true })
52 table.insert(b, { "leg_front_" .. n, size = { 0.18, 0.7, 0.18 }, at = { s * 0.2, 0.35, -0.42 }, color = c, leg = true })
53 table.insert(b, { "leg_back_" .. n, size = { 0.18, 0.7, 0.18 }, at = { s * 0.2, 0.35, 0.48 }, color = c, leg = true })
54 table.insert(b, { "hoof_front_" .. n, size = { 0.2, 0.1, 0.2 }, at = { s * 0.2, 0.05, -0.42 }, color = HOOF, leg = true })
55 table.insert(b, { "hoof_back_" .. n, size = { 0.2, 0.1, 0.2 }, at = { s * 0.2, 0.05, 0.48 }, color = HOOF, leg = true })
56 end
57 if saddled then
58 table.insert(b, { "blanket", size = { 0.68, 0.36, 0.5 }, at = { 0, 1.18, -0.02 }, color = "#3a6aa8" })
59 table.insert(b, { "saddle", size = { 0.5, 0.12, 0.42 }, at = { 0, 1.36, -0.02 }, color = "#6a3a1c" })
60 table.insert(b, { "horn", size = { 0.1, 0.12, 0.08 }, at = { 0, 1.46, -0.2 }, color = "#4a2810" })
61 table.insert(b, { "stirrup_left", size = { 0.04, 0.3, 0.08 }, at = { -0.35, 1.0, -0.02 }, color = "#4a2810" })
62 table.insert(b, { "stirrup_right", size = { 0.04, 0.3, 0.08 }, at = { 0.35, 1.0, -0.02 }, color = "#4a2810" })
63 table.insert(b, { "bridle", size = { 0.38, 0.06, 0.06 }, at = { 0, 1.62, -1.0 }, color = "#4a2810", head = true })
64 end
65 return b
66end
67
68local Pony = world.creature {
69 name = "Pony",
70 speed = 2,
71 count = math.floor(knobs.herd),
72 home = "paddock",
73 size = { 0.7, 1.9, 0.7 },
74 behaviors = {
75 follow_food = FOOD,
76 flee_when_hit = 7,
77 chatter = { "Hrrrm.", "Pfff.", "Nnh-hh-hh." },
78 sound = "whinny",
79 },
80 body = pony(false),
81}
82
83local Saddled = world.creature {
84 name = "Saddled pony",
85 speed = knobs.speed,
86 count = 0,
87 home = "paddock",
88 rideable = true,
89 seat = 1.4,
90 size = { 0.7, 1.9, 0.7 },
91 behaviors = {
92 follow_food = FOOD,
93 flee_when_hit = 5,
94 chatter = { "Hrrrm.", "Pfff." },
95 sound = "whinny",
96 },
97 body = pony(true),
98}
99
100-- how many of the herd are saddled, kept with the world
101local saddled = (store.get("saddled") :: number?) or 0
102
103local function keep()
104 local n = #world.creatures(Saddled)
105 if n ~= saddled then
106 saddled = n
107 store.set("saddled", n)
108 end
109end
110
111function Pony:spawned()
112 -- one that was saddled before the world last stopped is again
113 if #world.creatures(Saddled) < saddled then
114 self:become(Saddled)
115 end
116end
117
118function Pony:used(player)
119 local held = world.held(player)
120 if likes(held) then
121 if world.take(player, held :: string, 1) then
122 sound.play("munch", { at = self, volume = 0.7 })
123 local trust = self.trust or {}
124 trust[player.name] = (trust[player.name] or 0) + 1
125 self.trust = trust
126 if trust[player.name] >= knobs.trust then
127 self:say("It nuzzles you. It'd take a saddle now.")
128 else
129 self:say("Munch, munch.")
130 end
131 end
132 return
133 end
134 if held == SADDLE then
135 local trust = self.trust or {}
136 if (trust[player.name] or 0) < knobs.trust then
137 self:say("It steps away. Feed it first.")
138 elseif world.take(player, SADDLE, 1) then
139 self:become(Saddled)
140 sound.play("whinny", { at = self })
141 self:say("Ready to ride.")
142 keep()
143 end
144 return
145 end
146 self:say("Pfff. Got an apple?")
147end
148
149function Saddled:ridden(player)
150 sound.play("whinny", { at = self, volume = 0.6, pitch = 1.1 })
151end
152
153function Saddled:tick(dt: number)
154 if not self.rider then
155 self.idle = (self.idle or 0) + dt
156 if self.idle > 1 then
157 self.idle = 0
158 keep()
159 end
160 end
161end
162
163function Pony:hit(player)
164 self:say("Nnh-hh!")
165end
166Saddled.hit = Pony.hit