Little crabs from the creek. They scuttle off sideways if you come too close, and dance if you're kind.
| 1 | --!strict |
| 2 | -- Pebble Crab: little crabs from the creek north-east of the Green. |
| 3 | -- Walk up too fast and they scuttle off sideways. Interact and they dance. |
| 4 | |
| 5 | local world = require("@potluck/world") |
| 6 | local tweak = require("@potluck/tweak") |
| 7 | local sound = require("@potluck/sound@0.1") |
| 8 | |
| 9 | local knobs = tweak { |
| 10 | shell = { "#c8553d", label = "Shell color", order = 1 }, |
| 11 | shy = { 3, min = 0, max = 8, label = "How close is too close", order = 2 }, |
| 12 | } |
| 13 | |
| 14 | local Crab = world.creature { |
| 15 | name = "Pebble Crab", |
| 16 | speed = 2.6, |
| 17 | count = 5, |
| 18 | home = "creek", |
| 19 | body = { |
| 20 | { "shell", size = { 0.7, 0.26, 0.5 }, at = { 0, 0.3, 0 }, color = knobs.shell }, |
| 21 | { "shell_top", size = { 0.5, 0.1, 0.36 }, at = { 0, 0.47, 0 }, color = knobs.shell }, |
| 22 | { "claw_left", size = { 0.2, 0.16, 0.24 }, at = { -0.42, 0.32, -0.28 }, color = knobs.shell, head = true }, |
| 23 | { "claw_right", size = { 0.2, 0.16, 0.24 }, at = { 0.42, 0.32, -0.28 }, color = knobs.shell, head = true }, |
| 24 | { "eye_left", size = { 0.21, 0.221, 0.06 }, at = { -0.1, 0.56, -0.2 }, color = "#f6f2e6", head = true }, |
| 25 | { "pupil_left", size = { 0.116, 0.147, 0.06 }, at = { -0.1, 0.554, -0.241 }, color = "#1b1b1b", head = true }, |
| 26 | { "eye_right", size = { 0.21, 0.221, 0.06 }, at = { 0.1, 0.56, -0.2 }, color = "#f6f2e6", head = true }, |
| 27 | { "pupil_right", size = { 0.116, 0.147, 0.06 }, at = { 0.1, 0.554, -0.241 }, color = "#1b1b1b", head = true }, |
| 28 | { "legs_left", size = { 0.12, 0.2, 0.4 }, at = { -0.38, 0.1, 0.05 }, color = "#a8432f", leg = true }, |
| 29 | { "legs_right", size = { 0.12, 0.2, 0.4 }, at = { 0.38, 0.1, 0.05 }, color = "#a8432f", leg = true }, |
| 30 | }, |
| 31 | } |
| 32 | |
| 33 | function Crab:spawned() |
| 34 | self.dance = 0 |
| 35 | self.calm = 0 |
| 36 | end |
| 37 | |
| 38 | function Crab:tick(dt: number) |
| 39 | if self.dance > 0 then |
| 40 | self.dance -= dt |
| 41 | if math.floor(self.dance * 3) % 2 == 0 then |
| 42 | self:hop(0.35) |
| 43 | end |
| 44 | return |
| 45 | end |
| 46 | self.calm -= dt |
| 47 | local p = world.nearest_player(self.position, knobs.shy) |
| 48 | if p and self.calm <= 0 then |
| 49 | -- crabs go sideways: across the line to whoever came close |
| 50 | local d = self.position - p.position |
| 51 | local side = vector.create(-d.z, 0, d.x) |
| 52 | self:walk_to(self.position + side * 1.5 + d * 0.5, 3.6) |
| 53 | self:say("Click!") |
| 54 | sound.play("click", { at = self }) |
| 55 | self.calm = 2 |
| 56 | return |
| 57 | end |
| 58 | if self.calm <= 0 then |
| 59 | self:wander() |
| 60 | end |
| 61 | end |
| 62 | |
| 63 | function Crab:used(player) |
| 64 | self.dance = 2.5 |
| 65 | self:face(player.position) |
| 66 | self:say("Click click!") |
| 67 | sound.play("click", { at = self, pitch = 1.2 }) |
| 68 | end |
| 69 | |
| 70 | function Crab:hit(player) |
| 71 | self:hop(0.9) |
| 72 | self:say("Snip!") |
| 73 | sound.play("click", { at = self, pitch = 0.7 }) |
| 74 | self.calm = 0 |
| 75 | end |