Sign in
creature

Pup

by Potluck · version 1 · Checked for all ages

Friendly pups on the hill where everyone starts. They trot after you, and fetch when asked.

1--!strict
2-- Pup: friendly pups on the hill where everyone starts. They trot after
3-- whoever's close. Interact and they run off to fetch, then come back.
4
5local world = require("@potluck/world")
6local tweak = require("@potluck/tweak")
7local sound = require("@potluck/sound@0.1")
8
9local knobs = tweak {
10 coat = { "#c58b4e", label = "Coat color", order = 1 },
11 patch = { "#f4ede2", label = "Patch color", order = 2 },
12 fetch = { 10, min = 3, max = 24, label = "How far it fetches", order = 3 },
13}
14
15local Pup = world.creature {
16 name = "Pup",
17 speed = 3.4,
18 count = 2,
19 home = "start",
20 body = {
21 { "body", size = { 0.46, 0.44, 0.86 }, at = { 0, 0.56, 0.04 }, color = knobs.coat },
22 { "patch", size = { 0.48, 0.2, 0.3 }, at = { 0, 0.5, -0.22 }, color = knobs.patch },
23 { "head", size = { 0.4, 0.38, 0.4 }, at = { 0, 0.88, -0.5 }, color = knobs.coat, head = true },
24 { "snout", size = { 0.2, 0.16, 0.18 }, at = { 0, 0.8, -0.76 }, color = knobs.patch, head = true },
25 { "nose", size = { 0.08, 0.06, 0.04 }, at = { 0, 0.86, -0.86 }, color = "#1b1b1b", head = true },
26 { "ear_left", size = { 0.1, 0.2, 0.12 }, at = { -0.17, 1.1, -0.44 }, color = "#8a5a32", head = true },
27 { "ear_right", size = { 0.1, 0.2, 0.12 }, at = { 0.17, 1.1, -0.44 }, color = "#8a5a32", head = true },
28 { "eye_left", size = { 0.09, 0.095, 0.04 }, at = { -0.1, 0.94, -0.71 }, color = "#f6f2e6", head = true },
29 { "pupil_left", size = { 0.05, 0.063, 0.04 }, at = { -0.1, 0.937, -0.739 }, color = "#1b1b1b", head = true },
30 { "eye_right", size = { 0.09, 0.095, 0.04 }, at = { 0.1, 0.94, -0.71 }, color = "#f6f2e6", head = true },
31 { "pupil_right", size = { 0.05, 0.063, 0.04 }, at = { 0.1, 0.937, -0.739 }, color = "#1b1b1b", head = true },
32 { "leg_front_left", size = { 0.12, 0.36, 0.12 }, at = { -0.14, 0.18, -0.28 }, color = knobs.coat, leg = true },
33 { "leg_front_right", size = { 0.12, 0.36, 0.12 }, at = { 0.14, 0.18, -0.28 }, color = knobs.coat, leg = true },
34 { "leg_back_left", size = { 0.12, 0.36, 0.12 }, at = { -0.14, 0.18, 0.34 }, color = knobs.coat, leg = true },
35 { "leg_back_right", size = { 0.12, 0.36, 0.12 }, at = { 0.14, 0.18, 0.34 }, color = knobs.coat, leg = true },
36 { "tail", size = { 0.08, 0.08, 0.26 }, at = { 0, 0.78, 0.56 }, color = knobs.coat },
37 },
38}
39
40function Pup:spawned()
41 self.fetching = nil
42 self.back_to = nil
43 self.sit = 0
44end
45
46function Pup:tick(dt: number)
47 if self.sit > 0 then
48 self.sit -= dt
49 self:stop()
50 return
51 end
52 if self.fetching then
53 if self:distance_to(self.fetching) < 1.2 then
54 self.fetching = nil
55 self:say("Woof!")
56 sound.play("yip", { at = self, pitch = 0.8 })
57 else
58 return
59 end
60 end
61 if self.back_to then
62 local p = self.back_to
63 if self:distance_to(p) < 2 then
64 self.back_to = nil
65 self:hop(0.5)
66 else
67 self:walk_to(p, 4)
68 end
69 return
70 end
71 local friend = world.nearest_player(self.position, 10)
72 if friend and self:distance_to(friend.position) > 3 then
73 self:walk_to(friend.position, 3.4)
74 elseif friend then
75 self:stop()
76 self:face(friend.position)
77 else
78 self:wander()
79 end
80end
81
82function Pup:used(player)
83 -- off it goes, the way you're facing it, then back to you
84 local away = self.position - player.position
85 local len = math.max(0.1, math.sqrt(away.x * away.x + away.z * away.z))
86 local dir = vector.create(away.x / len, 0, away.z / len)
87 self.fetching = self.position + dir * knobs.fetch
88 self.back_to = player.position
89 self:walk_to(self.fetching, 5)
90 self:say("Arf!")
91 sound.play("yip", { at = self })
92end
93
94function Pup:hit(player)
95 self.sit = 3
96 self.fetching = nil
97 self:say("Whimper.")
98 sound.play("yip", { at = self, volume = 0.5, pitch = 1.4 })
99end